PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ point_in_polygon()

int point_in_polygon ( LWPOLY polygon,
LWPOINT point 
)

Definition at line 983 of file lwgeom_functions_analytic.c.

References getPoint2d_p(), LWPOLY::nrings, LWPOINT::point, point_in_ring(), and LWPOLY::rings.

Referenced by pip_short_circuit().

984 {
985  int i, result, in_ring;
986  POINT2D pt;
987 
988  POSTGIS_DEBUG(2, "point_in_polygon called.");
989 
990  getPoint2d_p(point->point, 0, &pt);
991  /* assume bbox short-circuit has already been attempted */
992 
993  /* everything is outside of an empty polygon */
994  if ( polygon->nrings == 0 ) return -1;
995 
996  in_ring = point_in_ring(polygon->rings[0], &pt);
997  if ( in_ring == -1) /* outside the exterior ring */
998  {
999  POSTGIS_DEBUG(3, "point_in_polygon: outside exterior ring.");
1000  return -1;
1001  }
1002  result = in_ring;
1003 
1004  for (i=1; i<polygon->nrings; i++)
1005  {
1006  in_ring = point_in_ring(polygon->rings[i], &pt);
1007  if (in_ring == 1) /* inside a hole => outside the polygon */
1008  {
1009  POSTGIS_DEBUGF(3, "point_in_polygon: within hole %d.", i);
1010  return -1;
1011  }
1012  if (in_ring == 0) /* on the edge of a hole */
1013  {
1014  POSTGIS_DEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
1015  return 0;
1016  }
1017  }
1018  return result; /* -1 = outside, 0 = boundary, 1 = inside */
1019 }
static int point_in_ring(POINTARRAY *pts, const POINT2D *point)
POINTARRAY * point
Definition: liblwgeom.h:411
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:347
Here is the call graph for this function:
Here is the caller graph for this function: