PostGIS  2.2.7dev-r@@SVN_REVISION@@
int point_in_ring_rtree ( RTREE_NODE root,
POINT2D point 
)

Definition at line 691 of file lwgeom_functions_analytic.c.

References determineSide(), FP_CONTAINS_BOTTOM, LWMLINE::geoms, getPoint2d_p(), isOnSegment(), LWMLINE::ngeoms, LWLINE::points, RTreeFindLineSegments(), POINT2D::x, and POINT2D::y.

Referenced by point_in_multipolygon_rtree(), and point_in_polygon_rtree().

692 {
693  int wn = 0;
694  int i;
695  double side;
696  POINT2D seg1;
697  POINT2D seg2;
698  LWMLINE *lines;
699 
700  POSTGIS_DEBUG(2, "point_in_ring called.");
701 
702  lines = RTreeFindLineSegments(root, point->y);
703  if (!lines)
704  return -1;
705 
706  for (i=0; i<lines->ngeoms; i++)
707  {
708  getPoint2d_p(lines->geoms[i]->points, 0, &seg1);
709  getPoint2d_p(lines->geoms[i]->points, 1, &seg2);
710 
711 
712  side = determineSide(&seg1, &seg2, point);
713 
714  POSTGIS_DEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1.x, seg1.y, seg2.x, seg2.y);
715  POSTGIS_DEBUGF(3, "side result: %.8f", side);
716  POSTGIS_DEBUGF(3, "counterclockwise wrap %d, clockwise wrap %d", FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y), FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y));
717 
718  /* zero length segments are ignored. */
719  if (((seg2.x-seg1.x)*(seg2.x-seg1.x)+(seg2.y-seg1.y)*(seg2.y-seg1.y)) < 1e-12*1e-12)
720  {
721  POSTGIS_DEBUG(3, "segment is zero length... ignoring.");
722 
723  continue;
724  }
725 
726  /* a point on the boundary of a ring is not contained. */
727  /* WAS: if (fabs(side) < 1e-12), see #852 */
728  if (side == 0.0)
729  {
730  if (isOnSegment(&seg1, &seg2, point) == 1)
731  {
732  POSTGIS_DEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
733 
734  return 0;
735  }
736  }
737 
738  /*
739  * If the point is to the left of the line, and it's rising,
740  * then the line is to the right of the point and
741  * circling counter-clockwise, so incremement.
742  */
743  if (FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y) && side>0)
744  {
745  POSTGIS_DEBUG(3, "incrementing winding number.");
746 
747  ++wn;
748  }
749  /*
750  * If the point is to the right of the line, and it's falling,
751  * then the line is to the right of the point and circling
752  * clockwise, so decrement.
753  */
754  else if (FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y) && side<0)
755  {
756  POSTGIS_DEBUG(3, "decrementing winding number.");
757 
758  --wn;
759  }
760  }
761 
762  POSTGIS_DEBUGF(3, "winding number %d", wn);
763 
764  if (wn == 0)
765  return -1;
766  return 1;
767 }
LWMLINE * RTreeFindLineSegments(RTREE_NODE *root, double value)
Retrieves a collection of line segments given the root and crossing value.
Definition: lwgeom_rtree.c:436
int ngeoms
Definition: liblwgeom.h:465
double x
Definition: liblwgeom.h:312
int isOnSegment(POINT2D *seg1, POINT2D *seg2, POINT2D *point)
double y
Definition: liblwgeom.h:312
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:448
LWLINE ** geoms
Definition: liblwgeom.h:467
#define FP_CONTAINS_BOTTOM(A, X, B)
double determineSide(POINT2D *seg1, POINT2D *seg2, POINT2D *point)
POINTARRAY * points
Definition: liblwgeom.h:406

Here is the call graph for this function:

Here is the caller graph for this function: