public static bool ContainsPointInPolygon(Coordinate p, Polygon polygon) { if (polygon == null) { throw new ArgumentNullException("polygon"); } if (polygon.IsEmpty) { return(false); } LinearRing shell = (LinearRing)polygon.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 < polygon.NumInteriorRings; i++) { LinearRing hole = (LinearRing)polygon.InteriorRing(i); if (CGAlgorithms.IsPointInRing(p, hole.Coordinates)) { return(false); } } return(true); }
private int Locate(Coordinate p, LinearRing ring) { // can this test be folded into IsPointInRing ? if (CGAlgorithms.IsOnLine(p, ring.Coordinates)) { return(LocationType.Boundary); } if (CGAlgorithms.IsPointInRing(p, ring.Coordinates)) { return(LocationType.Interior); } return(LocationType.Exterior); }
/** * 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. * <p> * 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. * * @param pts * @return */ private ICoordinateList Reduce(ICoordinateList inputPts) { ICoordinateList polyPts = ComputeOctRing(inputPts); // unable to compute interior polygon for some reason if (polyPts == null) { return(inputPts); } // add points defining polygon ICoordinateList reducedSet = new CoordinateCollection(); int nCount = polyPts.Count; for (int i = 0; i < nCount; i++) { if (!reducedSet.Contains(polyPts[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. nCount = inputPts.Count; for (int i = 0; i < nCount; i++) { if (!CGAlgorithms.IsPointInRing(inputPts[i], polyPts)) { reducedSet.Add(inputPts[i]); } } return(reducedSet); }
public bool IsInside(Coordinate pt) { return(CGAlgorithms.IsPointInRing(pt, pts)); }