PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ gserialized_from_lwpoly()

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

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

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