PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gserialized_from_lwpoly()

static size_t gserialized_from_lwpoly ( const LWPOLY poly,
uint8_t buf 
)
static

Definition at line 906 of file g_serialized.c.

References POINTARRAY::flags, LWPOLY::flags, FLAGS_GET_ZM, FLAGS_NDIMS, getPoint_internal(), LWDEBUG, lwerror(), POINTARRAY::npoints, LWPOLY::nrings, POLYGONTYPE, LWPOLY::rings, and ovdump::type.

Referenced by gserialized_from_lwgeom_any().

907 {
908  int i;
909  uint8_t *loc;
910  int ptsize;
911  int type = POLYGONTYPE;
912 
913  assert(poly);
914  assert(buf);
915 
916  LWDEBUG(2, "lwpoly_to_gserialized called");
917 
918  ptsize = sizeof(double) * FLAGS_NDIMS(poly->flags);
919  loc = buf;
920 
921  /* Write in the type. */
922  memcpy(loc, &type, sizeof(uint32_t));
923  loc += sizeof(uint32_t);
924 
925  /* Write in the nrings. */
926  memcpy(loc, &(poly->nrings), sizeof(uint32_t));
927  loc += sizeof(uint32_t);
928 
929  /* Write in the npoints per ring. */
930  for ( i = 0; i < poly->nrings; i++ )
931  {
932  memcpy(loc, &(poly->rings[i]->npoints), sizeof(uint32_t));
933  loc += sizeof(uint32_t);
934  }
935 
936  /* Add in padding if necessary to remain double aligned. */
937  if ( poly->nrings % 2 )
938  {
939  memset(loc, 0, sizeof(uint32_t));
940  loc += sizeof(uint32_t);
941  }
942 
943  /* Copy in the ordinates. */
944  for ( i = 0; i < poly->nrings; i++ )
945  {
946  POINTARRAY *pa = poly->rings[i];
947  size_t pasize;
948 
949  if ( FLAGS_GET_ZM(poly->flags) != FLAGS_GET_ZM(pa->flags) )
950  lwerror("Dimensions mismatch in lwpoly");
951 
952  pasize = pa->npoints * ptsize;
953  if ( pasize )
954  memcpy(loc, getPoint_internal(pa, 0), pasize);
955  loc += pasize;
956  }
957  return (size_t)(loc - buf);
958 }
int npoints
Definition: liblwgeom.h:371
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define FLAGS_GET_ZM(flags)
Definition: liblwgeom.h:153
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
unsigned int uint32_t
Definition: uthash.h:78
uint8_t flags
Definition: liblwgeom.h:369
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1753
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
type
Definition: ovdump.py:41
uint8_t flags
Definition: liblwgeom.h:452
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:152
unsigned char uint8_t
Definition: uthash.h:79
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: