PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ point_in_polygon()

int point_in_polygon ( LWPOLY polygon,
LWPOINT point 
)

Definition at line 996 of file lwgeom_functions_analytic.c.

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

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

Referenced by pip_short_circuit().

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