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

Definition at line 481 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.

482 {
483  BOX3D *box = (BOX3D*)PG_GETARG_POINTER(0);
484  GSERIALIZED *geom = PG_ARGISNULL(1) ? NULL : (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_POINTER(1));
485  LWGEOM *lwgeom = NULL;
486  BOX3D *result = NULL;
487  GBOX gbox;
488  int32_t srid;
489  int rv;
490 
491  /* Can't do anything with null inputs */
492  if ( (box == NULL) && (geom == NULL) )
493  PG_RETURN_NULL();
494 
495  /* Null geometry but non-null box, return the box */
496  if (geom == NULL)
497  {
498  result = palloc(sizeof(BOX3D));
499  memcpy(result, box, sizeof(BOX3D));
500  PG_RETURN_POINTER(result);
501  }
502 
503  /* Deserialize geometry and *calculate* the box */
504  /* We can't use the cached box because it's float, we *must* calculate */
505  lwgeom = lwgeom_from_gserialized(geom);
506  srid = lwgeom->srid;
507  rv = lwgeom_calculate_gbox(lwgeom, &gbox);
508  lwgeom_free(lwgeom);
509 
510  /* If we couldn't calculate the box, return what we know */
511  if ( rv == LW_FAILURE )
512  {
513  PG_FREE_IF_COPY(geom, 1);
514  /* No geom box, no input box, so null return */
515  if ( box == NULL )
516  PG_RETURN_NULL();
517  result = palloc(sizeof(BOX3D));
518  memcpy(result, box, sizeof(BOX3D));
519  PG_RETURN_POINTER(result);
520  }
521 
522  /* Null box and non-null geometry, just return the geometry box */
523  if ( box == NULL )
524  {
525  PG_FREE_IF_COPY(geom, 1);
526  result = box3d_from_gbox(&gbox);
527  result->srid = srid;
528  PG_RETURN_POINTER(result);
529  }
530 
531  result = palloc(sizeof(BOX3D));
532  result->xmax = Max(box->xmax, gbox.xmax);
533  result->ymax = Max(box->ymax, gbox.ymax);
534  result->zmax = Max(box->zmax, gbox.zmax);
535  result->xmin = Min(box->xmin, gbox.xmin);
536  result->ymin = Min(box->ymin, gbox.ymin);
537  result->zmin = Min(box->zmin, gbox.zmin);
538  result->srid = srid;
539 
540  PG_FREE_IF_COPY(geom, 1);
541  PG_RETURN_POINTER(result);
542 }
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:1063
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:665
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:64
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: