public static Geometry MCIndexNoding(Geometry geom) { INoder noder = new MCIndexNoder(new IntersectionAdder(new RobustLineIntersector())); noder.ComputeNodes(SegmentStringUtil.ExtractNodedSegmentStrings(geom)); return(SegmentStringUtil.ToGeometry(noder.GetNodedSubstrings(), geom.Factory)); }
public static int InteriorIntersectionCount(Geometry geom) { var intCounter = NodingIntersectionFinder.CreateIntersectionCounter(new RobustLineIntersector()); INoder noder = new MCIndexNoder(intCounter); noder.ComputeNodes(SegmentStringUtil.ExtractNodedSegmentStrings(geom)); return(intCounter.Count); }
///<summary> /// Tests whether this PreparedPolygon intersects a given geometry. ///</summary> /// <param name="geom">The test geometry</param> /// <returns>true if the test geometry intersects</returns> public bool Intersects(IGeometry geom) { /* * Do point-in-poly tests first, since they are cheaper and may result * in a quick positive result. * * If a point of any test components lie in target, result is true */ bool isInPrepGeomArea = IsAnyTestComponentInTarget(geom); if (isInPrepGeomArea) { return(true); } /** * If input contains only points, then at * this point it is known that none of them are contained in the target */ if (geom.Dimension == Dimension.Point) { return(false); } /* * If any segments intersect, result is true */ var lineSegStr = SegmentStringUtil.ExtractSegmentStrings(geom); // only request intersection finder if there are segments (ie NOT for point inputs) if (lineSegStr.Count > 0) { bool segsIntersect = prepPoly.IntersectionFinder.Intersects(lineSegStr); if (segsIntersect) { return(true); } } /* * If the test has dimension = 2 as well, it is necessary to * test for proper inclusion of the target. * Since no segments intersect, it is sufficient to test representative points. */ if (geom.Dimension == Dimension.Surface) { // TODO: generalize this to handle GeometryCollections bool isPrepGeomInArea = IsAnyTargetComponentInAreaTest(geom, prepPoly.RepresentativePoints); if (isPrepGeomInArea) { return(true); } } return(false); }
private static List <ISegmentString> ToSegmentStrings(IEnumerable <IGeometry> geoms) { var segStrings = new List <ISegmentString>(); foreach (var geom in geoms) { segStrings.AddRange(SegmentStringUtil.ExtractSegmentStrings(geom)); } return(segStrings); }
public static Geometry FindOneNode(Geometry geom) { var nv = new FastNodingValidator(SegmentStringUtil.ExtractNodedSegmentStrings(geom)); bool temp = nv.IsValid; var intPts = nv.Intersections; if (intPts.Count == 0) { return(null); } return(FunctionsUtil.GetFactoryOrDefault((Geometry)null).CreatePoint((Coordinate)intPts[0])); }
/// <summary> /// Runs a ScaledNoder on input. /// Input vertices should be rounded to precision model. /// </summary> /// <param name="geom"></param> /// <param name="scaleFactor"></param> /// <returns>The noded geometry</returns> public static Geometry ScaledNoding(Geometry geom, double scaleFactor) { var segs = CreateSegmentStrings(geom); var fixedPM = new PrecisionModel(scaleFactor); var noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)), fixedPM.Scale); noder.ComputeNodes(segs); var nodedSegStrings = noder.GetNodedSubstrings(); return(SegmentStringUtil.ToGeometry(nodedSegStrings, geom.Factory)); }
private void FindAndClassifyIntersections(IGeometry geom) { IList <ISegmentString> lineSegStr = SegmentStringUtil.ExtractSegmentStrings(geom); var intDetector = new SegmentIntersectionDetector(); intDetector.FindAllIntersectionTypes = true; prepPoly.IntersectionFinder.Intersects(lineSegStr, intDetector); _hasSegmentIntersection = intDetector.HasIntersection; _hasProperIntersection = intDetector.HasProperIntersection; _hasNonProperIntersection = intDetector.HasNonProperIntersection; }
public static Geometry MCIndexNodingWithPrecision(Geometry geom, double scaleFactor) { var fixedPM = new PrecisionModel(scaleFactor); LineIntersector li = new RobustLineIntersector(); li.PrecisionModel = fixedPM; INoder noder = new MCIndexNoder(new IntersectionAdder(li)); noder.ComputeNodes(SegmentStringUtil.ExtractNodedSegmentStrings(geom)); return(SegmentStringUtil.ToGeometry(noder.GetNodedSubstrings(), geom.Factory)); }
///<summary> /// Tests whether this geometry intersects a given geometry. ///</summary> /// <param name="geom">The test geometry</param> /// <returns>true if the test geometry intersects</returns> public bool Intersects(IGeometry geom) { /* * If any segments intersect, obviously intersects = true */ var lineSegStr = SegmentStringUtil.ExtractSegmentStrings(geom); // only request intersection finder if there are segments (ie NOT for point inputs) if (lineSegStr.Count > 0) { var segsIntersect = prepLine.IntersectionFinder.Intersects(lineSegStr); // MD - performance testing // boolean segsIntersect = false; if (segsIntersect) { return(true); } } /* * For L/L case we are done */ if (geom.Dimension == Dimension.Curve) { return(false); } /* * For L/A case, need to check for proper inclusion of the target in the test */ if (geom.Dimension == Dimension.Surface && prepLine.IsAnyTargetComponentInTest(geom)) { return(true); } /* * For L/P case, need to check if any points lie on line(s) */ if (geom.Dimension == Dimension.Point) { return(IsAnyTestPointInTarget(geom)); } // return prepLine.getGeometry().intersects(geom); return(false); }
///<summary> /// Tests whether this PreparedPolygon containsProperly a given geometry. ///</summary> ///<param name="geom">The test geometry</param> /// <returns>true if the polygon properly contains the geometry</returns> public bool ContainsProperly(IGeometry geom) { /* * Do point-in-poly tests first, since they are cheaper and may result * in a quick negative result. * * If a point of any test components does not lie in the target interior, result is false */ bool isAllInPrepGeomAreaInterior = IsAllTestComponentsInTargetInterior(geom); if (!isAllInPrepGeomAreaInterior) { return(false); } /* * If any segments intersect, result is false. */ var lineSegStr = SegmentStringUtil.ExtractSegmentStrings(geom); bool segsIntersect = prepPoly.IntersectionFinder.Intersects(lineSegStr); if (segsIntersect) { return(false); } /* * Given that no segments intersect, if any vertex of the target * is contained in some test component. * the test is NOT properly contained. */ if (geom is IPolygonal) { // TODO: generalize this to handle GeometryCollections bool isTargetGeomInTestArea = IsAnyTargetComponentInAreaTest(geom, prepPoly.RepresentativePoints); if (isTargetGeomInTestArea) { return(false); } } return(true); }
private static void ProcessNodes(Geometry geom, NodingIntersectionFinder intFinder) { var noder = new MCIndexNoder(intFinder); noder.ComputeNodes(SegmentStringUtil.ExtractNodedSegmentStrings(geom)); }
public static Geometry FindNodes(Geometry geom) { var intPts = FastNodingValidator.ComputeIntersections(SegmentStringUtil.ExtractNodedSegmentStrings(geom)); return(FunctionsUtil.GetFactoryOrDefault((Geometry)null).CreateMultiPointFromCoords(CoordinateArrays.ToCoordinateArray(intPts))); }
public static bool IsNodingValid(Geometry geom) { var nv = new FastNodingValidator(SegmentStringUtil.ExtractNodedSegmentStrings(geom)); return(nv.IsValid); }
public static IGeometry FindNodePoints(IGeometry geom) { IList <Coordinate> intPts = FastNodingValidator.ComputeIntersections(SegmentStringUtil.ExtractNodedSegmentStrings(geom)); return(FunctionsUtil.GetFactoryOrDefault(null).CreateMultiPoint(CoordinateArrays.ToCoordinateArray(intPts))); }