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

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

638 {
639  int i;
640  uint8_t *loc;
641  int ptsize;
642  int type = POLYGONTYPE;
643 
644  assert(poly);
645  assert(buf);
646 
647  LWDEBUG(2, "lwpoly_to_gserialized called");
648 
649  ptsize = sizeof(double) * FLAGS_NDIMS(poly->flags);
650  loc = buf;
651 
652  /* Write in the type. */
653  memcpy(loc, &type, sizeof(uint32_t));
654  loc += sizeof(uint32_t);
655 
656  /* Write in the nrings. */
657  memcpy(loc, &(poly->nrings), sizeof(uint32_t));
658  loc += sizeof(uint32_t);
659 
660  /* Write in the npoints per ring. */
661  for ( i = 0; i < poly->nrings; i++ )
662  {
663  memcpy(loc, &(poly->rings[i]->npoints), sizeof(uint32_t));
664  loc += sizeof(uint32_t);
665  }
666 
667  /* Add in padding if necessary to remain double aligned. */
668  if ( poly->nrings % 2 )
669  {
670  memset(loc, 0, sizeof(uint32_t));
671  loc += sizeof(uint32_t);
672  }
673 
674  /* Copy in the ordinates. */
675  for ( i = 0; i < poly->nrings; i++ )
676  {
677  POINTARRAY *pa = poly->rings[i];
678  size_t pasize;
679 
680  if ( FLAGS_GET_ZM(poly->flags) != FLAGS_GET_ZM(pa->flags) )
681  lwerror("Dimensions mismatch in lwpoly");
682 
683  pasize = pa->npoints * ptsize;
684  memcpy(loc, getPoint_internal(pa, 0), pasize);
685  loc += pasize;
686  }
687  return (size_t)(loc - buf);
688 }
int npoints
Definition: liblwgeom.h:327
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define FLAGS_GET_ZM(flags)
Definition: liblwgeom.h:119
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
uint8_t flags
Definition: liblwgeom.h:325
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1645
POINTARRAY ** rings
Definition: liblwgeom.h:413
int nrings
Definition: liblwgeom.h:411
uint8_t flags
Definition: liblwgeom.h:408
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:118

Here is the call graph for this function:

Here is the caller graph for this function: