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

◆ ST_ClipByBox2d()

Datum ST_ClipByBox2d ( PG_FUNCTION_ARGS  )

Definition at line 1527 of file postgis/lwgeom_geos.c.

1528{
1529 static const uint32_t geom_idx = 0;
1530 static const uint32_t box2d_idx = 1;
1532 LWGEOM *lwgeom1, *lwresult ;
1533 GBOX bbox1 = {0};
1534 GBOX *bbox2;
1535 uint8_t type;
1536 int32_t srid;
1537 lwflags_t flags;
1538
1539 if (!gserialized_datum_get_internals_p(PG_GETARG_DATUM(geom_idx), &bbox1, &flags, &type, &srid))
1540 {
1541 /* empty clips to empty, no matter rect */
1542 PG_RETURN_DATUM(PG_GETARG_DATUM(geom_idx));
1543 }
1544
1545 /* WARNING: this is really a BOX2DF, use only xmin and ymin fields */
1546 bbox2 = (GBOX *)PG_GETARG_POINTER(box2d_idx);
1547 bbox2->flags = 0;
1548
1549 /* If bbox1 is strictly contained by bbox2, return input geometry */
1550 if (bbox2->xmin < bbox1.xmin && bbox2->xmax > bbox1.xmax &&
1551 bbox2->ymin < bbox1.ymin && bbox2->ymax > bbox1.ymax)
1552 {
1553 PG_RETURN_DATUM(PG_GETARG_DATUM(geom_idx));
1554 }
1555
1556 /* If bbox1 outside of bbox2, return empty */
1557 if (!gbox_overlaps_2d(&bbox1, bbox2))
1558 {
1559 /* Get type and srid from datum */
1560 lwresult = lwgeom_construct_empty(type, srid, 0, 0);
1561 result = geometry_serialize(lwresult) ;
1562 lwgeom_free(lwresult) ;
1563 PG_RETURN_POINTER(result);
1564 }
1565
1566 lwgeom1 = lwgeom_from_gserialized(PG_GETARG_GSERIALIZED_P(geom_idx));
1567 lwresult = lwgeom_clip_by_rect(lwgeom1, bbox2->xmin, bbox2->ymin,
1568 bbox2->xmax, bbox2->ymax);
1569
1570 lwgeom_free(lwgeom1);
1571
1572 if (!lwresult)
1573 PG_RETURN_NULL();
1574
1575 result = geometry_serialize(lwresult) ;
1576 PG_RETURN_POINTER(result);
1577}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
Definition gbox.c:323
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_datum_get_internals_p(Datum gsdatum, GBOX *gbox, lwflags_t *flags, uint8_t *type, int32_t *srid)
Peak into a GSERIALIZED datum to find its bounding box and some other metadata.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
uint16_t lwflags_t
Definition liblwgeom.h:299
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition lwgeom.c:2219
double ymax
Definition liblwgeom.h:357
double xmax
Definition liblwgeom.h:355
double ymin
Definition liblwgeom.h:356
double xmin
Definition liblwgeom.h:354
lwflags_t flags
Definition liblwgeom.h:353

References GBOX::flags, gbox_overlaps_2d(), gserialized_datum_get_internals_p(), lwgeom_clip_by_rect(), lwgeom_construct_empty(), lwgeom_free(), lwgeom_from_gserialized(), result, GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Here is the call graph for this function: