PostGIS  2.3.8dev-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 552 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_distance_box_2d(), gserialized_distance_centroid_2d(), gserialized_gist_compress_2d(), gserialized_gist_consistent_2d(), and gserialized_gist_distance_2d().

553 {
554  GSERIALIZED *gpart;
555  uint8_t flags;
556  int result = LW_SUCCESS;
557 
558  POSTGIS_DEBUG(4, "entered function");
559 
560  /*
561  ** The most info we need is the 8 bytes of serialized header plus the
562  ** of floats necessary to hold the bounding box.
563  */
564  if (VARATT_IS_EXTENDED(gsdatum))
565  {
566  gpart = (GSERIALIZED*)PG_DETOAST_DATUM_SLICE(gsdatum, 0, 8 + sizeof(BOX2DF));
567  }
568  else
569  {
570  gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
571  }
572 
573  flags = gpart->flags;
574 
575  POSTGIS_DEBUGF(4, "got flags %d", gpart->flags);
576 
577  /* Do we even have a serialized bounding box? */
578  if ( FLAGS_GET_BBOX(flags) )
579  {
580  /* Yes! Copy it out into the box! */
581  POSTGIS_DEBUG(4, "copying box out of serialization");
582  memcpy(box2df, gpart->data, sizeof(BOX2DF));
583  result = LW_SUCCESS;
584  }
585  else
586  {
587  /* No, we need to calculate it from the full object. */
588  GBOX gbox;
589  GSERIALIZED *g = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
590 
591  gbox_init(&gbox);
592 
593  if (gserialized_get_gbox_p(g, &gbox) == LW_FAILURE)
594  {
595  POSTGIS_DEBUG(4, "could not calculate bbox, returning failure");
596  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
597  POSTGIS_FREE_IF_COPY_P(g, gsdatum);
598  return LW_FAILURE;
599  }
600  POSTGIS_FREE_IF_COPY_P(g, gsdatum);
601  result = box2df_from_gbox_p(&gbox, box2df);
602  }
603 
604  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
605 
606  if ( result == LW_SUCCESS )
607  {
608  POSTGIS_DEBUGF(4, "got box2df %s", box2df_to_string(box2df));
609  }
610 
611  return result;
612 }
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:398
uint8_t data[1]
Definition: liblwgeom.h:383
#define LW_SUCCESS
Definition: liblwgeom.h:79
#define LW_FAILURE
Definition: liblwgeom.h:78
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:141
static char * box2df_to_string(const BOX2DF *a)
uint8_t flags
Definition: liblwgeom.h:382
Here is the call graph for this function:
Here is the caller graph for this function: