PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ BOX3D_combine()

Datum BOX3D_combine ( PG_FUNCTION_ARGS  )

Definition at line 464 of file lwgeom_box3d.c.

465 {
466  BOX3D *box = (BOX3D *)PG_GETARG_POINTER(0);
467  GSERIALIZED *geom = PG_ARGISNULL(1) ? NULL : (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
468  LWGEOM *lwgeom = NULL;
469  BOX3D *result = NULL;
470  GBOX gbox;
471  int32_t srid;
472  int rv;
473 
474  /* Can't do anything with null inputs */
475  if (!box && !geom)
476  {
477  PG_RETURN_NULL();
478  }
479  /* Null geometry but non-null box, return the box */
480  else if (!geom)
481  {
482  result = palloc(sizeof(BOX3D));
483  memcpy(result, box, sizeof(BOX3D));
484  PG_RETURN_POINTER(result);
485  }
486 
487  /*
488  * Deserialize geometry and *calculate* the box
489  * We can't use the cached box because it's float, we *must* calculate
490  */
491  lwgeom = lwgeom_from_gserialized(geom);
492  srid = lwgeom->srid;
493  rv = lwgeom_calculate_gbox(lwgeom, &gbox);
494  lwgeom_free(lwgeom);
495 
496  /* If we couldn't calculate the box, return what we know */
497  if (rv == LW_FAILURE)
498  {
499  PG_FREE_IF_COPY(geom, 1);
500  /* No geom box, no input box, so null return */
501  if (!box)
502  PG_RETURN_NULL();
503  result = palloc(sizeof(BOX3D));
504  memcpy(result, box, sizeof(BOX3D));
505  PG_RETURN_POINTER(result);
506  }
507 
508  /* Null box and non-null geometry, just return the geometry box */
509  if (!box)
510  {
511  PG_FREE_IF_COPY(geom, 1);
512  result = box3d_from_gbox(&gbox);
513  result->srid = srid;
514  PG_RETURN_POINTER(result);
515  }
516 
517  result = palloc(sizeof(BOX3D));
518  result->xmax = Max(box->xmax, gbox.xmax);
519  result->ymax = Max(box->ymax, gbox.ymax);
520  result->zmax = Max(box->zmax, gbox.zmax);
521  result->xmin = Min(box->xmin, gbox.xmin);
522  result->ymin = Min(box->ymin, gbox.ymin);
523  result->zmin = Min(box->zmin, gbox.zmin);
524  result->srid = srid;
525 
526  PG_FREE_IF_COPY(geom, 1);
527  PG_RETURN_POINTER(result);
528 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: gbox.c:53
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
#define LW_FAILURE
Definition: liblwgeom.h:96
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
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:755
double xmax
Definition: liblwgeom.h:340
double zmin
Definition: liblwgeom.h:339
double ymax
Definition: liblwgeom.h:340
double ymin
Definition: liblwgeom.h:339
double zmax
Definition: liblwgeom.h:340
double xmin
Definition: liblwgeom.h:339
double ymax
Definition: liblwgeom.h:357
double zmax
Definition: liblwgeom.h:359
double xmax
Definition: liblwgeom.h:355
double zmin
Definition: liblwgeom.h:358
double ymin
Definition: liblwgeom.h:356
double xmin
Definition: liblwgeom.h:354
int32_t srid
Definition: liblwgeom.h:460

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