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

◆ gserialized1_set_gbox()

GSERIALIZED * gserialized1_set_gbox ( GSERIALIZED g,
GBOX gbox 
)

Update the bounding box of a GSERIALIZED, allocating a fresh one if there is not enough space to just write the new box in.

Copy a new bounding box into an existing gserialized.

WARNING if a new object needs to be created, the input pointer will have to be freed by the caller! Check to see if input == output. Returns null if there's a problem like mismatched dimensions.

Definition at line 1508 of file gserialized1.c.

1509{
1510
1511 int g_ndims = G1FLAGS_NDIMS_BOX(g->gflags);
1512 int box_ndims = FLAGS_NDIMS_BOX(gbox->flags);
1513 GSERIALIZED *g_out = NULL;
1514 size_t box_size = 2 * g_ndims * sizeof(float);
1515 float *fbox;
1516 int fbox_pos = 0;
1517
1518 /* The dimensionality of the inputs has to match or we are SOL. */
1519 if ( g_ndims != box_ndims )
1520 {
1521 return NULL;
1522 }
1523
1524 /* Serialized already has room for a box. */
1525 if (G1FLAGS_GET_BBOX(g->gflags))
1526 {
1527 g_out = g;
1528 }
1529 /* Serialized has no box. We need to allocate enough space for the old
1530 data plus the box, and leave a gap in the memory segment to write
1531 the new values into.
1532 */
1533 else
1534 {
1535 size_t varsize_new = SIZE_GET(g->size) + box_size;
1536 uint8_t *ptr;
1537 g_out = lwalloc(varsize_new);
1538 /* Copy the head of g into place */
1539 memcpy(g_out, g, 8);
1540 /* Copy the body of g into place after leaving space for the box */
1541 ptr = g_out->data;
1542 ptr += box_size;
1543 memcpy(ptr, g->data, SIZE_GET(g->size) - 8);
1544 G1FLAGS_SET_BBOX(g_out->gflags, 1);
1545 SIZE_SET(g_out->size, varsize_new);
1546 }
1547
1548 /* Move bounds to nearest float values */
1549 gbox_float_round(gbox);
1550 /* Now write the float box values into the memory segement */
1551 fbox = (float*)(g_out->data);
1552 /* Copy in X/Y */
1553 fbox[fbox_pos++] = gbox->xmin;
1554 fbox[fbox_pos++] = gbox->xmax;
1555 fbox[fbox_pos++] = gbox->ymin;
1556 fbox[fbox_pos++] = gbox->ymax;
1557 /* Optionally copy in higher dims */
1559 {
1560 fbox[fbox_pos++] = gbox->zmin;
1561 fbox[fbox_pos++] = gbox->zmax;
1562 }
1564 {
1565 fbox[fbox_pos++] = gbox->mmin;
1566 fbox[fbox_pos++] = gbox->mmax;
1567 }
1568
1569 return g_out;
1570}
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition gbox.c:774
int gserialized1_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
int gserialized1_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
int gserialized1_is_geodetic(const GSERIALIZED *gser)
Check if a GSERIALIZED is a geography.
#define G1FLAGS_SET_BBOX(gflags, value)
#define G1FLAGS_GET_BBOX(gflags)
#define G1FLAGS_NDIMS_BOX(gflags)
#define FLAGS_NDIMS_BOX(flags)
Definition liblwgeom.h:195
void * lwalloc(size_t size)
Definition lwutil.c:227
#define SIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
#define SIZE_SET(varsize, len)
double ymax
Definition liblwgeom.h:343
double zmax
Definition liblwgeom.h:345
double xmax
Definition liblwgeom.h:341
double zmin
Definition liblwgeom.h:344
double mmax
Definition liblwgeom.h:347
double ymin
Definition liblwgeom.h:342
double xmin
Definition liblwgeom.h:340
double mmin
Definition liblwgeom.h:346
lwflags_t flags
Definition liblwgeom.h:339
uint32_t size
Definition liblwgeom.h:430
uint8_t data[1]
Definition liblwgeom.h:433
uint8_t gflags
Definition liblwgeom.h:432

References GSERIALIZED::data, GBOX::flags, FLAGS_NDIMS_BOX, G1FLAGS_GET_BBOX, G1FLAGS_NDIMS_BOX, G1FLAGS_SET_BBOX, gbox_float_round(), GSERIALIZED::gflags, gserialized1_has_m(), gserialized1_has_z(), gserialized1_is_geodetic(), lwalloc(), GBOX::mmax, GBOX::mmin, GSERIALIZED::size, SIZE_GET, SIZE_SET, GBOX::xmax, GBOX::xmin, GBOX::ymax, GBOX::ymin, GBOX::zmax, and GBOX::zmin.

Referenced by gserialized_set_gbox().

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