Exemple #1
0
        /// <summary>
        /// Checks that two geometries are at least a minimum distance apart.
        /// </summary>
        /// <param name="g1">A geometry</param>
        /// <param name="g2">A geometry</param>
        /// <param name="minDist">The minimum distance the geometries should be separated by</param>
        private void CheckMinimumDistance(Geometry g1, Geometry g2, double minDist)
        {
            var distOp = new DistanceOp(g1, g2, minDist);

            _minDistanceFound = distOp.Distance();

            if (_minDistanceFound < minDist)
            {
                _isValid = false;
                var pts = distOp.NearestPoints();
                _errorLocation  = pts[1];
                _errorIndicator = g1.Factory.CreateLineString(pts);
                _errMsg         = "Distance between buffer curve and input is too small "
                                  + "(" + _minDistanceFound
                                  + " at " + WKTWriter.ToLineString(pts[0], pts[1]) + " )";
            }
        }
        private void DoNearestPointsTest(string wkt0, string wkt1, double distance,
                                         Coordinate p0, Coordinate p1)
        {
            var    op        = new DistanceOp(new WKTReader().Read(wkt0), new WKTReader().Read(wkt1));
            double tolerance = 1E-10;

            Assert.AreEqual(distance, op.NearestPoints()[0].Distance(op.NearestPoints()[1]), tolerance);
            Assert.AreEqual(p0.X, op.NearestPoints()[0].X, tolerance);
            Assert.AreEqual(p0.Y, op.NearestPoints()[0].Y, tolerance);
            Assert.AreEqual(p1.X, op.NearestPoints()[1].X, tolerance);
            Assert.AreEqual(p1.Y, op.NearestPoints()[1].Y, tolerance);
        }
Exemple #3
0
        /**
         * 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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="wktA"></param>
        /// <param name="wktB"></param>
        public virtual void  FindClosestPoint(string wktA, string wktB)
        {
            Console.WriteLine("-------------------------------------");
            try
            {
                var A = wktRdr.Read(wktA);
                var B = wktRdr.Read(wktB);
                Console.WriteLine("Geometry A: " + A);
                Console.WriteLine("Geometry B: " + B);
                var distOp = new DistanceOp(A, B);

                double distance = distOp.Distance();
                Console.WriteLine("Distance = " + distance);

                var closestPt     = distOp.NearestPoints();
                var closestPtLine = fact.CreateLineString(closestPt);
                Console.WriteLine("Closest points: " + closestPtLine + " (distance = " + closestPtLine.Length + ")");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
        public static IGeometry nearestPoints(IGeometry a, IGeometry b)
        {
            var pts = DistanceOp.NearestPoints(a, b);

            return(a.Factory.CreateLineString(pts));
        }