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

Definition at line 1184 of file lwgeom_functions_analytic.c.

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

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

1185 {
1186  int i, result, in_ring;
1187  POINT2D pt;
1188 
1189  POSTGIS_DEBUG(2, "point_in_polygon called.");
1190 
1191  getPoint2d_p(point->point, 0, &pt);
1192  /* assume bbox short-circuit has already been attempted */
1193 
1194  /* everything is outside of an empty polygon */
1195  if ( polygon->nrings == 0 ) return -1;
1196 
1197  in_ring = point_in_ring(polygon->rings[0], &pt);
1198  if ( in_ring == -1) /* outside the exterior ring */
1199  {
1200  POSTGIS_DEBUG(3, "point_in_polygon: outside exterior ring.");
1201  return -1;
1202  }
1203  result = in_ring;
1204 
1205  for (i=1; i<polygon->nrings; i++)
1206  {
1207  in_ring = point_in_ring(polygon->rings[i], &pt);
1208  if (in_ring == 1) /* inside a hole => outside the polygon */
1209  {
1210  POSTGIS_DEBUGF(3, "point_in_polygon: within hole %d.", i);
1211  return -1;
1212  }
1213  if (in_ring == 0) /* on the edge of a hole */
1214  {
1215  POSTGIS_DEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
1216  return 0;
1217  }
1218  }
1219  return result; /* -1 = outside, 0 = boundary, 1 = inside */
1220 }
POINTARRAY * point
Definition: liblwgeom.h:367
char ** result
Definition: liblwgeom.h:218
POINTARRAY ** rings
Definition: liblwgeom.h:413
int nrings
Definition: liblwgeom.h:411
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:434
int point_in_ring(POINTARRAY *pts, POINT2D *point)

Here is the call graph for this function:

Here is the caller graph for this function: