PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ gserialized_datum_get_box2df_p()

int gserialized_datum_get_box2df_p ( Datum  gsdatum,
BOX2DF *  box2df 
)

Definition at line 511 of file gserialized_gist_2d.c.

512 {
513  int result = LW_SUCCESS;
514  GSERIALIZED *gpart = NULL;
515  int need_detoast = PG_GSERIALIZED_DATUM_NEEDS_DETOAST((struct varlena *)gsdatum);
516  if (need_detoast)
517  {
518  gpart = (GSERIALIZED *)PG_DETOAST_DATUM_SLICE(gsdatum, 0, gserialized_max_header_size());
519  }
520  else
521  {
522  gpart = (GSERIALIZED *)gsdatum;
523  }
524 
525  if (gserialized_has_bbox(gpart))
526  {
527  size_t box_ndims;
528  const float *f = gserialized_get_float_box_p(gpart, &box_ndims);
529  memcpy(box2df, f, sizeof(BOX2DF));
530  result = LW_SUCCESS;
531  }
532  else
533  {
534  GBOX gbox = {0};
535  if (need_detoast && LWSIZE_GET(gpart->size) >= gserialized_max_header_size())
536  {
537  /* The headers don't contain a bbox and the object is larger than what we retrieved, so
538  * we now detoast it completely and recheck */
539  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
540  gpart = (GSERIALIZED *)PG_DETOAST_DATUM(gsdatum);
541  }
542  result = gserialized_get_gbox_p(gpart, &gbox);
543  if (result == LW_SUCCESS)
544  {
545  result = box2df_from_gbox_p(&gbox, box2df);
546  }
547  }
548 
549  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
550  return result;
551 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
int gserialized_has_bbox(const GSERIALIZED *g)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: gserialized.c:163
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
const float * gserialized_get_float_box_p(const GSERIALIZED *g, size_t *ndims)
Access to the float bounding box, if there is one.
Definition: gserialized.c:248
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...
Definition: gserialized.c:101
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:338
#define LW_SUCCESS
Definition: liblwgeom.h:111
#define POSTGIS_FREE_IF_COPY_P(ptrsrc, ptrori)
Definition: lwinline.h:245
uint32_t size
Definition: liblwgeom.h:458

References box2df_from_gbox_p(), gserialized_get_float_box_p(), gserialized_get_gbox_p(), gserialized_has_bbox(), 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: