PostGIS 3.7.0dev-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 1509 of file gserialized1.c.

1510{
1511
1512 int g_ndims = G1FLAGS_NDIMS_BOX(g->gflags);
1513 int box_ndims = FLAGS_NDIMS_BOX(gbox->flags);
1514 GSERIALIZED *g_out = NULL;
1515 size_t box_size = 2 * g_ndims * sizeof(float);
1516 float *fbox;
1517 int fbox_pos = 0;
1518
1519 /* The dimensionality of the inputs has to match or we are SOL. */
1520 if ( g_ndims != box_ndims )
1521 {
1522 return NULL;
1523 }
1524
1525 /* Serialized already has room for a box. */
1526 if (G1FLAGS_GET_BBOX(g->gflags))
1527 {
1528 g_out = g;
1529 }
1530 /* Serialized has no box. We need to allocate enough space for the old
1531 data plus the box, and leave a gap in the memory segment to write
1532 the new values into.
1533 */
1534 else
1535 {
1536 size_t varsize_new = LWSIZE_GET(g->size) + box_size;
1537 uint8_t *ptr;
1538 g_out = lwalloc(varsize_new);
1539 /* Copy the head of g into place */
1540 memcpy(g_out, g, 8);
1541 /* Copy the body of g into place after leaving space for the box */
1542 ptr = g_out->data;
1543 ptr += box_size;
1544 memcpy(ptr, g->data, LWSIZE_GET(g->size) - 8);
1545 G1FLAGS_SET_BBOX(g_out->gflags, 1);
1546 LWSIZE_SET(g_out->size, varsize_new);
1547 }
1548
1549 /* Move bounds to nearest float values */
1550 gbox_float_round(gbox);
1551 /* Now write the float box values into the memory segment */
1552 fbox = (float*)(g_out->data);
1553 /* Copy in X/Y */
1554 fbox[fbox_pos++] = gbox->xmin;
1555 fbox[fbox_pos++] = gbox->xmax;
1556 fbox[fbox_pos++] = gbox->ymin;
1557 fbox[fbox_pos++] = gbox->ymax;
1558 /* Optionally copy in higher dims */
1560 {
1561 fbox[fbox_pos++] = gbox->zmin;
1562 fbox[fbox_pos++] = gbox->zmax;
1563 }
1565 {
1566 fbox[fbox_pos++] = gbox->mmin;
1567 fbox[fbox_pos++] = gbox->mmax;
1568 }
1569
1570 return g_out;
1571}
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition gbox.c:786
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:181
#define LWSIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
Definition liblwgeom.h:324
void * lwalloc(size_t size)
Definition lwutil.c:227
#define LWSIZE_SET(varsize, len)
Definition liblwgeom.h:325
double ymax
Definition liblwgeom.h:357
double zmax
Definition liblwgeom.h:359
double xmax
Definition liblwgeom.h:355
double zmin
Definition liblwgeom.h:358
double mmax
Definition liblwgeom.h:361
double ymin
Definition liblwgeom.h:356
double xmin
Definition liblwgeom.h:354
double mmin
Definition liblwgeom.h:360
lwflags_t flags
Definition liblwgeom.h:353
uint32_t size
Definition liblwgeom.h:444
uint8_t data[1]
Definition liblwgeom.h:447
uint8_t gflags
Definition liblwgeom.h:446

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(), LWSIZE_GET, LWSIZE_SET, GBOX::mmax, GBOX::mmin, GSERIALIZED::size, 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: