PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ BOX3D_combine()

Datum BOX3D_combine ( PG_FUNCTION_ARGS  )

Definition at line 455 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().

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