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

◆ lwpoly_covers_lwpoly()

int lwpoly_covers_lwpoly ( const LWPOLY poly1,
const LWPOLY poly2 
)

Given a polygon1 check if all points of polygon2 are inside polygon1 and no intersections of the polygon edges occur.

return LW_TRUE if polygon is inside or on edge of polygon.

Definition at line 2481 of file lwgeodetic.c.

2482{
2483 uint32_t i;
2484
2485 /* Nulls and empties don't contain anything! */
2486 if ( ! poly1 || lwgeom_is_empty((LWGEOM*)poly1) )
2487 {
2488 LWDEBUG(4,"returning false, geometry1 is empty or null");
2489 return LW_FALSE;
2490 }
2491
2492 /* Nulls and empties don't contain anything! */
2493 if ( ! poly2 || lwgeom_is_empty((LWGEOM*)poly2) )
2494 {
2495 LWDEBUG(4,"returning false, geometry2 is empty or null");
2496 return LW_FALSE;
2497 }
2498
2499 /* check if all vertices of poly2 are inside poly1 */
2500 for (i = 0; i < poly2->nrings; i++)
2501 {
2502 if (LW_FALSE == lwpoly_covers_pointarray(poly1, poly2->rings[i]))
2503 {
2504 LWDEBUG(4,"returning false, geometry2 has point outside of geometry1");
2505 return LW_FALSE;
2506 }
2507 }
2508
2509 /* check for any edge intersections, so nothing is partially outside of poly1 */
2510 for (i = 0; i < poly2->nrings; i++)
2511 {
2512 if (LW_TRUE == lwpoly_intersects_line(poly1, poly2->rings[i]))
2513 {
2514 LWDEBUG(4,"returning false, geometry2 is partially outside of geometry1");
2515 return LW_FALSE;
2516 }
2517 }
2518
2519 /* no abort condition found, so the poly2 should be completely inside poly1 */
2520 return LW_TRUE;
2521}
#define LW_FALSE
Definition liblwgeom.h:94
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
int lwpoly_intersects_line(const LWPOLY *lwpoly, const POINTARRAY *line)
Checks if any edges of lwpoly intersect with the line formed by the pointarray return LW_TRUE if any ...
int lwpoly_covers_pointarray(const LWPOLY *lwpoly, const POINTARRAY *pta)
return LW_TRUE if all points are inside the polygon
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:101
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199

References LW_FALSE, LW_TRUE, LWDEBUG, lwgeom_is_empty(), lwpoly_covers_pointarray(), lwpoly_intersects_line(), LWPOLY::nrings, and LWPOLY::rings.

Referenced by lwgeom_covers_lwgeom_sphere().

Here is the call graph for this function:
Here is the caller graph for this function: