PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ BOX3D_combine()

Datum BOX3D_combine ( PG_FUNCTION_ARGS  )

Definition at line 499 of file lwgeom_box3d.c.

500{
501 BOX3D *box = (BOX3D *)PG_GETARG_POINTER(0);
502 GSERIALIZED *geom = PG_ARGISNULL(1) ? NULL : (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
503 LWGEOM *lwgeom = NULL;
504 BOX3D *result = NULL;
505 GBOX gbox;
506 int32_t srid;
507 int rv;
508
509 /* Can't do anything with null inputs */
510 if (!box && !geom)
511 {
512 PG_RETURN_NULL();
513 }
514 /* Null geometry but non-null box, return the box */
515 else if (!geom)
516 {
517 result = palloc(sizeof(BOX3D));
518 memcpy(result, box, sizeof(BOX3D));
519 PG_RETURN_POINTER(result);
520 }
521
522 /*
523 * Deserialize geometry and *calculate* the box
524 * We can't use the cached box because it's float, we *must* calculate
525 */
526 lwgeom = lwgeom_from_gserialized(geom);
527 srid = lwgeom->srid;
528 rv = lwgeom_calculate_gbox(lwgeom, &gbox);
529 lwgeom_free(lwgeom);
530
531 /* If we couldn't calculate the box, return what we know */
532 if (rv == LW_FAILURE)
533 {
534 PG_FREE_IF_COPY(geom, 1);
535 /* No geom box, no input box, so null return */
536 if (!box)
537 PG_RETURN_NULL();
538 result = palloc(sizeof(BOX3D));
539 memcpy(result, box, sizeof(BOX3D));
540 PG_RETURN_POINTER(result);
541 }
542
543 /* Null box and non-null geometry, just return the geometry box */
544 if (!box)
545 {
546 PG_FREE_IF_COPY(geom, 1);
547 result = box3d_from_gbox(&gbox);
548 result->srid = srid;
549 PG_RETURN_POINTER(result);
550 }
551
552 result = palloc(sizeof(BOX3D));
553 result->xmax = Max(box->xmax, gbox.xmax);
554 result->ymax = Max(box->ymax, gbox.ymax);
555 result->zmax = Max(box->zmax, gbox.zmax);
556 result->xmin = Min(box->xmin, gbox.xmin);
557 result->ymin = Min(box->ymin, gbox.ymin);
558 result->zmin = Min(box->zmin, gbox.zmin);
559 result->srid = srid;
560
561 PG_FREE_IF_COPY(geom, 1);
562 PG_RETURN_POINTER(result);
563}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
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.
#define LW_FAILURE
Definition liblwgeom.h:96
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
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:783
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: