public static Result Execute(IGeometry geometryA, IGeometry geometryB) { double distance = double.PositiveInfinity; IPoint closestPointA = null; IPoint closestPointB = null; foreach (IPoint aPoint in geometryA.GetCoordinates().SelectMany(a => a.Select(b => b))) { NearestPointOnLine.Result result; result = NearestPointOnLine.Execute(aPoint, geometryA); if (result.Distance < distance) { distance = result.Distance; closestPointA = aPoint; closestPointB = result.Point; } } foreach (IPoint bPoint in geometryB.GetCoordinates().SelectMany(a => a.Select(b => b))) { NearestPointOnLine.Result result; result = NearestPointOnLine.Execute(bPoint, geometryB); if (result.Distance < distance) { distance = result.Distance; closestPointB = bPoint; closestPointA = result.Point; } } return(Result.Create(closestPointA, closestPointB, distance)); }
public static Result Execute(IFeatureSet featureSetA, IFeatureSet featureSetB) { double distance = double.PositiveInfinity; IPoint closestPointA = null; IPoint closestPointB = null; IFeature closestFeatureA = null; IFeature closestFeatureB = null; foreach (IFeature aFeature in featureSetA.Features) { foreach (IPoint aPoint in aFeature.Geometry.GetCoordinates().SelectMany(a => a.Select(b => b))) { NearestPointOnLine.Result result; foreach (IFeature feature in featureSetB.Features) { result = NearestPointOnLine.Execute(aPoint, feature.Geometry); if (result.Distance < distance) { distance = result.Distance; closestPointA = aPoint; closestPointB = result.Point; closestFeatureA = aFeature; closestFeatureB = feature; } } } } foreach (IFeature bFeature in featureSetB.Features) { foreach (IPoint bPoint in bFeature.Geometry.GetCoordinates().SelectMany(a => a.Select(b => b))) { NearestPointOnLine.Result result; foreach (IFeature feature in featureSetA.Features) { result = NearestPointOnLine.Execute(bPoint, feature.Geometry); if (result.Distance < distance) { distance = result.Distance; closestPointB = bPoint; closestPointA = result.Point; closestFeatureA = feature; closestFeatureB = bFeature; } } } } return(Result.Create( closestPointA, closestPointB, distance, featureA: closestFeatureA, featureB: closestFeatureB, geometryA: closestFeatureA != null ? closestFeatureA.Geometry : null, geometryB: closestFeatureB != null ? closestFeatureB.Geometry : null)); }