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

Definition at line 911 of file lwgeom_functions_analytic.c.

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

Referenced by pip_short_circuit().

912 {
913  uint32_t i;
914  int result, in_ring;
915  POINT2D pt;
916 
917  POSTGIS_DEBUG(2, "point_in_polygon called.");
918 
919  getPoint2d_p(point->point, 0, &pt);
920  /* assume bbox short-circuit has already been attempted */
921 
922  /* everything is outside of an empty polygon */
923  if ( polygon->nrings == 0 ) return -1;
924 
925  in_ring = point_in_ring(polygon->rings[0], &pt);
926  if ( in_ring == -1) /* outside the exterior ring */
927  {
928  POSTGIS_DEBUG(3, "point_in_polygon: outside exterior ring.");
929  return -1;
930  }
931  result = in_ring;
932 
933  for (i=1; i<polygon->nrings; i++)
934  {
935  in_ring = point_in_ring(polygon->rings[i], &pt);
936  if (in_ring == 1) /* inside a hole => outside the polygon */
937  {
938  POSTGIS_DEBUGF(3, "point_in_polygon: within hole %d.", i);
939  return -1;
940  }
941  if (in_ring == 0) /* on the edge of a hole */
942  {
943  POSTGIS_DEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
944  return 0;
945  }
946  }
947  return result; /* -1 = outside, 0 = boundary, 1 = inside */
948 }
static int point_in_ring(POINTARRAY *pts, const POINT2D *point)
POINTARRAY * point
Definition: liblwgeom.h:410
uint32_t nrings
Definition: liblwgeom.h:454
unsigned int uint32_t
Definition: uthash.h:78
POINTARRAY ** rings
Definition: liblwgeom.h:456
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:338

Here is the call graph for this function:

Here is the caller graph for this function: