/// <summary> /// Calculates the intersection of a polygon shape without relying on the NTS geometry /// </summary> /// <param name="lineShape"></param> /// <param name="otherShape"></param> /// <returns></returns> public static bool Intersects(ShapeRange lineShape, ShapeRange otherShape) { if (lineShape.FeatureType != FeatureTypes.Line) { throw new ArgumentException("The First parameter should be a point shape, but it was featuretype:" + lineShape.FeatureType); } // Implmented in PolygonShape if(otherShape.FeatureType == FeatureTypes.Polygon) { return otherShape.Intersects(lineShape); } // Test for point on a line if(otherShape.FeatureType == FeatureTypes.Point || otherShape.FeatureType == FeatureTypes.MultiPoint) { return IntersectsVertex(lineShape, otherShape); } // There is no other way for this polygon to intersect the other points if (otherShape.FeatureType == FeatureTypes.Point || otherShape.FeatureType == FeatureTypes.MultiPoint) return false; // For lines and polygons, if any segment intersects any segment of this polygon shape, return true. // This is essentially looking for the rare case of crossing in and crossing out again with // no actual points inside this polygonShape. return SegmentsIntersect(lineShape, otherShape); }
/// <summary> /// Calculates the intersection of a polygon shape without relying on the NTS geometry /// </summary> /// <param name="pointShape"></param> /// <param name="otherShape"></param> /// <returns></returns> public static bool Intersects(ShapeRange pointShape, ShapeRange otherShape) { if(pointShape.FeatureType != FeatureTypes.Point && pointShape.FeatureType != FeatureTypes.MultiPoint) { throw new ArgumentException("The First parameter should be a point shape, but it was featuretype:" + pointShape.FeatureType); } // Implmented in PolygonShape or line shape. Point shape is the simplest and just looks for overlapping coordinates. if (otherShape.FeatureType == FeatureTypes.Polygon || otherShape.FeatureType == FeatureTypes.Line) { return otherShape.Intersects(pointShape); } // For two point-type shapes, test if any vertex from one overlaps with any vertex of the other within Epsilon tollerance return VerticesIntersect(pointShape, otherShape); }