PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ BOX3D_combine()

Datum BOX3D_combine ( PG_FUNCTION_ARGS  )

Definition at line 349 of file lwgeom_box3d.c.

References BOX3D_construct(), 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().

350 {
351  BOX3D *box = (BOX3D*)PG_GETARG_POINTER(0);
352  GSERIALIZED *geom = PG_ARGISNULL(1) ? NULL : (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_POINTER(1));
353  LWGEOM *lwgeom = NULL;
354  BOX3D *result = NULL;
355  GBOX gbox;
356  int32_t srid;
357  int rv;
358 
359  /* Can't do anything with null inputs */
360  if ( (box == NULL) && (geom == NULL) )
361  PG_RETURN_NULL();
362 
363  /* Null geometry but non-null box, return the box */
364  if (geom == NULL)
365  {
366  result = palloc(sizeof(BOX3D));
367  memcpy(result, box, sizeof(BOX3D));
368  PG_RETURN_POINTER(result);
369  }
370 
371  /* Deserialize geometry and *calculate* the box */
372  /* We can't use the cached box because it's float, we *must* calculate */
373  lwgeom = lwgeom_from_gserialized(geom);
374  srid = lwgeom->srid;
375  rv = lwgeom_calculate_gbox(lwgeom, &gbox);
376  lwgeom_free(lwgeom);
377 
378  /* If we couldn't calculate the box, return what we know */
379  if ( rv == LW_FAILURE )
380  {
381  PG_FREE_IF_COPY(geom, 1);
382  /* No geom box, no input box, so null return */
383  if ( box == NULL )
384  PG_RETURN_NULL();
385  result = palloc(sizeof(BOX3D));
386  memcpy(result, box, sizeof(BOX3D));
387  PG_RETURN_POINTER(result);
388  }
389 
390  /* Null box and non-null geometry, just return the geometry box */
391  if ( box == NULL )
392  {
393  PG_FREE_IF_COPY(geom, 1);
394  result = box3d_from_gbox(&gbox);
395  result->srid = srid;
396  PG_RETURN_POINTER(result);
397  }
398 
399  result = palloc(sizeof(BOX3D));
400  result->xmax = Max(box->xmax, gbox.xmax);
401  result->ymax = Max(box->ymax, gbox.ymax);
402  result->zmax = Max(box->zmax, gbox.zmax);
403  result->xmin = Min(box->xmin, gbox.xmin);
404  result->ymin = Min(box->ymin, gbox.ymin);
405  result->zmin = Min(box->zmin, gbox.zmin);
406  result->srid = srid;
407 
408  PG_FREE_IF_COPY(geom, 1);
409  PG_RETURN_POINTER(result);
410 }
int32_t srid
Definition: liblwgeom.h:263
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:277
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
double ymin
Definition: liblwgeom.h:261
int32_t srid
Definition: liblwgeom.h:383
#define LW_FAILURE
Definition: liblwgeom.h:64
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:652
double ymin
Definition: liblwgeom.h:278
double zmax
Definition: liblwgeom.h:281
double xmin
Definition: liblwgeom.h:276
double xmin
Definition: liblwgeom.h:261
double ymax
Definition: liblwgeom.h:279
BOX3D * box3d_from_gbox(const GBOX *gbox)
Definition: g_box.c:49
double xmax
Definition: liblwgeom.h:262
double zmin
Definition: liblwgeom.h:280
double ymax
Definition: liblwgeom.h:262
double zmax
Definition: liblwgeom.h:262
double zmin
Definition: liblwgeom.h:261
Here is the call graph for this function:
Here is the caller graph for this function: