private LineString GetLineWithExtraPoints(LineString currentLine, Coordinate coordinateToAddIfNeeded) { var point = new Point(coordinateToAddIfNeeded); if (currentLine.Distance(point) >= _options.MaxDistanceToExisitngLineForMerge * 2) { // coordinate not close enough return(currentLine); } var closestCoordinateOnGpx = currentLine.Coordinates.OrderBy(c => c.Distance(coordinateToAddIfNeeded)).First(); if (closestCoordinateOnGpx.Distance(coordinateToAddIfNeeded) < 2 * _options.MaxDistanceToExisitngLineForMerge) { // line already has a close enough coordinate return(currentLine); } // need to add a coordinate to the line var coordinates = currentLine.Coordinates.ToList(); var line = new LocationIndexedLine(currentLine); var projectedLocation = line.Project(coordinateToAddIfNeeded); var coordinateToAdd = line.ExtractPoint(projectedLocation); coordinates.Insert(projectedLocation.SegmentIndex + 1, coordinateToAdd); return(_geometryFactory.CreateLineString(coordinates.ToArray()) as LineString); }
public void TestGetSegmentMultiLineString() { IGeometry line = reader.Read("MULTILINESTRING ((0 0, 10 0, 20 0), (20 0, 30 0))"); LocationIndexedLine indexedLine = new LocationIndexedLine(line); LinearLocation loc0 = indexedLine.IndexOf(new Coordinate(0, 0)); LinearLocation loc0_5 = indexedLine.IndexOf(new Coordinate(5, 0)); LinearLocation loc1 = indexedLine.IndexOf(new Coordinate(10, 0)); LinearLocation loc2 = indexedLine.IndexOf(new Coordinate(20, 0)); LinearLocation loc2B = new LinearLocation(1, 0, 0.0); LinearLocation loc2_5 = indexedLine.IndexOf(new Coordinate(25, 0)); LinearLocation loc3 = indexedLine.IndexOf(new Coordinate(30, 0)); LineSegment seg0 = new LineSegment(new Coordinate(0, 0), new Coordinate(10, 0)); LineSegment seg1 = new LineSegment(new Coordinate(10, 0), new Coordinate(20, 0)); LineSegment seg2 = new LineSegment(new Coordinate(20, 0), new Coordinate(30, 0)); Assert.IsTrue(loc0.GetSegment(line).Equals(seg0)); Assert.IsTrue(loc0_5.GetSegment(line).Equals(seg0)); Assert.IsTrue(loc1.GetSegment(line).Equals(seg1)); Assert.IsTrue(loc2.GetSegment(line).Equals(seg1)); Assert.IsTrue(loc2_5.GetSegment(line).Equals(seg2)); Assert.IsTrue(loc3.GetSegment(line).Equals(seg2)); }
protected override bool IndexOfAfterCheck(IGeometry linearGeom, Coordinate testPt) { var indexedLine = new LocationIndexedLine(linearGeom); // check locations are consecutive var loc1 = indexedLine.IndexOf(testPt); var loc2 = indexedLine.IndexOfAfter(testPt, loc1); if (loc2.CompareTo(loc1) <= 0) { return(false); } // check extracted points are the same as the input var pt1 = indexedLine.ExtractPoint(loc1); var pt2 = indexedLine.ExtractPoint(loc2); if (!pt1.Equals2D(testPt)) { return(false); } if (!pt2.Equals2D(testPt)) { return(false); } return(true); }
protected override Coordinate ExtractOffsetAt(IGeometry linearGeom, Coordinate testPt, double offsetDistance) { var indexedLine = new LocationIndexedLine(linearGeom); var index = indexedLine.IndexOf(testPt); return(indexedLine.ExtractPoint(index, offsetDistance)); }
private void Stuff(MultiLineString multilinestring, IEnumerable <MultiLineString> troutStreamSections, MultiPolygon pal) { IGeometry[] t = multilinestring.Geometries; var stream = t.First(); var primaryLength = stream.Length; var lil = new LocationIndexedLine(stream); var lil2 = new LengthIndexedLine(stream); var result = stream.Intersection(pal) as MultiLineString; var geoms = result.Geometries; foreach (var part in geoms.Select(i => i as LineString)) { var subParts = lil.IndicesOf(part); var count = subParts.Length; foreach (var subPart in subParts) { var fraction = subPart.SegmentFraction; var noIdea = subPart.GetSegmentLength(part); var otherNoIdea = subPart.GetSegmentLength(stream); } var subParts2 = lil2.IndicesOf(part); var count2 = subParts2.Length; foreach (double subPart in subParts2) { // var fraction = subPart. // var noIdea = subPart.GetSegmentLength(part); // var otherNoIdea = subPart.GetSegmentLength(stream); } } }
public void TestRepeatedCoordsLineString() { var line = reader.Read("LINESTRING (10 0, 10 0, 20 0)"); var indexedLine = new LocationIndexedLine(line); var loc0 = indexedLine.IndexOf(new Coordinate(11, 0)); Assert.IsTrue(loc0.CompareTo(new LinearLocation(1, 0.1)) == 0); }
public void TestZeroLengthLineString() { var line = reader.Read("LINESTRING (10 0, 10 0)"); var indexedLine = new LocationIndexedLine(line); var loc0 = indexedLine.IndexOf(new Coordinate(11, 0)); Assert.IsTrue(loc0.CompareTo(new LinearLocation(0, Double.NaN)) == 0); }
protected override IGeometry IndicesOfThenExtract(IGeometry input, IGeometry subLine) { var indexedLine = new LocationIndexedLine(input); var loc = indexedLine.IndicesOf(subLine); var result = indexedLine.ExtractLine(loc[0], loc[1]); return(result); }
IGeometry InsertPoint(IGeometry geom, Coordinate point) { if (!(geom is ILineal)) { throw new InvalidOperationException(); } var lil = new LocationIndexedLine(geom); var ll = lil.Project(point); var element = (ILineString)geom.GetGeometryN(ll.ComponentIndex); var oldSeq = element.CoordinateSequence; var newSeq = element.Factory.CoordinateSequenceFactory.Create( oldSeq.Count + 1, oldSeq.Dimension); var j = 0; if (ll.SegmentIndex == 0 && ll.SegmentFraction == 0) { if (ll.GetSegment(element).P0.Distance(point) == 0) { return(geom); } newSeq.SetCoordinate(0, point); CoordinateSequences.Copy(oldSeq, 0, newSeq, 1, oldSeq.Count); } else if (ll.SegmentIndex == oldSeq.Count - 1 && ll.SegmentFraction == 0) { if (ll.GetSegment(element).P0.Distance(point) == 0) { return(geom); } CoordinateSequences.Copy(oldSeq, 0, newSeq, 0, oldSeq.Count); newSeq.SetCoordinate(oldSeq.Count, point); } else { if (ll.IsVertex) { return(geom); } CoordinateSequences.Copy(oldSeq, 0, newSeq, 0, ll.SegmentIndex + 1); newSeq.SetCoordinate(ll.SegmentIndex + 1, point); CoordinateSequences.Copy(oldSeq, ll.SegmentIndex + 1, newSeq, ll.SegmentIndex + 2, newSeq.Count - 2 - ll.SegmentIndex); } var lines = new List <IGeometry>(); LineStringExtracter.GetLines(geom, lines); lines[ll.ComponentIndex] = geom.Factory.CreateLineString(newSeq); if (lines.Count == 1) { return(lines[0]); } return(geom.Factory.BuildGeometry(lines)); }
private void RunExtractLine(string wkt, LinearLocation start, LinearLocation end, string expected) { var geom = Read(wkt); var lil = new LocationIndexedLine(geom); var result = lil.ExtractLine(start, end); //System.out.println(result); CheckExpected(result, expected); }
private void RunExtractLine(String wkt, LinearLocation start, LinearLocation end, String expected) { IGeometry geom = Read(wkt); LocationIndexedLine lil = new LocationIndexedLine(geom); IGeometry result = lil.ExtractLine(start, end); //System.out.println(result); CheckExpected(result, expected); }
public void TestSameSegmentMultiLineString() { IGeometry line = reader.Read("MULTILINESTRING ((0 0, 10 0, 20 0), (20 0, 30 0))"); LocationIndexedLine indexedLine = new LocationIndexedLine(line); LinearLocation loc0 = indexedLine.IndexOf(new Coordinate(0, 0)); LinearLocation loc0_5 = indexedLine.IndexOf(new Coordinate(5, 0)); LinearLocation loc1 = indexedLine.IndexOf(new Coordinate(10, 0)); LinearLocation loc2 = indexedLine.IndexOf(new Coordinate(20, 0)); LinearLocation loc2B = new LinearLocation(1, 0, 0.0); LinearLocation loc2_5 = indexedLine.IndexOf(new Coordinate(25, 0)); LinearLocation loc3 = indexedLine.IndexOf(new Coordinate(30, 0)); Assert.IsTrue(loc0.IsOnSameSegment(loc0)); Assert.IsTrue(loc0.IsOnSameSegment(loc0_5)); Assert.IsTrue(loc0.IsOnSameSegment(loc1)); Assert.IsTrue(!loc0.IsOnSameSegment(loc2)); Assert.IsTrue(!loc0.IsOnSameSegment(loc2_5)); Assert.IsTrue(!loc0.IsOnSameSegment(loc3)); Assert.IsTrue(loc0_5.IsOnSameSegment(loc0)); Assert.IsTrue(loc0_5.IsOnSameSegment(loc1)); Assert.IsTrue(!loc0_5.IsOnSameSegment(loc2)); Assert.IsTrue(!loc0_5.IsOnSameSegment(loc3)); Assert.IsTrue(!loc2.IsOnSameSegment(loc0)); Assert.IsTrue(loc2.IsOnSameSegment(loc1)); Assert.IsTrue(loc2.IsOnSameSegment(loc2)); Assert.IsTrue(!loc2.IsOnSameSegment(loc3)); Assert.IsTrue(loc2B.IsOnSameSegment(loc3)); Assert.IsTrue(loc2_5.IsOnSameSegment(loc3)); Assert.IsTrue(!loc3.IsOnSameSegment(loc0)); Assert.IsTrue(!loc3.IsOnSameSegment(loc2)); Assert.IsTrue(loc3.IsOnSameSegment(loc2B)); Assert.IsTrue(loc3.IsOnSameSegment(loc2_5)); Assert.IsTrue(loc3.IsOnSameSegment(loc3)); }
public void TestSameSegmentLineString() { var line = reader.Read("LINESTRING (0 0, 10 0, 20 0, 30 0)"); var indexedLine = new LocationIndexedLine(line); var loc0 = indexedLine.IndexOf(new Coordinate(0, 0)); var loc0_5 = indexedLine.IndexOf(new Coordinate(5, 0)); var loc1 = indexedLine.IndexOf(new Coordinate(10, 0)); var loc2 = indexedLine.IndexOf(new Coordinate(20, 0)); var loc2_5 = indexedLine.IndexOf(new Coordinate(25, 0)); var loc3 = indexedLine.IndexOf(new Coordinate(30, 0)); Assert.IsTrue(loc0.IsOnSameSegment(loc0)); Assert.IsTrue(loc0.IsOnSameSegment(loc0_5)); Assert.IsTrue(loc0.IsOnSameSegment(loc1)); Assert.IsTrue(!loc0.IsOnSameSegment(loc2)); Assert.IsTrue(!loc0.IsOnSameSegment(loc2_5)); Assert.IsTrue(!loc0.IsOnSameSegment(loc3)); Assert.IsTrue(loc0_5.IsOnSameSegment(loc0)); Assert.IsTrue(loc0_5.IsOnSameSegment(loc1)); Assert.IsTrue(!loc0_5.IsOnSameSegment(loc2)); Assert.IsTrue(!loc0_5.IsOnSameSegment(loc3)); Assert.IsTrue(!loc2.IsOnSameSegment(loc0)); Assert.IsTrue(loc2.IsOnSameSegment(loc1)); Assert.IsTrue(loc2.IsOnSameSegment(loc2)); Assert.IsTrue(loc2.IsOnSameSegment(loc3)); Assert.IsTrue(loc2_5.IsOnSameSegment(loc3)); Assert.IsTrue(!loc3.IsOnSameSegment(loc0)); Assert.IsTrue(loc3.IsOnSameSegment(loc2)); Assert.IsTrue(loc3.IsOnSameSegment(loc2_5)); Assert.IsTrue(loc3.IsOnSameSegment(loc3)); }