PostGIS  3.3.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 2473 of file lwgeodetic.c.

2474 {
2475  uint32_t i;
2476 
2477  /* Nulls and empties don't contain anything! */
2478  if ( ! poly1 || lwgeom_is_empty((LWGEOM*)poly1) )
2479  {
2480  LWDEBUG(4,"returning false, geometry1 is empty or null");
2481  return LW_FALSE;
2482  }
2483 
2484  /* Nulls and empties don't contain anything! */
2485  if ( ! poly2 || lwgeom_is_empty((LWGEOM*)poly2) )
2486  {
2487  LWDEBUG(4,"returning false, geometry2 is empty or null");
2488  return LW_FALSE;
2489  }
2490 
2491  /* check if all vertices of poly2 are inside poly1 */
2492  for (i = 0; i < poly2->nrings; i++)
2493  {
2494  if (LW_FALSE == lwpoly_covers_pointarray(poly1, poly2->rings[i]))
2495  {
2496  LWDEBUG(4,"returning false, geometry2 has point outside of geometry1");
2497  return LW_FALSE;
2498  }
2499  }
2500 
2501  /* check for any edge intersections, so nothing is partially outside of poly1 */
2502  for (i = 0; i < poly2->nrings; i++)
2503  {
2504  if (LW_TRUE == lwpoly_intersects_line(poly1, poly2->rings[i]))
2505  {
2506  LWDEBUG(4,"returning false, geometry2 is partially outside of geometry1");
2507  return LW_FALSE;
2508  }
2509  }
2510 
2511  /* no abort condition found, so the poly2 should be completly inside poly1 */
2512  return LW_TRUE;
2513 }
#define LW_FALSE
Definition: liblwgeom.h:109
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:108
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:2573
int lwpoly_covers_pointarray(const LWPOLY *lwpoly, const POINTARRAY *pta)
return LW_TRUE if all points are inside the polygon
Definition: lwgeodetic.c:2554
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
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:203

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: