PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ point_in_multipolygon()

int point_in_multipolygon ( LWMPOLY mpolygon,
LWPOINT point 
)

Definition at line 997 of file lwgeom_functions_analytic.c.

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

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

998 {
999  int i, j, 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  result = -1;
1008 
1009  for (j = 0; j < mpolygon->ngeoms; j++ )
1010  {
1011 
1012  LWPOLY *polygon = mpolygon->geoms[j];
1013 
1014  /* everything is outside of an empty polygon */
1015  if ( polygon->nrings == 0 ) continue;
1016 
1017  in_ring = point_in_ring(polygon->rings[0], &pt);
1018  if ( in_ring == -1) /* outside the exterior ring */
1019  {
1020  POSTGIS_DEBUG(3, "point_in_polygon: outside exterior ring.");
1021  continue;
1022  }
1023  if ( in_ring == 0 )
1024  {
1025  return 0;
1026  }
1027 
1028  result = in_ring;
1029 
1030  for (i=1; i<polygon->nrings; i++)
1031  {
1032  in_ring = point_in_ring(polygon->rings[i], &pt);
1033  if (in_ring == 1) /* inside a hole => outside the polygon */
1034  {
1035  POSTGIS_DEBUGF(3, "point_in_polygon: within hole %d.", i);
1036  result = -1;
1037  break;
1038  }
1039  if (in_ring == 0) /* on the edge of a hole */
1040  {
1041  POSTGIS_DEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
1042  return 0;
1043  }
1044  }
1045  if ( result != -1)
1046  {
1047  return result;
1048  }
1049  }
1050  return result;
1051 }
POINTARRAY * point
Definition: liblwgeom.h:395
LWPOLY ** geoms
Definition: liblwgeom.h:480
POINTARRAY ** rings
Definition: liblwgeom.h:441
int nrings
Definition: liblwgeom.h:439
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:448
int ngeoms
Definition: liblwgeom.h:478
int point_in_ring(POINTARRAY *pts, POINT2D *point)
Here is the call graph for this function:
Here is the caller graph for this function: