Exemple #1
0
        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 }));
                }
            }
        }
Exemple #2
0
        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 }));
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        private void HandleIntersectionCase(GpxProlongerExecutorInput input, LineAndCoordinate current, LineAndCoordinate next, List <ILineString> linesToProlong)
        {
            var intersection = current.Line.Intersection(next.Line).Coordinates
                               .OrderBy(c => c.Distance(current.Coordinate) + c.Distance(next.Coordinate)).FirstOrDefault();

            if (intersection == null)
            {
                var distance = new DistanceOp(current.Line, next.Line);
                intersection = distance.NearestPoints().First();
            }

            var currentLengthIndexedLine                  = new LengthIndexedLine(current.Line);
            var closestCoordinateCurrentIndex             = currentLengthIndexedLine.Project(current.Coordinate);
            var closestCoordinateCurrentIntersectionIndex = currentLengthIndexedLine.Project(intersection);
            var currentSegment =
                currentLengthIndexedLine.ExtractLine(closestCoordinateCurrentIndex, closestCoordinateCurrentIntersectionIndex);

            var nextLengthIndexedLine                  = new LengthIndexedLine(next.Line);
            var closestCoordinateNextIndex             = nextLengthIndexedLine.Project(next.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);

            linesToProlong.Add(_geometryFactory.CreateLineString(new[] { currentCoordinate, nextCoordinate }));
        }