PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ BOX3D_combine()

Datum BOX3D_combine ( PG_FUNCTION_ARGS  )

Definition at line 456 of file lwgeom_box3d.c.

457 {
458  BOX3D *box = (BOX3D *)PG_GETARG_POINTER(0);
459  GSERIALIZED *geom = PG_ARGISNULL(1) ? NULL : (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_POINTER(1));
460  LWGEOM *lwgeom = NULL;
461  BOX3D *result = NULL;
462  GBOX gbox;
463  int32_t srid;
464  int rv;
465 
466  /* Can't do anything with null inputs */
467  if (!box && !geom)
468  {
469  PG_RETURN_NULL();
470  }
471  /* Null geometry but non-null box, return the box */
472  else if (!geom)
473  {
474  result = palloc(sizeof(BOX3D));
475  memcpy(result, box, sizeof(BOX3D));
476  PG_RETURN_POINTER(result);
477  }
478 
479  /*
480  * Deserialize geometry and *calculate* the box
481  * We can't use the cached box because it's float, we *must* calculate
482  */
483  lwgeom = lwgeom_from_gserialized(geom);
484  srid = lwgeom->srid;
485  rv = lwgeom_calculate_gbox(lwgeom, &gbox);
486  lwgeom_free(lwgeom);
487 
488  /* If we couldn't calculate the box, return what we know */
489  if (rv == LW_FAILURE)
490  {
491  PG_FREE_IF_COPY(geom, 1);
492  /* No geom box, no input box, so null return */
493  if (!box)
494  PG_RETURN_NULL();
495  result = palloc(sizeof(BOX3D));
496  memcpy(result, box, sizeof(BOX3D));
497  PG_RETURN_POINTER(result);
498  }
499 
500  /* Null box and non-null geometry, just return the geometry box */
501  if (!box)
502  {
503  PG_FREE_IF_COPY(geom, 1);
504  result = box3d_from_gbox(&gbox);
505  result->srid = srid;
506  PG_RETURN_POINTER(result);
507  }
508 
509  result = palloc(sizeof(BOX3D));
510  result->xmax = Max(box->xmax, gbox.xmax);
511  result->ymax = Max(box->ymax, gbox.ymax);
512  result->zmax = Max(box->zmax, gbox.zmax);
513  result->xmin = Min(box->xmin, gbox.xmin);
514  result->ymin = Min(box->ymin, gbox.ymin);
515  result->zmin = Min(box->zmin, gbox.zmin);
516  result->srid = srid;
517 
518  PG_FREE_IF_COPY(geom, 1);
519  PG_RETURN_POINTER(result);
520 }
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:60
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define LW_FAILURE
Definition: liblwgeom.h:79
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
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 xmax
Definition: liblwgeom.h:281
double zmin
Definition: liblwgeom.h:280
double ymax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:280
double zmax
Definition: liblwgeom.h:281
double xmin
Definition: liblwgeom.h:280
int32_t srid
Definition: liblwgeom.h:282
double ymax
Definition: liblwgeom.h:298
double zmax
Definition: liblwgeom.h:300
double xmax
Definition: liblwgeom.h:296
double zmin
Definition: liblwgeom.h:299
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295
int32_t srid
Definition: liblwgeom.h:402

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.

Here is the call graph for this function: