arcgis engine計算點到線的最短距離


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.         }

計算出來最近的點,然后和初始的那個點連成一個線,也就做出了直線的中垂線


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM