Example #1
0
        /// <summary>
        /// Test whether two geometries lie within a given distance of each other.
        /// </summary>
        /// <param name="g0"></param>
        /// <param name="g1"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static bool IsWithinDistance(Geometry g0, Geometry g1, double distance)
        {
            // check envelope distance for a short-circuit negative result
            double envDist = g0.EnvelopeInternal.Distance(g1.EnvelopeInternal);

            if (envDist > distance)
            {
                return(false);
            }

            // MD - could improve this further with a positive short-circuit based on envelope MinMaxDist

            var distOp = new DistanceOp(g0, g1, distance);

            return(distOp.Distance() <= distance);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="wktA"></param>
        /// <param name="wktB"></param>
		public virtual void  FindClosestPoint(string wktA, string wktB)
		{
			Console.WriteLine("-------------------------------------");
			try
			{
				IGeometry A = wktRdr.Read(wktA);
                IGeometry B = wktRdr.Read(wktB);
				Console.WriteLine("Geometry A: " + A);
				Console.WriteLine("Geometry B: " + B);
				DistanceOp distOp = new DistanceOp(A, B);
				
				double distance = distOp.Distance();
				Console.WriteLine("Distance = " + distance);
				
				Coordinate[] closestPt = distOp.NearestPoints();
				ILineString closestPtLine = fact.CreateLineString(closestPt);
				Console.WriteLine("Closest points: " + closestPtLine + " (distance = " + closestPtLine.Length + ")");
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.StackTrace);
			}
		}
Example #3
0
        /// <summary>
        /// Compute the the closest points of two geometries.
        /// The points are presented in the same order as the input Geometries.
        /// </summary>
        /// <param name="g0">A <c>Geometry</c>.</param>
        /// <param name="g1">Another <c>Geometry</c>.</param>
        /// <returns>The closest points in the geometries.</returns>
        public static Coordinate[] NearestPoints(IGeometry g0, IGeometry g1)
        {
            var distOp = new DistanceOp(g0, g1);

            return(distOp.NearestPoints());
        }
Example #4
0
        /// <summary>
        /// Test whether two geometries lie within a given distance of each other.
        /// </summary>
        /// <param name="g0"></param>
        /// <param name="g1"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static bool IsWithinDistance(IGeometry g0, IGeometry g1, double distance)
        {
            var distOp = new DistanceOp(g0, g1, distance);

            return(distOp.Distance() <= distance);
        }
Example #5
0
        /// <summary>
        /// Compute the distance between the closest points of two geometries.
        /// </summary>
        /// <param name="g0">A <c>Geometry</c>.</param>
        /// <param name="g1">Another <c>Geometry</c>.</param>
        /// <returns>The distance between the geometries.</returns>
        public static double Distance(IGeometry g0, IGeometry g1)
        {
            var distOp = new DistanceOp(g0, g1);

            return(distOp.Distance());
        }
 /// <summary>
 /// Compute the distance between the closest points of two geometries.
 /// </summary>
 /// <param name="g0">A <c>Geometry</c>.</param>
 /// <param name="g1">Another <c>Geometry</c>.</param>
 /// <returns>The distance between the geometries.</returns>
 public static double Distance(IGeometry g0, IGeometry g1)
 {
     DistanceOp distOp = new DistanceOp(g0, g1);
     return distOp.Distance();
 }
 /// <summary>
 /// Compute the the closest points of two geometries.
 /// The points are presented in the same order as the input Geometries.
 /// </summary>
 /// <param name="g0">A <c>Geometry</c>.</param>
 /// <param name="g1">Another <c>Geometry</c>.</param>
 /// <returns>The closest points in the geometries.</returns>
 public static Coordinate[] NearestPoints(IGeometry g0, IGeometry g1)
 {
     DistanceOp distOp = new DistanceOp(g0, g1);
     return distOp.NearestPoints();
 }
 /// <summary>
 /// Test whether two geometries lie within a given distance of each other.
 /// </summary>
 /// <param name="g0"></param>
 /// <param name="g1"></param>
 /// <param name="distance"></param>
 /// <returns></returns>
 public static bool IsWithinDistance(IGeometry g0, IGeometry g1, double distance)
 {
     DistanceOp distOp = new DistanceOp(g0, g1, distance);
     return distOp.Distance() <= distance;
 }
        ///<summary>
        /// Checks that two geometries are at least a minumum 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(IGeometry g1, IGeometry 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)
 {
     DistanceOp 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);
 }