private void HandleSelfClosingCase(GpxProlongerExecutorInput input, LineAndCoordinate current, LineAndCoordinate next, List <ILineString> linesToProlong) { var lengthIndexedLine = new LengthIndexedLine(current.Line); var closestCoordinateCurrentIndex = lengthIndexedLine.Project(current.Coordinate); var closestCoordinateNextIndex = lengthIndexedLine.Project(next.Coordinate); var segment = lengthIndexedLine.ExtractLine(closestCoordinateCurrentIndex, closestCoordinateNextIndex); var coordinates = segment.Coordinates.Concat(new[] { segment.Coordinates.First() }).ToArray(); if (coordinates.Length < 4) { return; } var polygon = new Polygon(new LinearRing(coordinates)); if (polygon.Area < input.MinimalAreaSize) { return; } var currentCoordinate = lengthIndexedLine.ExtractPoint(closestCoordinateCurrentIndex); var nextCoordinate = lengthIndexedLine.ExtractPoint(closestCoordinateNextIndex); if (!AddCoordinate(current.Line, currentCoordinate, nextCoordinate, linesToProlong, input.MinimalDistance)) { linesToProlong.Add(_geometryFactory.CreateLineString(new[] { currentCoordinate, nextCoordinate })); } }
private void HandleTwoLinesCase(GpxProlongerExecutorInput input, LineAndCoordinate current, LineAndCoordinate next, List <ILineString> linesToProlong) { var currentLengthIndexedLine = new LengthIndexedLine(current.Line); var currentCoordinate = currentLengthIndexedLine.ExtractPoint(currentLengthIndexedLine.Project(current.Coordinate)); var nextLengthIndexedLine = new LengthIndexedLine(next.Line); var nextCoordinate = nextLengthIndexedLine.ExtractPoint(nextLengthIndexedLine.Project(next.Coordinate)); var bothLinesAreInList = linesToProlong.Contains(current.Line) && linesToProlong.Contains(next.Line); if (bothLinesAreInList && current.Line.Coordinates.Last().Distance(current.Coordinate) < input.MinimalDistance && next.Line.Coordinates.First().Distance(next.Coordinate) < input.MinimalDistance) { linesToProlong.Remove(current.Line); linesToProlong.Remove(next.Line); linesToProlong.Add(_geometryFactory.CreateLineString(current.Line.Coordinates .Concat(next.Line.Coordinates).ToArray())); } else if (bothLinesAreInList && current.Line.Coordinates.First().Distance(current.Coordinate) < input.MinimalDistance && next.Line.Coordinates.Last().Distance(next.Coordinate) < input.MinimalDistance) { linesToProlong.Remove(current.Line); linesToProlong.Remove(next.Line); linesToProlong.Add(_geometryFactory.CreateLineString(next.Line.Coordinates .Concat(current.Line.Coordinates).ToArray())); } else if (!AddCoordinate(current.Line, currentCoordinate, nextCoordinate, linesToProlong, input.MinimalDistance)) { if (!AddCoordinate(next.Line, currentCoordinate, nextCoordinate, linesToProlong, input.MinimalDistance)) { linesToProlong.Add(_geometryFactory.CreateLineString(new[] { currentCoordinate, nextCoordinate })); } } }
/// <summary> /// This methods tries to find the coordinate to add on the closest line and prefers to return one of the edges if possible. /// </summary> /// <param name="lineToTestAgainst"></param> /// <param name="closestLine"></param> /// <param name="minimalDistance"></param> /// <returns></returns> private Coordinate GetCoordinateToAdd(ILineString lineToTestAgainst, ILineString closestLine, double minimalDistance) { var closestCoordinate = lineToTestAgainst.Coordinates.Last(); var edgeCoordinate = GetEdgeCoordiante(closestLine, closestCoordinate, minimalDistance, 1.5); if (edgeCoordinate != null) { return(edgeCoordinate); } if (lineToTestAgainst.Intersects(closestLine)) { var intecsectionCoordinate = lineToTestAgainst.Intersection(closestLine).Coordinates.First(); edgeCoordinate = GetEdgeCoordiante(closestLine, intecsectionCoordinate, minimalDistance, 3); return(edgeCoordinate ?? intecsectionCoordinate); } var closestCoordinateOnExitingLine = closestLine.Coordinates.OrderBy(c => c.Distance(closestCoordinate)).First(); if (closestCoordinateOnExitingLine.Distance(closestCoordinate) < minimalDistance) { return(closestCoordinateOnExitingLine); } var closestLineIndexed = new LengthIndexedLine(closestLine); var closestCoordinateProjectedIndex = closestLineIndexed.Project(closestCoordinate); var projectedCoordinate = closestLineIndexed.ExtractPoint(closestCoordinateProjectedIndex); _geometryFactory.PrecisionModel.MakePrecise(projectedCoordinate); edgeCoordinate = GetEdgeCoordiante(closestLine, projectedCoordinate, minimalDistance, 3); return(edgeCoordinate ?? projectedCoordinate); }
public void TestProjectPointWithDuplicateCoords() { var linearGeom = Read("LINESTRING (0 0, 10 0, 10 0, 20 0)"); var indexedLine = new LengthIndexedLine(linearGeom); double projIndex = indexedLine.Project(new Coordinate(10, 1)); Assert.IsTrue(projIndex == 10.0); }
/// <summary> /// Splits a branch at the given coordinate. /// All branch features are updated /// </summary> /// <param name="branch"></param> /// <param name="coordinate"></param> /// <param name="newBranchId"></param> /// <param name="newNodeId"></param> public static INode SplitBranchAtNode(IBranch branch, ICoordinate coordinate, long newBranchId, long newNodeId) { var lengthIndexedLine = new LengthIndexedLine(branch.Geometry); double offset = lengthIndexedLine.Project(coordinate); return(SplitBranchAtNode(branch, offset)); }
public static IGeometry Project(IGeometry g, IGeometry g2) { var ll = new LengthIndexedLine(g); double index = ll.Project(g2.Coordinate); var p = ll.ExtractPoint(index); return(g.Factory.CreatePoint(p)); }
public void TestProjectExtractPoint() { var linearGeom = Read("MULTILINESTRING ((0 2, 0 0), (-1 1, 1 1))"); var indexedLine = new LengthIndexedLine(linearGeom); double index = indexedLine.Project(new Coordinate(1, 0)); var pt = indexedLine.ExtractPoint(index); Assert.IsTrue(pt.Equals(new Coordinate(0, 0))); }
public void TestComputeZNaN() { var linearGeom = Read("LINESTRING (0 0, 10 10 10)"); var indexedLine = new LengthIndexedLine(linearGeom); double projIndex = indexedLine.Project(new Coordinate(5, 5)); var projPt = indexedLine.ExtractPoint(projIndex); Assert.IsTrue(double.IsNaN(projPt.Z)); }
/** * verbindet die zwei Linien bei den nähesten Punkten der Linien: * erster Teil it Anfang der Linie <code>line0</code> bis zum (ersten) nähesten Punkt zu <code>line1</code> * zweitert Teilverbindet die zwei nähesten Punkte * dritter Teil ist der Endteil von <code>line1</code> ab dem nähesten Punkt * @param line0 * @param line1 * @return */ private static List <Coordinate> concat(ILineString line0, ILineString line1) { List <Coordinate> listCoords = new List <Coordinate>(); IGeometry intersection = line0.Intersection(line1); LengthIndexedLine lil0 = new LengthIndexedLine(line0); LengthIndexedLine lil1 = new LengthIndexedLine(line1); Coordinate[] closestPoints = DistanceOp.NearestPoints(line0, line1); if (!intersection.IsEmpty) { // die 2 Linien kreuzen sich double maxPos = 0; for (int i = 0; i < intersection.NumPoints; i++) { // den letzten Schnittpunkt suchen Coordinate crossPoint = intersection.Coordinates[i]; double pos = lil0.Project(crossPoint); if (maxPos < pos) { maxPos = pos; closestPoints[0] = crossPoint; closestPoints[1] = crossPoint; } } } for (int i = 0; i < line0.Coordinates.Length; i++) { if (lil0.Project(line0.Coordinates[i]) < lil0.Project(closestPoints[0])) { listCoords.Add(line0.Coordinates[i]); } } listCoords.Add(closestPoints[0]); if (closestPoints[0] != closestPoints[1]) { // die 2 Linien kreuzen sich nicht listCoords.Add(closestPoints[1]); } for (int i = 0; i < line1.Coordinates.Length; i++) { if (lil1.Project(line1.Coordinates[i]) > lil1.Project(closestPoints[1])) { listCoords.Add(line1.Coordinates[i]); } } return(listCoords); }
public void TestComputeZ() { IGeometry linearGeom = Read("LINESTRING (0 0 0, 10 10 10)"); LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double projIndex = indexedLine.Project(new Coordinate(5, 5)); Coordinate projPt = indexedLine.ExtractPoint(projIndex); // System.out.println(projPt); Assert.IsTrue(projPt.Equals3D(new Coordinate(5, 5, 5))); }
private void HandleIntersectionCase(GpxProlongerExecutorInput input, SegmentWithLines segment, List <ILineString> linesToProlong) { var intersection = segment.Start.Line.Intersection(segment.End.Line).Coordinates .OrderBy(c => c.Distance(segment.Start.Coordinate) + c.Distance(segment.End.Coordinate)).FirstOrDefault(); if (intersection == null) { var distance = new DistanceOp(segment.Start.Line, segment.End.Line); intersection = distance.NearestPoints().First(); } var currentLengthIndexedLine = new LengthIndexedLine(segment.Start.Line); var closestCoordinateCurrentIndex = currentLengthIndexedLine.Project(segment.Start.Coordinate); var closestCoordinateCurrentIntersectionIndex = currentLengthIndexedLine.Project(intersection); var currentSegment = currentLengthIndexedLine.ExtractLine(closestCoordinateCurrentIndex, closestCoordinateCurrentIntersectionIndex); var nextLengthIndexedLine = new LengthIndexedLine(segment.End.Line); var closestCoordinateNextIndex = nextLengthIndexedLine.Project(segment.End.Coordinate); var closestCoordinateNextIntersectionIndex = nextLengthIndexedLine.Project(intersection); var nextSegment = nextLengthIndexedLine.ExtractLine(closestCoordinateNextIntersectionIndex, closestCoordinateNextIndex); var coordinates = currentSegment.Coordinates.Concat(nextSegment.Coordinates) .Concat(new[] { currentSegment.Coordinates.First() }).ToArray(); if (coordinates.Length < 4) { return; } var polygon = new Polygon(new LinearRing(coordinates)); if (polygon.Area < input.MinimalAreaSize) { return; } var currentCoordinate = currentLengthIndexedLine.ExtractPoint(closestCoordinateCurrentIndex); var nextCoordinate = nextLengthIndexedLine.ExtractPoint(closestCoordinateNextIndex); var line = CreateLineString(currentCoordinate, segment.OriginalCoordinates, nextCoordinate); linesToProlong.Add(line); }
public void TestComputeZ() { var linearGeom = Read("LINESTRING (0 0 0, 10 10 10)"); var indexedLine = new LengthIndexedLine(linearGeom); double projIndex = indexedLine.Project(new Coordinate(5, 5)); var projPt = indexedLine.ExtractPoint(projIndex); // System.out.println(projPt); Assert.That(projPt, Is.InstanceOf <CoordinateZ>()); Assert.IsTrue(((CoordinateZ)projPt).Equals3D(new CoordinateZ(5, 5, 5))); }
public static Geometry Project(Geometry g, Geometry g2) { var ll = new LengthIndexedLine(g); if (g2.Dimension == Dimension.Curve) { var line = (LineString)g2.GetGeometryN(0); var pStart = line.GetCoordinateN(0); var pEnd = line.GetCoordinateN(line.NumPoints - 1); double indexStart = ll.Project(pStart); double indexEnd = ll.Project(pEnd); return(ll.ExtractLine(indexStart, indexEnd)); } else { double index = ll.Project(g2.Coordinate); var p = ll.ExtractPoint(index); return(g.Factory.CreatePoint(p)); } }
protected override void CalculateLocation(VehicleManager vehicleManager) { if (lengthIndexedLine == null) { return; } var oldCoordinate = vehicleManager.Position.Location; var newCoordinate = lengthIndexedLine.ExtractPoint(lengthIndexedLine.Project(oldCoordinate) + 0.000001 * Speed); vehicleManager.Position.Location = newCoordinate; vehicleManager.Position.Speed = Speed; vehicleManager.Position.Angle = vehicleManager.Position.Angle; }
private void HandleSelfClosingCase(GpxProlongerExecutorInput input, SegmentWithLines segment, List <ILineString> linesToProlong) { var lengthIndexedLine = new LengthIndexedLine(segment.Start.Line); var closestCoordinateCurrentIndex = lengthIndexedLine.Project(segment.Start.Coordinate); var closestCoordinateNextIndex = lengthIndexedLine.Project(segment.End.Coordinate); var indexedSegment = lengthIndexedLine.ExtractLine(closestCoordinateCurrentIndex, closestCoordinateNextIndex); var coordinates = indexedSegment.Coordinates.Concat(new[] { indexedSegment.Coordinates.First() }).ToArray(); if (coordinates.Length < 4) { return; } var polygon = new Polygon(new LinearRing(coordinates)); if (polygon.Area < input.MinimalAreaSize) { return; } if (!AddSegmentToLine(segment.Start.Line, segment, linesToProlong, input.MinimalDistance)) { linesToProlong.Add(CreateLineString(segment.StartProjected, segment.OriginalCoordinates, segment.EndProjected)); } }
private SegmentWithLines CreateSegmentWithLines(Coordinate[] segment, LineAndCoordinate current, LineAndCoordinate next) { var currentLengthIndexedLine = new LengthIndexedLine(current.Line); var currentCoordinate = currentLengthIndexedLine.ExtractPoint(currentLengthIndexedLine.Project(current.Coordinate)); var nextLengthIndexedLine = new LengthIndexedLine(next.Line); var nextCoordinate = nextLengthIndexedLine.ExtractPoint(nextLengthIndexedLine.Project(next.Coordinate)); var segmentWithLines = new SegmentWithLines { OriginalCoordinates = segment, Start = current, StartProjected = currentCoordinate, End = next, EndProjected = nextCoordinate }; return(segmentWithLines); }
public static double ProjectIndex(IGeometry g, IGeometry g2) { var ll = new LengthIndexedLine(g); return(ll.Project(g2.Coordinate)); }