arcgis engine 计算距离面积体积
生活随笔
收集整理的這篇文章主要介紹了
arcgis engine 计算距离面积体积
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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.html6.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 ? ? ? ? }
========
總結
以上是生活随笔為你收集整理的arcgis engine 计算距离面积体积的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图解.net程序集赋予强名称
- 下一篇: arcgis坐标系学习总结