arcgis engine计算点到线的最短距离
2024-08-31 22:38:25
IProximityOperator接口用于获取两个几何图形的距离,以及给定一个Point,求另一个几何图形上离离给定点最近的点。IProximityOperator接口的主要方法有:QueryNearesPoint,ReturnDistance, ReturnNearestPoint
ReturnDistance方法用于返回两个几何对象间的最短距离,QueryNearesPoint方法用于查询获取几何对象上离给定输入点的最近距离的点的引用,ReturnNearestPoint方法用于创建并返回几何对象上离给定输入点的最近距离的点
- IMap pMap = axMapControl1.Map;
- ILayer pLayer = null;
- IPoint po=null;
- IPolyline pl=null;
- IFeatureLayer featurelayer=null;
- IFeatureClass featureclass = null;
- IGraphicsContainer gra;
- IElement ptele;
- IPointCollection lineptcol;
- gra = axMapControl1.Map as IGraphicsContainer;
- lineptcol = new PolylineClass();
- for (int i = 0; i < pMap.LayerCount; i++)
- {
- pLayer = pMap.get_Layer(i);
- featurelayer = pLayer as IFeatureLayer;
- featureclass = featurelayer.FeatureClass;
- IFeature feature = featureclass.GetFeature(0);
- if (feature.Shape is IPoint)
- {
- po = feature.Shape as IPoint;
- }
- else {
- pl = feature.Shape as IPolyline;
- }
- //MessageBox.Show("qqqq");
- }
- double dis = GetTwoGeometryDistance(po, pl);
- IPoint po2 = NearestPoint(po, pl);
- object a = Type.Missing;
- lineptcol.AddPoint(po, ref a, ref a);
- lineptcol.AddPoint(po2, ref a, ref a);
- IElement lineele = new LineElementClass();
- IPolyline pline = new PolylineClass();
- pline = lineptcol as IPolyline;
- lineele.Geometry = pline as IGeometry;
- gra.AddElement(lineele, 0);
- axMapControl1.Refresh();
- MessageBox.Show(dis.ToString());
计算几何图形之间的距离
- public
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;
- }
- }
离给定的几何图形最近的点
- //离给定的几何图形最近的点
- public 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; - }
- }
计算出来最近的点,然后和初始的那个点连成一个线,也就做出了直线的中垂线
最新文章
- php 时间加减
- JAVA WEB 作用域之间的区别
- AOJ 0558 广度优先搜索
- BZOJ 2879 NOI2012美食节
- Stack Overflow for web end
- Extjs5.1中的新特性
- Cocos2d-x性能分析-Android版本之Gprof
- 201521123121 《Java程序设计》第14周学习总结
- IntelliJ IDEA 14.1.4设置关闭自动保存和标志改动文件为星号?
- qt中的tcp编程
- Laravel: 基础篇
- JDBC driver for MySQL连接提示";The connection property &#39;zeroDateTimeBehavior&#39; acceptable values are: &#39;CONVERT_TO_NULL&#39;, &#39;EXCEPTION&#39; or &#39;ROUND&#39;. The value &#39;convertToNull&#39; is not acceptable.";解决方案
- Codeforces Beta Round #35 (Div. 2)
- java 高性能读模式(译)
- sql server 只读帐号设置能读取存储过程,view等内容。
- MySQL 5.7.17 Group Relication(组复制)搭建手册【转】
- MVC、MVP、MVVM 模式
- Dubbo (开源分布式服务框架)
- Linux Shell Vim 经常使用命令、使用技巧总结
- ThinkPHP项目笔记之MVC篇