IProximityOperator接口用于获取两个几何图形的距离,以及给定一个Point,求另一个几何图形上离离给定点最近的点。IProximityOperator接口的主要方法有:QueryNearesPoint,ReturnDistance, ReturnNearestPoint
ReturnDistance方法用于返回两个几何对象间的最短距离,QueryNearesPoint方法用于查询获取几何对象上离给定输入点的最近距离的点的引用,ReturnNearestPoint方法用于创建并返回几何对象上离给定输入点的最近距离的点

  1. IMap pMap = axMapControl1.Map;
  2.            ILayer pLayer = null;
  3.            IPoint po=null;
  4.            IPolyline pl=null;
  5.            IFeatureLayer featurelayer=null;
  6.            IFeatureClass featureclass = null;
  7.            IGraphicsContainer gra;
  8.            IElement ptele;
  9.            IPointCollection lineptcol;
  10.            gra = axMapControl1.Map as IGraphicsContainer;
  11.            lineptcol = new PolylineClass();
  12.            for (int i = 0; i < pMap.LayerCount; i++)
  13.            {
  14.                pLayer = pMap.get_Layer(i);
  15.                 featurelayer = pLayer as IFeatureLayer;
  16.                 featureclass = featurelayer.FeatureClass;
  17.                IFeature feature = featureclass.GetFeature(0);
  18.  
  19.                if (feature.Shape is IPoint)
  20.                {
  21.                    po = feature.Shape as IPoint;
  22.                }
  23.                else {
  24.                     pl = feature.Shape as IPolyline;
  25.                }
  26.                //MessageBox.Show("qqqq");
  27.            }
  28.  
  29.            double dis = GetTwoGeometryDistance(po, pl);
  30.            IPoint po2 = NearestPoint(po, pl);
  31.            object a = Type.Missing;
  32.            lineptcol.AddPoint(po, ref a, ref a);
  33.            lineptcol.AddPoint(po2, ref a, ref a);
  34.            IElement lineele = new LineElementClass();
  35.            IPolyline pline = new PolylineClass();
  36.            pline = lineptcol as IPolyline;
  37.            lineele.Geometry = pline as IGeometry;
  38.            gra.AddElement(lineele, 0);
  39.            axMapControl1.Refresh();
  40.            MessageBox.Show(dis.ToString());

计算几何图形之间的距离

  1. public
    double GetTwoGeometryDistance(IGeometry pGeometryA, IGeometry pGeometryB)
  2.         {
  3.             IProximityOperator pProOperator = pGeometryA as IProximityOperator;
  4.             if (pGeometryA != null || pGeometryB != null)
  5.             {
  6.                 double distance = pProOperator.ReturnDistance(pGeometryB);
  7.                 return distance;
  8.             }
  9.             else
  10.             {
  11.                 return 0;
  12.             }
  13.         }

离给定的几何图形最近的点

  1. //离给定的几何图形最近的点
  2.         public IPoint NearestPoint(IPoint pInputPoint, IGeometry pGeometry)
  3.         {
  4.             try
  5.             {
  6.                 IProximityOperator pProximity = (IProximityOperator)pGeometry;
  7.                 IPoint pNearestPoint = pProximity.ReturnNearestPoint(pInputPoint, esriSegmentExtension.esriNoExtension);
  8.                 return pNearestPoint;
  9.             }
  10.             catch (Exception Err)
  11.             {
  12.                 MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  13.                 return
    null;
  14.             }
  15.         }

计算出来最近的点,然后和初始的那个点连成一个线,也就做出了直线的中垂线

最新文章

  1. php 时间加减
  2. JAVA WEB 作用域之间的区别
  3. AOJ 0558 广度优先搜索
  4. BZOJ 2879 NOI2012美食节
  5. Stack Overflow for web end
  6. Extjs5.1中的新特性
  7. Cocos2d-x性能分析-Android版本之Gprof
  8. 201521123121 《Java程序设计》第14周学习总结
  9. IntelliJ IDEA 14.1.4设置关闭自动保存和标志改动文件为星号?
  10. qt中的tcp编程
  11. Laravel: 基础篇
  12. JDBC driver for MySQL连接提示&quot;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.&quot;解决方案
  13. Codeforces Beta Round #35 (Div. 2)
  14. java 高性能读模式(译)
  15. sql server 只读帐号设置能读取存储过程,view等内容。
  16. MySQL 5.7.17 Group Relication(组复制)搭建手册【转】
  17. MVC、MVP、MVVM 模式
  18. Dubbo (开源分布式服务框架)
  19. Linux Shell Vim 经常使用命令、使用技巧总结
  20. ThinkPHP项目笔记之MVC篇

热门文章

  1. Intervals POJ - 1201 差分约束
  2. Oracle存储过程实例分析总结(代码)
  3. 源码分析String
  4. 011 Container With Most Water 盛最多水的容器
  5. (转)CentOS 6下配置软RAID图文详解
  6. js中的focus()聚焦
  7. postgresql安装,java简单使用postgresql
  8. 开始使用JQuery 方法
  9. lazyload的使用心得
  10. c#基础 函数传值