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

◆ gserialized_datum_get_box2df_p()

int gserialized_datum_get_box2df_p ( Datum  gsdatum,
BOX2DF *  box2df 
)

Peak into a GSERIALIZED datum to find the bounding box.

If the box is there, copy it out and return it. If not, calculate the box from the full object and return the box based on that. If no box is available, return LW_FAILURE, otherwise LW_SUCCESS.

Definition at line 450 of file gserialized_gist_2d.c.

451{
452 GSERIALIZED *gpart;
453 int result = LW_SUCCESS;
454
455 POSTGIS_DEBUG(4, "entered function");
456
457 /*
458 ** Because geometry is declared as "storage = main" anything large
459 ** enough to take serious advantage of PG_DETOAST_DATUM_SLICE will have
460 ** already been compressed, which means the entire object will be
461 ** fetched and decompressed before a slice is taken, thus removing
462 ** any efficiencies gained from slicing.
463 ** As of Pg12 we can partially decompress a toasted object
464 ** (though we still need to fully retrieve it from TOAST)
465 ** which makes slicing worthwhile.
466 */
467 gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
468
469 POSTGIS_DEBUGF(4, "got flags %d", gpart->gflags);
470
471 /* Do we even have a serialized bounding box? */
472 if (gserialized_has_bbox(gpart))
473 {
474 /* Yes! Copy it out into the box! */
475 size_t box_ndims;
476 const float *f = gserialized_get_float_box_p(gpart, &box_ndims);
477
478 POSTGIS_DEBUG(4, "copying box out of serialization");
479 memcpy(box2df, f, sizeof(BOX2DF));
480 result = LW_SUCCESS;
481 }
482 else
483 {
484 /* No, we need to calculate it from the full object. */
485 GBOX gbox;
486 gbox_init(&gbox);
487
488 result = gserialized_get_gbox_p(gpart, &gbox);
489 if ( result == LW_SUCCESS )
490 {
491 result = box2df_from_gbox_p(&gbox, box2df);
492 }
493 else
494 {
495 POSTGIS_DEBUG(4, "could not calculate bbox");
496 }
497 }
498
499 POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
500 POSTGIS_DEBUGF(4, "result = %d, got box2df %s", result, result == LW_SUCCESS ? box2df_to_string(box2df) : "NONE");
501
502 return result;
503}
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition gbox.c:40
const float * gserialized_get_float_box_p(const GSERIALIZED *g, size_t *ndims)
Access to the float bounding box, if there is one.
int gserialized_has_bbox(const GSERIALIZED *g)
Check if a GSERIALIZED has a bounding box without deserializing first.
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
Definition gserialized.c:65
static char * box2df_to_string(const BOX2DF *a)
static int box2df_from_gbox_p(GBOX *box, BOX2DF *a)
#define LW_SUCCESS
Definition liblwgeom.h:111
#define POSTGIS_FREE_IF_COPY_P(ptrsrc, ptrori)
Definition lwinline.h:235
uint8_t gflags
Definition liblwgeom.h:432

References box2df_from_gbox_p(), box2df_to_string(), gbox_init(), GSERIALIZED::gflags, gserialized_get_float_box_p(), gserialized_get_gbox_p(), gserialized_has_bbox(), LW_SUCCESS, and POSTGIS_FREE_IF_COPY_P.

Referenced by geom2d_brin_inclusion_add_value(), gserialized_datum_predicate_2d(), gserialized_datum_predicate_box2df_geom_2d(), gserialized_distance_box_2d(), gserialized_distance_centroid_2d(), gserialized_gist_compress_2d(), gserialized_gist_consistent_2d(), gserialized_gist_distance_2d(), gserialized_spgist_compress_2d(), gserialized_spgist_inner_consistent_2d(), and gserialized_spgist_leaf_consistent_2d().

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