arcgis engine 计算距离面积体积

166 篇文章 21 订阅

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         }
========
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值