Exemplo n.º 1
0
        public void ProlongStart_NoPoints_ShouldReturnOriginalLine()
        {
            var lineToProlong = new LineString(new [] { new Coordinate(0, 0), new Coordinate(1, 1) });

            var results = _executor.ProlongLineStart(lineToProlong, new Coordinate[0], new List <LineString>(), 5, 200);

            Assert.AreEqual(lineToProlong.Coordinates.Length, results.Coordinates.Length);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method is try to prolong all lines according to original GPS trace.
        /// for each line it prolongs the start of the line unless the previous line was already prolonged to intersect it.
        /// </summary>
        /// <param name="linesToProlong"></param>
        /// <param name="gpxItmLines"></param>
        /// <returns></returns>
        private async Task <List <ILineString> > ProlongLinesStartAccordingToOriginalGpx(List <ILineString> linesToProlong, List <ILineString> gpxItmLines)
        {
            var prolongedLines       = new List <ILineString>();
            var currentLineIndex     = gpxItmLines.Count - 1;
            var currentPositionIndex = gpxItmLines[currentLineIndex].Coordinates.Length - 1;

            for (int lineIndex = linesToProlong.Count - 1; lineIndex >= 0; lineIndex--)
            {
                var prolongedLine         = linesToProlong[lineIndex];
                var previousLineToProlong = lineIndex > 0 ? linesToProlong[lineIndex - 1] : null;
                if (previousLineToProlong != null && previousLineToProlong.Intersects(prolongedLine))
                {
                    prolongedLines.Add(prolongedLine);
                    continue;
                }
                var currentCoordinate = prolongedLine.Coordinates.First();
                UpdateIndexes(currentCoordinate, gpxItmLines, ref currentLineIndex, ref currentPositionIndex);
                var originalCoordinates = gpxItmLines[currentLineIndex].Coordinates.Take(currentPositionIndex + 1).ToArray();

                var lineStringInArea = await GetLineStringsInArea(new LineString(new[] { currentCoordinate, currentCoordinate }),
                                                                  _options.MaximalProlongLineLength);

                var prolongedLineStart = _gpxProlongerExecutor.ProlongLineStart(prolongedLine,
                                                                                originalCoordinates,
                                                                                lineStringInArea.Concat(prolongedLines).Concat(linesToProlong.Take(lineIndex)).ToArray(),
                                                                                _options.DistanceToExisitngLineMergeThreshold,
                                                                                _options.MaximalProlongLineLength);

                prolongedLines.Add(prolongedLineStart);
            }
            prolongedLines.Reverse(); // reverse back to keep the original order of the lines
            return(prolongedLines);
        }