PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ 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));
546  result = LW_SUCCESS;
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  }
564 
565  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
566  return result;
567 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:324
#define LW_SUCCESS
Definition: liblwgeom.h:97
#define POSTGIS_FREE_IF_COPY_P(ptrsrc, ptrori)
Definition: lwinline.h:344
uint32_t size
Definition: liblwgeom.h:444

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: