PostGIS  2.3.7dev-r@@SVN_REVISION@@
static size_t gserialized_from_lwpoly ( const LWPOLY poly,
uint8_t *  buf 
)
static

Definition at line 662 of file g_serialized.c.

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

Referenced by gserialized_from_lwgeom_any().

663 {
664  int i;
665  uint8_t *loc;
666  int ptsize;
667  int type = POLYGONTYPE;
668 
669  assert(poly);
670  assert(buf);
671 
672  LWDEBUG(2, "lwpoly_to_gserialized called");
673 
674  ptsize = sizeof(double) * FLAGS_NDIMS(poly->flags);
675  loc = buf;
676 
677  /* Write in the type. */
678  memcpy(loc, &type, sizeof(uint32_t));
679  loc += sizeof(uint32_t);
680 
681  /* Write in the nrings. */
682  memcpy(loc, &(poly->nrings), sizeof(uint32_t));
683  loc += sizeof(uint32_t);
684 
685  /* Write in the npoints per ring. */
686  for ( i = 0; i < poly->nrings; i++ )
687  {
688  memcpy(loc, &(poly->rings[i]->npoints), sizeof(uint32_t));
689  loc += sizeof(uint32_t);
690  }
691 
692  /* Add in padding if necessary to remain double aligned. */
693  if ( poly->nrings % 2 )
694  {
695  memset(loc, 0, sizeof(uint32_t));
696  loc += sizeof(uint32_t);
697  }
698 
699  /* Copy in the ordinates. */
700  for ( i = 0; i < poly->nrings; i++ )
701  {
702  POINTARRAY *pa = poly->rings[i];
703  size_t pasize;
704 
705  if ( FLAGS_GET_ZM(poly->flags) != FLAGS_GET_ZM(pa->flags) )
706  lwerror("Dimensions mismatch in lwpoly");
707 
708  pasize = pa->npoints * ptsize;
709  memcpy(loc, getPoint_internal(pa, 0), pasize);
710  loc += pasize;
711  }
712  return (size_t)(loc - buf);
713 }
int npoints
Definition: liblwgeom.h:370
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define FLAGS_GET_ZM(flags)
Definition: liblwgeom.h:152
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
uint8_t flags
Definition: liblwgeom.h:368
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1706
POINTARRAY ** rings
Definition: liblwgeom.h:456
int nrings
Definition: liblwgeom.h:454
uint8_t flags
Definition: liblwgeom.h:451
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:151
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102

Here is the call graph for this function:

Here is the caller graph for this function: