PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ BOX3D_combine()

Datum BOX3D_combine ( PG_FUNCTION_ARGS  )

Definition at line 479 of file lwgeom_box3d.c.

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

Referenced by BOX3D_zmax().

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) )
491  PG_RETURN_NULL();
492 
493  /* Null geometry but non-null box, return the box */
494  if (geom == NULL)
495  {
496  result = palloc(sizeof(BOX3D));
497  memcpy(result, box, sizeof(BOX3D));
498  PG_RETURN_POINTER(result);
499  }
500 
501  /* Deserialize geometry and *calculate* the box */
502  /* We can't use the cached box because it's float, we *must* calculate */
503  lwgeom = lwgeom_from_gserialized(geom);
504  srid = lwgeom->srid;
505  rv = lwgeom_calculate_gbox(lwgeom, &gbox);
506  lwgeom_free(lwgeom);
507 
508  /* If we couldn't calculate the box, return what we know */
509  if ( rv == LW_FAILURE )
510  {
511  PG_FREE_IF_COPY(geom, 1);
512  /* No geom box, no input box, so null return */
513  if ( box == NULL )
514  PG_RETURN_NULL();
515  result = palloc(sizeof(BOX3D));
516  memcpy(result, box, sizeof(BOX3D));
517  PG_RETURN_POINTER(result);
518  }
519 
520  /* Null box and non-null geometry, just return the geometry box */
521  if ( box == NULL )
522  {
523  PG_FREE_IF_COPY(geom, 1);
524  result = box3d_from_gbox(&gbox);
525  result->srid = srid;
526  PG_RETURN_POINTER(result);
527  }
528 
529  result = palloc(sizeof(BOX3D));
530  result->xmax = Max(box->xmax, gbox.xmax);
531  result->ymax = Max(box->ymax, gbox.ymax);
532  result->zmax = Max(box->zmax, gbox.zmax);
533  result->xmin = Min(box->xmin, gbox.xmin);
534  result->ymin = Min(box->ymin, gbox.ymin);
535  result->zmin = Min(box->zmin, gbox.zmin);
536  result->srid = srid;
537 
538  PG_FREE_IF_COPY(geom, 1);
539  PG_RETURN_POINTER(result);
540 }
int32_t srid
Definition: liblwgeom.h:279
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:293
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
double ymin
Definition: liblwgeom.h:277
int32_t srid
Definition: liblwgeom.h:399
#define LW_FAILURE
Definition: liblwgeom.h:79
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:701
double ymin
Definition: liblwgeom.h:294
double zmax
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:292
double xmin
Definition: liblwgeom.h:277
double ymax
Definition: liblwgeom.h:295
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:64
double xmax
Definition: liblwgeom.h:278
double zmin
Definition: liblwgeom.h:296
double ymax
Definition: liblwgeom.h:278
double zmax
Definition: liblwgeom.h:278
double zmin
Definition: liblwgeom.h:277
Here is the call graph for this function:
Here is the caller graph for this function: