PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ point_in_polygon()

int point_in_polygon ( LWPOLY polygon,
LWPOINT point 
)

Definition at line 1002 of file lwgeom_functions_analytic.c.

1003 {
1004  uint32_t i;
1005  int result, in_ring;
1006  POINT2D pt;
1007 
1008  POSTGIS_DEBUG(2, "point_in_polygon called.");
1009 
1010  getPoint2d_p(point->point, 0, &pt);
1011  /* assume bbox short-circuit has already been attempted */
1012 
1013  /* everything is outside of an empty polygon */
1014  if ( polygon->nrings == 0 ) return -1;
1015 
1016  in_ring = point_in_ring(polygon->rings[0], &pt);
1017  if ( in_ring == -1) /* outside the exterior ring */
1018  {
1019  POSTGIS_DEBUG(3, "point_in_polygon: outside exterior ring.");
1020  return -1;
1021  }
1022  result = in_ring;
1023 
1024  for (i=1; i<polygon->nrings; i++)
1025  {
1026  in_ring = point_in_ring(polygon->rings[i], &pt);
1027  if (in_ring == 1) /* inside a hole => outside the polygon */
1028  {
1029  POSTGIS_DEBUGF(3, "point_in_polygon: within hole %d.", i);
1030  return -1;
1031  }
1032  if (in_ring == 0) /* on the edge of a hole */
1033  {
1034  POSTGIS_DEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
1035  return 0;
1036  }
1037  }
1038  return result; /* -1 = outside, 0 = boundary, 1 = inside */
1039 }
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:349
static int point_in_ring(POINTARRAY *pts, const POINT2D *point)
POINTARRAY * point
Definition: liblwgeom.h:457
POINTARRAY ** rings
Definition: liblwgeom.h:505
uint32_t nrings
Definition: liblwgeom.h:510

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

Referenced by pip_short_circuit().

Here is the call graph for this function:
Here is the caller graph for this function: