PostGIS  2.5.0beta1dev-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)) { 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:281
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:295
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
double ymin
Definition: liblwgeom.h:279
int32_t srid
Definition: liblwgeom.h:401
#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:746
double ymin
Definition: liblwgeom.h:296
double zmax
Definition: liblwgeom.h:299
double xmin
Definition: liblwgeom.h:294
double xmin
Definition: liblwgeom.h:279
double ymax
Definition: liblwgeom.h:297
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:60
double xmax
Definition: liblwgeom.h:280
double zmin
Definition: liblwgeom.h:298
double ymax
Definition: liblwgeom.h:280
double zmax
Definition: liblwgeom.h:280
double zmin
Definition: liblwgeom.h:279
Here is the call graph for this function:
Here is the caller graph for this function: