PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum BOX3D_combine ( PG_FUNCTION_ARGS  )

Definition at line 479 of file lwgeom_box3d.c.

References box3d_from_gbox(), LW_FAILURE, lwgeom_calculate_gbox(), lwgeom_free(), lwgeom_from_gserialized(), BOX3D::srid, LWGEOM::srid, BOX3D::xmax, GBOX::xmax, BOX3D::xmin, GBOX::xmin, BOX3D::ymax, GBOX::ymax, BOX3D::ymin, GBOX::ymin, BOX3D::zmax, GBOX::zmax, BOX3D::zmin, and GBOX::zmin.

480 {
481  BOX3D *box = (BOX3D*)PG_GETARG_POINTER(0);
482  GSERIALIZED *geom = PG_ARGISNULL(1) ? NULL : (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_POINTER(1));
483  LWGEOM *lwgeom = NULL;
484  BOX3D *result = NULL;
485  GBOX gbox;
486  int32_t srid;
487  int rv;
488 
489  /* Can't do anything with null inputs */
490  if ((box == NULL) && (geom == NULL)) { PG_RETURN_NULL(); }
491  /* Null geometry but non-null box, return the box */
492  else if (geom == NULL)
493  {
494  result = palloc(sizeof(BOX3D));
495  memcpy(result, box, sizeof(BOX3D));
496  PG_RETURN_POINTER(result);
497  }
498 
499  /* Deserialize geometry and *calculate* the box */
500  /* We can't use the cached box because it's float, we *must* calculate */
501  lwgeom = lwgeom_from_gserialized(geom);
502  srid = lwgeom->srid;
503  rv = lwgeom_calculate_gbox(lwgeom, &gbox);
504  lwgeom_free(lwgeom);
505 
506  /* If we couldn't calculate the box, return what we know */
507  if ( rv == LW_FAILURE )
508  {
509  PG_FREE_IF_COPY(geom, 1);
510  /* No geom box, no input box, so null return */
511  if ( box == NULL )
512  PG_RETURN_NULL();
513  result = palloc(sizeof(BOX3D));
514  memcpy(result, box, sizeof(BOX3D));
515  PG_RETURN_POINTER(result);
516  }
517 
518  /* Null box and non-null geometry, just return the geometry box */
519  if ( box == NULL )
520  {
521  PG_FREE_IF_COPY(geom, 1);
522  result = box3d_from_gbox(&gbox);
523  result->srid = srid;
524  PG_RETURN_POINTER(result);
525  }
526 
527  result = palloc(sizeof(BOX3D));
528  result->xmax = Max(box->xmax, gbox.xmax);
529  result->ymax = Max(box->ymax, gbox.ymax);
530  result->zmax = Max(box->zmax, gbox.zmax);
531  result->xmin = Min(box->xmin, gbox.xmin);
532  result->ymin = Min(box->ymin, gbox.ymin);
533  result->zmin = Min(box->zmin, gbox.zmin);
534  result->srid = srid;
535 
536  PG_FREE_IF_COPY(geom, 1);
537  PG_RETURN_POINTER(result);
538 }
int32_t srid
Definition: liblwgeom.h:278
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:292
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
double ymin
Definition: liblwgeom.h:276
int32_t srid
Definition: liblwgeom.h:398
#define LW_FAILURE
Definition: liblwgeom.h:78
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:739
double ymin
Definition: liblwgeom.h:293
double zmax
Definition: liblwgeom.h:296
double xmin
Definition: liblwgeom.h:291
double xmin
Definition: liblwgeom.h:276
double ymax
Definition: liblwgeom.h:294
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:60
double xmax
Definition: liblwgeom.h:277
double zmin
Definition: liblwgeom.h:295
double ymax
Definition: liblwgeom.h:277
double zmax
Definition: liblwgeom.h:277
double zmin
Definition: liblwgeom.h:276

Here is the call graph for this function: