PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ gserialized_from_lwpoly()

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

Definition at line 903 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().

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