arcgis engine 計算距離面積體積_arcgis

來源:互聯網
上載者:User
ArcGIS Engine二次開發——計算shapefile面圖層要素的面積 http://blog.csdn.net/giselite/article/details/44750349


全部都應該學會看AE的類圖和協助,尤其是類圖,在安裝目錄下的Diagram目錄裡,看多了自然就會得心應手。廢話不多說了,下面是我寫的一段實驗代碼


,公布一下,希望能協助那些有需求的童鞋,給他們節省點時間。


using System.Runtime;  
using System.Runtime.InteropServices;  
using ESRI.ArcGIS.Geodatabase;  
using ESRI.ArcGIS.DataSourcesFile;  
using ESRI.ArcGIS.Geometry;  
  
        private void Form1_Click(object sender, EventArgs e)  
        {  
            IWorkspaceFactory pWSF = null;  
            double dArea = 0;  
            try  
            {  
                pWSF = new ShapefileWorkspaceFactoryClass();  
                IFeatureWorkspace pWS = pWSF.OpenFromFile(@"H:\水體淹沒面積", 0) as IFeatureWorkspace;  
                IFeatureClass pFC = pWS.OpenFeatureClass("水體淹沒面積專題.shp");  
  
                IFeatureCursor pFeatureCur = pFC.Search(null, false);  
                IFeature pFeature = pFeatureCur.NextFeature();  
                while (pFeature != null)  
                {  
                    if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)  
                    {  
                        IArea pArea = pFeature.Shape as IArea;  
                        dArea = dArea + pArea.Area;  
                    }  
  
                    pFeature = pFeatureCur.NextFeature();  
                }  
  
                Marshal.ReleaseComObject(pFeatureCur);  
            }  
            catch (System.Exception ex)  
            {  
                  
            }  
  
            Marshal.ReleaseComObject(pWSF);  
        }  
========
6.5 IProximityOperator介面 http://www.cnblogs.com/gisoracle/archive/2012/03/28/2420706.html


6.5.1 IProximityOperator介面簡介


IProximityOperator介面用於擷取兩個幾何圖形的距離,以及給定一個 Point,求另一個幾何圖形上離離給定點最近的點。IProximityOperator介面的主


要方法有:QueryNearesPoint,ReturnDistance, ReturnNearestPoint


ReturnDistance方法用於返回兩個幾何對象間的最短距離,QueryNearesPoint方法用於查詢擷取幾何對象上離給定輸入焦點的最近距離的點的引用,


ReturnNearestPoint方法用於建立並返回幾何對象上離給定輸入焦點的最近距離的點。


6.5.2 最近點查詢功能開發


以下程式碼片段示範如何使用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;
            }
     }
========
空間關係(計算兩點間距離、計算範圍) http://xitong.iteye.com/blog/1715755


計算兩點間距離


1         /// <summary>計算兩點間距離
2 /// </summary>
3 /// <param name="point1"></param>
4 /// <param name="point2"></param>
5 /// <returns></returns>
6         public static double getDistanceOfTwoPoints(ESRI.ArcGIS.Geometry.IPoint point1, ESRI.ArcGIS.Geometry.IPoint point2)
7         {
8             return Math.Sqrt((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y));
9         }


feature平移
1 IGeometry geo=feature.Shape;
2 ((ITransform2D)geo).Move(20,20);




計算範圍


得到點集合的n倍Envelope範圍


 1         /// <summary>得到點集合的n倍Envelope範圍
 2 /// </summary>
 3 /// <param name="points"></param>
 4 /// <param name="zoomInNumber"></param>
 5 /// <returns></returns>
 6         public static IEnvelope getBigEnvelope(IPointCollection points, double zoomInNumber)
 7         {
 8             IEnvelope result = new EnvelopeClass();
 9 
10             double xmax = 0, xmin = 999999999999, ymax = 0, ymin = 999999999999;
11 
12             for (int i = 0; i < points.PointCount; i++)
13             {
14                 ESRI.ArcGIS.Geometry.IPoint p = points.get_Point(i);
15                 if (xmax < p.X) xmax = p.X;
16                 if (ymax < p.Y) ymax = p.Y;
17                 if (xmin > p.X) xmin = p.X;
18                 if (ymin > p.Y) ymin = p.Y;
19             }
20             result.XMax = xmax + xmax - xmin;
21             result.XMin = xmin - xmax + xmin;
22             result.YMax = ymax + ymax - ymin;
23             result.YMin = ymin - ymax + ymin;
24 
25             return result;
26         }
========

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.