arcengine 中求任意两点的距离
时间: 2023-07-29 17:07:50 浏览: 131
在 ArcEngine 中,可以使用 Geometry 类的 Distance 方法来求解任意两点之间的距离。具体步骤如下:
1. 创建两个点对象,分别表示两个点的位置。
```csharp
IPoint point1 = new PointClass();
point1.PutCoords(x1, y1);
IPoint point2 = new PointClass();
point2.PutCoords(x2, y2);
```
2. 创建一个几何对象,将两个点加入其中。
```csharp
IGeometryCollection geometryCollection = new PolylineClass();
geometryCollection.AddGeometry(point1);
geometryCollection.AddGeometry(point2);
```
3. 调用 Geometry 类的 Distance 方法计算两点间距离。
```csharp
double distance = geometryCollection.Distance;
```
其中,distance 表示两点间的距离,单位与地图单位相同(如米、千米、英尺等)。
相关问题
arcengine 中求直线上两点的距离
在 ArcEngine 中,可以使用 `IProximityOperator` 接口的 `ReturnDistance` 方法来计算直线上两点的距离。具体步骤如下:
1. 获取直线要素对象(例如 `IPolyline`);
2. 获取直线的起点和终点(例如 `IPoint`);
3. 创建一个新的点对象(例如 `IPoint`)表示要计算距离的另一个点;
4. 获取 `IProximityOperator` 接口;
5. 调用 `ReturnDistance` 方法,传入两个点对象,即可得到直线上两点的距离。
示例代码如下:
```csharp
// polyline 为直线要素对象
IPolyline polyline = ...;
// 获取直线的起点和终点
IPoint startPoint = polyline.FromPoint;
IPoint endPoint = polyline.ToPoint;
// 创建一个新的点对象
IPoint point = new PointClass();
point.PutCoords(x, y); // 设置点的坐标值
// 获取 IProximityOperator 接口
IProximityOperator proximityOperator = polyline as IProximityOperator;
// 计算距离
double distance = proximityOperator.ReturnDistance(startPoint, point);
```
其中,`x` 和 `y` 分别为要计算距离的点的横坐标和纵坐标。
ArcEngine获取曲线上任意两点间的距离『转』
在ArcEngine中,可以通过以下步骤获取曲线上任意两点间的距离:
1. 获取曲线的几何属性,例如长度和端点坐标等。
```
IPolyline polyline = ... // 获取曲线对象
IGeometry geometry = polyline as IGeometry;
double length = geometry.Length; // 曲线长度
IPoint fromPoint = polyline.FromPoint; // 起点坐标
IPoint toPoint = polyline.ToPoint; // 终点坐标
```
2. 获取曲线上的点集合,可以通过调用 `IPointCollection` 接口的 `QueryPoint` 方法来获取。通过设置距离和方向参数,可以获取距离指定点一定距离处的点,从而实现获取任意两点间的距离。
```
IPointCollection pointCollection = polyline as IPointCollection;
IPoint startPoint = ... // 起点
IPoint endPoint = ... // 终点
double startDistance = polyline.FromPoint.Distance(startPoint); // 起点距离曲线起点的距离
double endDistance = polyline.FromPoint.Distance(endPoint); // 终点距离曲线起点的距离
int fromIndex = pointCollection.QueryPoint(startDistance, esriSegmentExtension.esriNoExtension);
int toIndex = pointCollection.QueryPoint(endDistance, esriSegmentExtension.esriNoExtension);
IPoint fromPointOnLine = pointCollection.get_Point(fromIndex); // 距起点最近的曲线点
IPoint toPointOnLine = pointCollection.get_Point(toIndex); // 距终点最近的曲线点
double distance = fromPointOnLine.Distance(toPointOnLine); // 任意两点间距离
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)