PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ gserialized2_from_lwpoly()

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

Definition at line 908 of file gserialized2.c.

909{
910 uint32_t i;
911 uint8_t *loc;
912 int ptsize;
913 int type = POLYGONTYPE;
914
915 assert(poly);
916 assert(buf);
917
918 LWDEBUGF(2, "%s called", __func__);
919
920 ptsize = sizeof(double) * FLAGS_NDIMS(poly->flags);
921 loc = buf;
922
923 /* Write in the type. */
924 memcpy(loc, &type, sizeof(uint32_t));
925 loc += sizeof(uint32_t);
926
927 /* Write in the nrings. */
928 memcpy(loc, &(poly->nrings), sizeof(uint32_t));
929 loc += sizeof(uint32_t);
930
931 /* Write in the npoints per ring. */
932 for (i = 0; i < poly->nrings; i++)
933 {
934 memcpy(loc, &(poly->rings[i]->npoints), sizeof(uint32_t));
935 loc += sizeof(uint32_t);
936 }
937
938 /* Add in padding if necessary to remain double aligned. */
939 if (poly->nrings % 2)
940 {
941 memset(loc, 0, sizeof(uint32_t));
942 loc += sizeof(uint32_t);
943 }
944
945 /* Copy in the ordinates. */
946 for (i = 0; i < poly->nrings; i++)
947 {
948 POINTARRAY *pa = poly->rings[i];
949 size_t pasize;
950
951 if (FLAGS_GET_ZM(poly->flags) != FLAGS_GET_ZM(pa->flags))
952 lwerror("Dimensions mismatch in lwpoly");
953
954 pasize = pa->npoints * ptsize;
955 if ( pa->npoints > 0 )
956 memcpy(loc, getPoint_internal(pa, 0), pasize);
957 loc += pasize;
958 }
959 return (size_t)(loc - buf);
960}
#define FLAGS_NDIMS(flags)
Definition liblwgeom.h:193
#define POLYGONTYPE
Definition liblwgeom.h:118
#define FLAGS_GET_ZM(flags)
Definition liblwgeom.h:194
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition lwutil.c:190
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition lwinline.h:67
POINTARRAY ** rings
Definition liblwgeom.h:505
uint32_t nrings
Definition liblwgeom.h:510
lwflags_t flags
Definition liblwgeom.h:507
lwflags_t flags
Definition liblwgeom.h:417
uint32_t npoints
Definition liblwgeom.h:413

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

Referenced by gserialized2_from_lwgeom_any().

Here is the call graph for this function:
Here is the caller graph for this function: