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

◆ lwpoly_from_gserialized2_buffer()

static LWPOLY * lwpoly_from_gserialized2_buffer ( uint8_t *  data_ptr,
lwflags_t  lwflags,
size_t *  size,
int32_t  srid 
)
static

Definition at line 1277 of file gserialized2.c.

1278{
1279 uint8_t *start_ptr = data_ptr;
1280 LWPOLY *poly;
1281 uint8_t *ordinate_ptr;
1282 uint32_t nrings = 0;
1283 uint32_t i = 0;
1284
1285 assert(data_ptr);
1286
1287 poly = (LWPOLY*)lwalloc(sizeof(LWPOLY));
1288 poly->srid = srid;
1289 poly->bbox = NULL;
1290 poly->type = POLYGONTYPE;
1291 poly->flags = lwflags;
1292
1293 data_ptr += 4; /* Skip past the polygontype. */
1294 nrings = gserialized2_get_uint32_t(data_ptr); /* Zero => empty geometry */
1295 poly->nrings = nrings;
1296 LWDEBUGF(4, "nrings = %d", nrings);
1297 data_ptr += 4; /* Skip past the nrings. */
1298
1299 ordinate_ptr = data_ptr; /* Start the ordinate pointer. */
1300 if (nrings > 0)
1301 {
1302 poly->rings = (POINTARRAY**)lwalloc( sizeof(POINTARRAY*) * nrings );
1303 poly->maxrings = nrings;
1304 ordinate_ptr += nrings * 4; /* Move past all the npoints values. */
1305 if (nrings % 2) /* If there is padding, move past that too. */
1306 ordinate_ptr += 4;
1307 }
1308 else /* Empty polygon */
1309 {
1310 poly->rings = NULL;
1311 poly->maxrings = 0;
1312 }
1313
1314 for (i = 0; i < nrings; i++)
1315 {
1316 uint32_t npoints = 0;
1317
1318 /* Read in the number of points. */
1319 npoints = gserialized2_get_uint32_t(data_ptr);
1320 data_ptr += 4;
1321
1322 /* Make a point array for the ring, and move the ordinate pointer past the ring ordinates. */
1323 poly->rings[i] = ptarray_construct_reference_data(FLAGS_GET_Z(lwflags), FLAGS_GET_M(lwflags), npoints, ordinate_ptr);
1324
1325 ordinate_ptr += sizeof(double) * FLAGS_NDIMS(lwflags) * npoints;
1326 }
1327
1328 if (size)
1329 *size = ordinate_ptr - start_ptr;
1330
1331 return poly;
1332}
static uint32_t gserialized2_get_uint32_t(const uint8_t *loc)
POINTARRAY * ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist)
Construct a new POINTARRAY, referencing to the data from ptlist.
Definition ptarray.c:291
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
void * lwalloc(size_t size)
Definition lwutil.c:227
#define FLAGS_NDIMS(flags)
Definition liblwgeom.h:179
#define POLYGONTYPE
Definition liblwgeom.h:104
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:166
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
Definition lwutil.c:477
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
POINTARRAY ** rings
Definition liblwgeom.h:519
uint8_t type
Definition liblwgeom.h:522
uint32_t maxrings
Definition liblwgeom.h:525
uint32_t nrings
Definition liblwgeom.h:524
GBOX * bbox
Definition liblwgeom.h:518
lwflags_t flags
Definition liblwgeom.h:521
int32_t srid
Definition liblwgeom.h:520

References LWPOLY::bbox, LWPOLY::flags, FLAGS_GET_M, FLAGS_GET_Z, FLAGS_NDIMS, gserialized2_get_uint32_t(), lwalloc(), LWDEBUGF, lwflags(), LWPOLY::maxrings, LWPOLY::nrings, POLYGONTYPE, ptarray_construct_reference_data(), LWPOLY::rings, LWPOLY::srid, and LWPOLY::type.

Referenced by lwgeom_from_gserialized2_buffer().

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