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

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function: