PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ 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 587 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(), LW_FAILURE, 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().

588 {
589  GSERIALIZED *gpart;
590  uint8_t flags;
591  int result = LW_SUCCESS;
592 
593  POSTGIS_DEBUG(4, "entered function");
594 
595  /*
596  ** The most info we need is the 8 bytes of serialized header plus the
597  ** of floats necessary to hold the bounding box.
598  */
599  if (VARATT_IS_EXTENDED(gsdatum))
600  {
601  gpart = (GSERIALIZED*)PG_DETOAST_DATUM_SLICE(gsdatum, 0, 8 + sizeof(BOX2DF));
602  }
603  else
604  {
605  gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
606  }
607 
608  flags = gpart->flags;
609 
610  POSTGIS_DEBUGF(4, "got flags %d", gpart->flags);
611 
612  /* Do we even have a serialized bounding box? */
613  if ( FLAGS_GET_BBOX(flags) )
614  {
615  /* Yes! Copy it out into the box! */
616  POSTGIS_DEBUG(4, "copying box out of serialization");
617  memcpy(box2df, gpart->data, sizeof(BOX2DF));
618  result = LW_SUCCESS;
619  }
620  else
621  {
622  /* No, we need to calculate it from the full object. */
623  GBOX gbox;
624  GSERIALIZED *g = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
625 
626  gbox_init(&gbox);
627 
628  if (gserialized_get_gbox_p(g, &gbox) == LW_FAILURE)
629  {
630  POSTGIS_DEBUG(4, "could not calculate bbox, returning failure");
631  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
632  POSTGIS_FREE_IF_COPY_P(g, gsdatum);
633  return LW_FAILURE;
634  }
635  POSTGIS_FREE_IF_COPY_P(g, gsdatum);
636  result = box2df_from_gbox_p(&gbox, box2df);
637  }
638 
639  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
640 
641  if ( result == LW_SUCCESS )
642  {
643  POSTGIS_DEBUGF(4, "got box2df %s", box2df_to_string(box2df));
644  }
645 
646  return result;
647 }
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:642
uint8_t data[1]
Definition: liblwgeom.h:384
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define LW_FAILURE
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:51
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:142
static char * box2df_to_string(const BOX2DF *a)
unsigned char uint8_t
Definition: uthash.h:79
uint8_t flags
Definition: liblwgeom.h:383
Here is the call graph for this function:
Here is the caller graph for this function: