/// <summary> /// /// </summary> /// <param name="p"></param> /// <param name="ring"></param> /// <returns></returns> private Locations LocateInPolygonRing(ICoordinate p, ILinearRing ring) { // can this test be folded into IsPointInRing? if (CGAlgorithms.IsOnLine(p, ring.Coordinates)) { return(Locations.Boundary); } if (CGAlgorithms.IsPointInRing(p, ring.Coordinates)) { return(Locations.Interior); } return(Locations.Exterior); }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <param name="poly"></param> /// <returns></returns> public static bool ContainsPointInPolygon(ICoordinate p, IPolygon poly) { if (poly.IsEmpty) { return(false); } ILinearRing shell = (ILinearRing)poly.ExteriorRing; if (!CGAlgorithms.IsPointInRing(p, shell.Coordinates)) { return(false); } // now test if the point lies in or on the holes for (int i = 0; i < poly.NumInteriorRings; i++) { ILinearRing hole = (ILinearRing)poly.GetInteriorRingN(i); if (CGAlgorithms.IsPointInRing(p, hole.Coordinates)) { return(false); } } return(true); }
/// <summary> /// Uses a heuristic to reduce the number of points scanned to compute the hull. /// The heuristic is to find a polygon guaranteed to /// be in (or on) the hull, and eliminate all points inside it. /// A quadrilateral defined by the extremal points /// in the four orthogonal directions /// can be used, but even more inclusive is /// to use an octilateral defined by the points in the 8 cardinal directions. /// Note that even if the method used to determine the polygon vertices /// is not 100% robust, this does not affect the robustness of the convex hull. /// </summary> /// <param name="pts"></param> /// <returns></returns> private ICoordinate[] Reduce(ICoordinate[] pts) { ICoordinate[] polyPts = ComputeOctRing(inputPts); // unable to compute interior polygon for some reason if (polyPts == null) { return(inputPts); } // add points defining polygon SortedSet <ICoordinate> reducedSet = new SortedSet <ICoordinate>(); for (int i = 0; i < polyPts.Length; i++) { reducedSet.Add(polyPts[i]); } /* * Add all unique points not in the interior poly. * CGAlgorithms.IsPointInRing is not defined for points actually on the ring, * but this doesn't matter since the points of the interior polygon * are forced to be in the reduced set. */ for (int i = 0; i < inputPts.Length; i++) { if (!CGAlgorithms.IsPointInRing(inputPts[i], polyPts)) { reducedSet.Add(inputPts[i]); } } ICoordinate[] arr = new ICoordinate[reducedSet.Count]; reducedSet.CopyTo(arr, 0); return(arr); }
/// <summary> /// /// </summary> /// <param name="pt"></param> /// <returns></returns> public bool IsInside(ICoordinate pt) { return(CGAlgorithms.IsPointInRing(pt, pts)); }