PostGIS  2.5.0dev-r@@SVN_REVISION@@
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 643 of file gserialized_gist_2d.c.

References box2df_from_gbox_p(), box2df_to_string(), GSERIALIZED::data, GSERIALIZED::flags, FLAGS_GET_BBOX, gbox_init(), gserialized_get_gbox_p(), and LW_SUCCESS.

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(), and gserialized_gist_distance_2d().

644 {
645  GSERIALIZED *gpart;
646  uint8_t flags;
647  int result = LW_SUCCESS;
648 
649  POSTGIS_DEBUG(4, "entered function");
650 
651  /*
652  ** Because geometry is declared as "storage = main" anything large
653  ** enough to take serious advantage of PG_DETOAST_DATUM_SLICE will have
654  ** already been compressed, which means the entire object will be
655  ** fetched and decompressed before a slice is taken, thus removing
656  ** any efficiencies gained from slicing. We need to move to
657  ** "storage = external" and implement our own geometry compressor
658  ** before we can take advantage of sliced retrieval.
659  */
660  gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
661  flags = gpart->flags;
662 
663  POSTGIS_DEBUGF(4, "got flags %d", gpart->flags);
664 
665  /* Do we even have a serialized bounding box? */
666  if ( FLAGS_GET_BBOX(flags) )
667  {
668  /* Yes! Copy it out into the box! */
669  POSTGIS_DEBUG(4, "copying box out of serialization");
670  memcpy(box2df, gpart->data, sizeof(BOX2DF));
671  result = LW_SUCCESS;
672  }
673  else
674  {
675  /* No, we need to calculate it from the full object. */
676  GBOX gbox;
677  gbox_init(&gbox);
678 
679  result = gserialized_get_gbox_p(gpart, &gbox);
680  if ( result == LW_SUCCESS )
681  {
682  result = box2df_from_gbox_p(&gbox, box2df);
683  }
684  else
685  {
686  POSTGIS_DEBUG(4, "could not calculate bbox");
687  }
688  }
689 
690  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
691  POSTGIS_DEBUGF(4, "result = %d, got box2df %s", result, result == LW_SUCCESS ? box2df_to_string(box2df) : "NONE");
692 
693  return result;
694 }
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
Definition: g_serialized.c:639
uint8_t data[1]
Definition: liblwgeom.h:383
#define LW_SUCCESS
Definition: liblwgeom.h:79
static int box2df_from_gbox_p(GBOX *box, BOX2DF *a)
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:47
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:141
static char * box2df_to_string(const BOX2DF *a)
unsigned char uint8_t
Definition: uthash.h:79
uint8_t flags
Definition: liblwgeom.h:382

Here is the call graph for this function:

Here is the caller graph for this function: