int point_in_polygon ( LWPOLY polygon,
LWPOINT point 
)

Definition at line 1167 of file lwgeom_functions_analytic.c.

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

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

01168 {
01169         int i, result, in_ring;
01170         POINTARRAY *ring;
01171         POINT2D pt;
01172 
01173         POSTGIS_DEBUG(2, "point_in_polygon called.");
01174 
01175         getPoint2d_p(point->point, 0, &pt);
01176         /* assume bbox short-circuit has already been attempted */
01177 
01178         /* everything is outside of an empty polygon */
01179         if ( polygon->nrings == 0 ) return -1;
01180 
01181         ring = polygon->rings[0];
01182         in_ring = point_in_ring(polygon->rings[0], &pt);
01183         if ( in_ring == -1) /* outside the exterior ring */
01184         {
01185                 POSTGIS_DEBUG(3, "point_in_polygon: outside exterior ring.");
01186                 return -1;
01187         }
01188         result = in_ring;
01189 
01190         for (i=1; i<polygon->nrings; i++)
01191         {
01192                 ring = polygon->rings[i];
01193                 in_ring = point_in_ring(polygon->rings[i], &pt);
01194                 if (in_ring == 1) /* inside a hole => outside the polygon */
01195                 {
01196                         POSTGIS_DEBUGF(3, "point_in_polygon: within hole %d.", i);
01197                         return -1;
01198                 }
01199                 if (in_ring == 0) /* on the edge of a hole */
01200                 {
01201                         POSTGIS_DEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
01202                         return 0;
01203                 }
01204         }
01205         return result; /* -1 = outside, 0 = boundary, 1 = inside */
01206 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Wed Aug 22 01:29:43 2012 for PostGIS Trunk Doxygen by  doxygen 1.4.7