PostGIS  2.5.0dev-r@@SVN_REVISION@@
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 2502 of file lwgeodetic.c.

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().

2503 {
2504  uint32_t i;
2505 
2506  /* Nulls and empties don't contain anything! */
2507  if ( ! poly1 || lwgeom_is_empty((LWGEOM*)poly1) )
2508  {
2509  LWDEBUG(4,"returning false, geometry1 is empty or null");
2510  return LW_FALSE;
2511  }
2512 
2513  /* Nulls and empties don't contain anything! */
2514  if ( ! poly2 || lwgeom_is_empty((LWGEOM*)poly2) )
2515  {
2516  LWDEBUG(4,"returning false, geometry2 is empty or null");
2517  return LW_FALSE;
2518  }
2519 
2520  /* check if all vertices of poly2 are inside poly1 */
2521  for (i = 0; i < poly2->nrings; i++)
2522  {
2523 
2524  /* every other ring is a hole, check if point is inside the actual polygon */
2525  if ( i % 2 == 0)
2526  {
2527  if (LW_FALSE == lwpoly_covers_pointarray(poly1, poly2->rings[i]))
2528  {
2529  LWDEBUG(4,"returning false, geometry2 has point outside of geometry1");
2530  return LW_FALSE;
2531  }
2532  }
2533  else
2534  {
2535  if (LW_TRUE == lwpoly_covers_pointarray(poly1, poly2->rings[i]))
2536  {
2537  LWDEBUG(4,"returning false, geometry2 has point inside a hole of geometry1");
2538  return LW_FALSE;
2539  }
2540  }
2541  }
2542 
2543  /* check for any edge intersections, so nothing is partially outside of poly1 */
2544  for (i = 0; i < poly2->nrings; i++)
2545  {
2546  if (LW_TRUE == lwpoly_intersects_line(poly1, poly2->rings[i]))
2547  {
2548  LWDEBUG(4,"returning false, geometry2 is partially outside of geometry1");
2549  return LW_FALSE;
2550  }
2551  }
2552 
2553  /* no abort condition found, so the poly2 should be completly inside poly1 */
2554  return LW_TRUE;
2555 }
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 ...
Definition: lwgeodetic.c:2615
int lwpoly_covers_pointarray(const LWPOLY *lwpoly, const POINTARRAY *pta)
return LW_TRUE if all points are inside the polygon
Definition: lwgeodetic.c:2596
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
uint32_t nrings
Definition: liblwgeom.h:454
unsigned int uint32_t
Definition: uthash.h:78
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
POINTARRAY ** rings
Definition: liblwgeom.h:456
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1386

Here is the call graph for this function:

Here is the caller graph for this function: