PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ point_in_polygon()

int point_in_polygon ( LWPOLY polygon,
LWPOINT point 
)

Definition at line 956 of file lwgeom_functions_analytic.c.

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

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: