/// <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); } }
/// <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); }
/// <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> /// 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]) + " )"; } }