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

◆ gserialized_datum_get_box2df_p()

int gserialized_datum_get_box2df_p ( Datum  gsdatum,
BOX2DF *  box2df 
)

Definition at line 527 of file gserialized_gist_2d.c.

528{
529 int result = LW_SUCCESS;
530 GSERIALIZED *gpart = NULL;
531 int need_detoast = PG_GSERIALIZED_DATUM_NEEDS_DETOAST((struct varlena *)gsdatum);
532 if (need_detoast)
533 {
534 gpart = (GSERIALIZED *)PG_DETOAST_DATUM_SLICE(gsdatum, 0, gserialized_max_header_size());
535 }
536 else
537 {
538 gpart = (GSERIALIZED *)gsdatum;
539 }
540
541 if (gserialized_has_bbox(gpart))
542 {
543 size_t box_ndims;
544 const float *f = gserialized_get_float_box_p(gpart, &box_ndims);
545 memcpy(box2df, f, sizeof(BOX2DF));
547 }
548 else
549 {
550 GBOX gbox = {0};
551 if (need_detoast && LWSIZE_GET(gpart->size) >= gserialized_max_header_size())
552 {
553 /* The headers don't contain a bbox and the object is larger than what we retrieved, so
554 * we now detoast it completely and recheck */
555 POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
556 gpart = (GSERIALIZED *)PG_DETOAST_DATUM(gsdatum);
557 }
558 result = gserialized_get_gbox_p(gpart, &gbox);
559 if (result == LW_SUCCESS)
560 {
561 result = box2df_from_gbox_p(&gbox, box2df);
562 }
563 else {
564 /* Oh dear, has someone fed us an empty? */
565 POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
566 gpart = (GSERIALIZED *)PG_DETOAST_DATUM(gsdatum);
567 if (gserialized_is_empty(gpart))
568 {
569 box2df_set_empty(box2df);
570 return LW_SUCCESS;
571 }
572 }
573 }
574
575 POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
576 return result;
577}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
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:94
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
uint32_t gserialized_max_header_size(void)
Returns the size in bytes to read from toast to get the basic information from a geometry: GSERIALIZE...
void box2df_set_empty(BOX2DF *a)
static int box2df_from_gbox_p(GBOX *box, BOX2DF *a)
#define LWSIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
Definition liblwgeom.h:324
#define LW_SUCCESS
Definition liblwgeom.h:97
#define POSTGIS_FREE_IF_COPY_P(ptrsrc, ptrori)
Definition lwinline.h:340
uint32_t size
Definition liblwgeom.h:444

References box2df_from_gbox_p(), box2df_set_empty(), gserialized_get_float_box_p(), gserialized_get_gbox_p(), gserialized_has_bbox(), gserialized_is_empty(), gserialized_max_header_size(), LW_SUCCESS, LWSIZE_GET, POSTGIS_FREE_IF_COPY_P, result, and GSERIALIZED::size.

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: