PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ 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 2585 of file lwgeodetic.c.

References LW_FALSE, LW_TRUE, LWDEBUG, lwgeom_is_empty(), lwpoly_covers_pointarray(), and lwpoly_intersects_line().

Referenced by lwgeom_covers_lwgeom_sphere().

2586 {
2587  int i;
2588 
2589  /* Nulls and empties don't contain anything! */
2590  if ( ! poly1 || lwgeom_is_empty((LWGEOM*)poly1) )
2591  {
2592  LWDEBUG(4,"returning false, geometry1 is empty or null");
2593  return LW_FALSE;
2594  }
2595 
2596  /* Nulls and empties don't contain anything! */
2597  if ( ! poly2 || lwgeom_is_empty((LWGEOM*)poly2) )
2598  {
2599  LWDEBUG(4,"returning false, geometry2 is empty or null");
2600  return LW_FALSE;
2601  }
2602 
2603  /* check if all vertices of poly2 are inside poly1 */
2604  for (i = 0; i < poly2->nrings; i++)
2605  {
2606 
2607  /* every other ring is a hole, check if point is inside the actual polygon */
2608  if ( i % 2 == 0)
2609  {
2610  if (LW_FALSE == lwpoly_covers_pointarray(poly1, poly2->rings[i]))
2611  {
2612  LWDEBUG(4,"returning false, geometry2 has point outside of geometry1");
2613  return LW_FALSE;
2614  }
2615  }
2616  else
2617  {
2618  if (LW_TRUE == lwpoly_covers_pointarray(poly1, poly2->rings[i]))
2619  {
2620  LWDEBUG(4,"returning false, geometry2 has point inside a hole of geometry1");
2621  return LW_FALSE;
2622  }
2623  }
2624  }
2625 
2626  /* check for any edge intersections, so nothing is partially outside of poly1 */
2627  for (i = 0; i < poly2->nrings; i++)
2628  {
2629  if (LW_TRUE == lwpoly_intersects_line(poly1, poly2->rings[i]))
2630  {
2631  LWDEBUG(4,"returning false, geometry2 is partially outside of geometry1");
2632  return LW_FALSE;
2633  }
2634  }
2635 
2636  /* no abort condition found, so the poly2 should be completly inside poly1 */
2637  return LW_TRUE;
2638 }
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:2698
int lwpoly_covers_pointarray(const LWPOLY *lwpoly, const POINTARRAY *pta)
return LW_TRUE if all points are inside the polygon
Definition: lwgeodetic.c:2679
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
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:1346
Here is the call graph for this function:
Here is the caller graph for this function: