PostGIS  2.2.7dev-r@@SVN_REVISION@@
int point_in_polygon ( LWPOLY polygon,
LWPOINT point 
)

Definition at line 954 of file lwgeom_functions_analytic.c.

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

Referenced by contains(), coveredby(), covers(), and geos_intersects().

955 {
956  int i, result, in_ring;
957  POINT2D pt;
958 
959  POSTGIS_DEBUG(2, "point_in_polygon called.");
960 
961  getPoint2d_p(point->point, 0, &pt);
962  /* assume bbox short-circuit has already been attempted */
963 
964  /* everything is outside of an empty polygon */
965  if ( polygon->nrings == 0 ) return -1;
966 
967  in_ring = point_in_ring(polygon->rings[0], &pt);
968  if ( in_ring == -1) /* outside the exterior ring */
969  {
970  POSTGIS_DEBUG(3, "point_in_polygon: outside exterior ring.");
971  return -1;
972  }
973  result = in_ring;
974 
975  for (i=1; i<polygon->nrings; i++)
976  {
977  in_ring = point_in_ring(polygon->rings[i], &pt);
978  if (in_ring == 1) /* inside a hole => outside the polygon */
979  {
980  POSTGIS_DEBUGF(3, "point_in_polygon: within hole %d.", i);
981  return -1;
982  }
983  if (in_ring == 0) /* on the edge of a hole */
984  {
985  POSTGIS_DEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
986  return 0;
987  }
988  }
989  return result; /* -1 = outside, 0 = boundary, 1 = inside */
990 }
POINTARRAY * point
Definition: liblwgeom.h:395
POINTARRAY ** rings
Definition: liblwgeom.h:441
int nrings
Definition: liblwgeom.h:439
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:448
int point_in_ring(POINTARRAY *pts, POINT2D *point)

Here is the call graph for this function:

Here is the caller graph for this function: