PostGIS  2.5.7dev-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 643 of file gserialized_gist_2d.c.

644 {
645  GSERIALIZED *gpart;
646  uint8_t flags;
647  int result = LW_SUCCESS;
648 
649  POSTGIS_DEBUG(4, "entered function");
650 
651  /*
652  ** The most info we need is the 8 bytes of serialized header plus the
653  ** of floats necessary to hold the bounding box.
654  */
655  if (VARATT_IS_EXTENDED(gsdatum))
656  {
657  gpart = (GSERIALIZED*)PG_DETOAST_DATUM_SLICE(gsdatum, 0, 8 + sizeof(BOX2DF));
658  }
659  else
660  {
661  gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
662  }
663 
664  flags = gpart->flags;
665 
666  POSTGIS_DEBUGF(4, "got flags %d", gpart->flags);
667 
668  /* Do we even have a serialized bounding box? */
669  if ( FLAGS_GET_BBOX(flags) )
670  {
671  /* Yes! Copy it out into the box! */
672  POSTGIS_DEBUG(4, "copying box out of serialization");
673  memcpy(box2df, gpart->data, sizeof(BOX2DF));
674  result = LW_SUCCESS;
675  }
676  else
677  {
678  /* No, we need to calculate it from the full object. */
679  GBOX gbox;
680  GSERIALIZED *g = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
681 
682  gbox_init(&gbox);
683 
684  if (gserialized_get_gbox_p(g, &gbox) == LW_FAILURE)
685  {
686  POSTGIS_DEBUG(4, "could not calculate bbox, returning failure");
687  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
688  POSTGIS_FREE_IF_COPY_P(g, gsdatum);
689  return LW_FAILURE;
690  }
691  POSTGIS_FREE_IF_COPY_P(g, gsdatum);
692  result = box2df_from_gbox_p(&gbox, box2df);
693  }
694 
695  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
696 
697  if ( result == LW_SUCCESS )
698  {
699  POSTGIS_DEBUGF(4, "got box2df %s", box2df_to_string(box2df));
700  }
701 
702  return result;
703 }
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:47
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:640
static char * box2df_to_string(const BOX2DF *a)
static int box2df_from_gbox_p(GBOX *box, BOX2DF *a)
#define LW_FAILURE
Definition: liblwgeom.h:79
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:142
uint8_t flags
Definition: liblwgeom.h:386
uint8_t data[1]
Definition: liblwgeom.h:387
unsigned char uint8_t
Definition: uthash.h:79

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(), 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: