IProximityOperator接口用于获取两个几何图形的距离,以及给定一个Point,求另一个几何图形上离离给定点最近的点。IProximityOperator接口的主要方法有:QueryNearesPoint,ReturnDistance, ReturnNearestPoint
ReturnDistance方法用于返回两个几何对象间的最短距离,QueryNearesPoint方法用于查询获取几何对象上离给定输入点的最近距离的点的引用,ReturnNearestPoint方法用于创建并返回几何对象上离给定输入点的最近距离的点。
以下代码片段演示如何使用IProximityOperator接口获取给定点与要查询的几何图形的最近点:
/// 在pGeometry上返回一个离pInputPoint最近的point
/// </summary>
/// <param name="pInputPoint">给定的点对象</param>
/// <param name="pGeometry">要查询的几何图形</param>
/// <returns>the nearest Point</returns>
private IPoint NearestPoint(IPoint pInputPoint, IGeometry pGeometry)
{
try
{
IProximityOperator pProximity = (IProximityOperator)pGeometry;
IPoint pNearestPoint = pProximity.ReturnNearestPoint(pInputPoint, esriSegmentExtension.esriNoExtension);
return pNearestPoint;
}
catch(Exception Err)
{
MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return null;
}
}
以下代码片段演示如何使用IProximityOperator接口查询给定的两个几何对象的距离:
/// <summary>
/// 获取两个几何图形的距离
/// </summary>
/// <param name="pGeometryA">几何图形A</param>
/// <param name="pGeometryB">几何图形B</param>
/// <returns>两个几何图形的距离</returns>
private double GetTwoGeometryDistance(IGeometry pGeometryA, IGeometry pGeometryB)
{
IProximityOperator pProOperator = pGeometryA as IProximityOperator;
if (pGeometryA!=null|| pGeometryB !=null)
{
double distance= pProOperator.ReturnDistance(pGeometryB);
return distance;
}
else
{
return 0;
}
}