PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ gserialized_datum_get_box2df_p()

static int gserialized_datum_get_box2df_p ( Datum  gsdatum,
BOX2DF *  box2df 
)
static

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 528 of file gserialized_gist_2d.c.

References box2df_from_gbox_p(), box2df_to_string(), GSERIALIZED::data, GSERIALIZED::flags, FLAGS_GET_BBOX, LW_FAILURE, LW_SUCCESS, lwgeom_calculate_gbox(), lwgeom_free(), and lwgeom_from_gserialized().

Referenced by 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().

529 {
530  GSERIALIZED *gpart;
531  uint8_t flags;
532  int result = LW_SUCCESS;
533 
534  POSTGIS_DEBUG(4, "entered function");
535 
536  /*
537  ** The most info we need is the 8 bytes of serialized header plus the
538  ** of floats necessary to hold the bounding box.
539  */
540  if (VARATT_IS_EXTENDED(gsdatum))
541  {
542  gpart = (GSERIALIZED*)PG_DETOAST_DATUM_SLICE(gsdatum, 0, 8 + sizeof(BOX2DF));
543  }
544  else
545  {
546  gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
547  }
548 
549  flags = gpart->flags;
550 
551  POSTGIS_DEBUGF(4, "got flags %d", gpart->flags);
552 
553  /* Do we even have a serialized bounding box? */
554  if ( FLAGS_GET_BBOX(flags) )
555  {
556  /* Yes! Copy it out into the box! */
557  POSTGIS_DEBUG(4, "copying box out of serialization");
558  memcpy(box2df, gpart->data, sizeof(BOX2DF));
559  result = LW_SUCCESS;
560  }
561  else
562  {
563  /* No, we need to calculate it from the full object. */
564  GBOX gbox;
565  GSERIALIZED *g = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
566  LWGEOM *lwgeom = lwgeom_from_gserialized(g);
567  if ( lwgeom_calculate_gbox(lwgeom, &gbox) == LW_FAILURE )
568  {
569  POSTGIS_DEBUG(4, "could not calculate bbox, returning failure");
570  lwgeom_free(lwgeom);
571  return LW_FAILURE;
572  }
573  lwgeom_free(lwgeom);
574  result = box2df_from_gbox_p(&gbox, box2df);
575  }
576 
577  if ( result == LW_SUCCESS )
578  {
579  POSTGIS_DEBUGF(4, "got box2df %s", box2df_to_string(box2df));
580  }
581 
582  return result;
583 }
uint8_t data[1]
Definition: liblwgeom.h:368
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
#define LW_SUCCESS
Definition: liblwgeom.h:65
#define LW_FAILURE
Definition: liblwgeom.h:64
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:652
static int box2df_from_gbox_p(GBOX *box, BOX2DF *a)
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:126
static char * box2df_to_string(const BOX2DF *a)
uint8_t flags
Definition: liblwgeom.h:367
Here is the call graph for this function:
Here is the caller graph for this function: