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

Definition at line 350 of file lwgeom_box3d.c.

References box3d_from_gbox(), LW_FAILURE, lwgeom_calculate_gbox(), lwgeom_free(), lwgeom_from_gserialized(), result, 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.

351 {
352  BOX3D *box = (BOX3D*)PG_GETARG_POINTER(0);
353  GSERIALIZED *geom = PG_ARGISNULL(1) ? NULL : (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_POINTER(1));
354  LWGEOM *lwgeom = NULL;
355  BOX3D *result = NULL;
356  GBOX gbox;
357  int32_t srid;
358  int rv;
359 
360  /* Can't do anything with null inputs */
361  if ( (box == NULL) && (geom == NULL) )
362  PG_RETURN_NULL();
363 
364  /* Null geometry but non-null box, return the box */
365  if (geom == NULL)
366  {
367  result = palloc(sizeof(BOX3D));
368  memcpy(result, box, sizeof(BOX3D));
369  PG_RETURN_POINTER(result);
370  }
371 
372  /* Deserialize geometry and *calculate* the box */
373  /* We can't use the cached box because it's float, we *must* calculate */
374  lwgeom = lwgeom_from_gserialized(geom);
375  srid = lwgeom->srid;
376  rv = lwgeom_calculate_gbox(lwgeom, &gbox);
377  lwgeom_free(lwgeom);
378 
379  /* If we couldn't calculate the box, return what we know */
380  if ( rv == LW_FAILURE )
381  {
382  PG_FREE_IF_COPY(geom, 1);
383  /* No geom box, no input box, so null return */
384  if ( box == NULL )
385  PG_RETURN_NULL();
386  result = palloc(sizeof(BOX3D));
387  memcpy(result, box, sizeof(BOX3D));
388  PG_RETURN_POINTER(result);
389  }
390 
391  /* Null box and non-null geometry, just return the geometry box */
392  if ( box == NULL )
393  {
394  PG_FREE_IF_COPY(geom, 1);
395  result = box3d_from_gbox(&gbox);
396  result->srid = srid;
397  PG_RETURN_POINTER(result);
398  }
399 
400  result = palloc(sizeof(BOX3D));
401  result->xmax = Max(box->xmax, gbox.xmax);
402  result->ymax = Max(box->ymax, gbox.ymax);
403  result->zmax = Max(box->zmax, gbox.zmax);
404  result->xmin = Min(box->xmin, gbox.xmin);
405  result->ymin = Min(box->ymin, gbox.ymin);
406  result->zmin = Min(box->zmin, gbox.zmin);
407  result->srid = srid;
408 
409  PG_FREE_IF_COPY(geom, 1);
410  PG_RETURN_POINTER(result);
411 }
int32_t srid
Definition: liblwgeom.h:235
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:249
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
double ymin
Definition: liblwgeom.h:233
char ** result
Definition: liblwgeom.h:218
int32_t srid
Definition: liblwgeom.h:355
#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
double ymin
Definition: liblwgeom.h:250
double zmax
Definition: liblwgeom.h:253
double xmin
Definition: liblwgeom.h:248
double xmin
Definition: liblwgeom.h:233
double ymax
Definition: liblwgeom.h:251
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:47
double xmax
Definition: liblwgeom.h:234
double zmin
Definition: liblwgeom.h:252
double ymax
Definition: liblwgeom.h:234
double zmax
Definition: liblwgeom.h:234
double zmin
Definition: liblwgeom.h:233

Here is the call graph for this function: