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); }
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); }
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)); }