Arcgis面积测量

12 篇文章 1 订阅

面积测量中最主要的接口就是INewPolygonFeedback。

 

下面就是AreaMeasure.cs的全部内容,这是将实现和调用分开,在外部通过

            //自定义画多边形,测面积
            ToolbarControl.AddItem(new AreaMeasure(), -1, -1, true, 0,
                esriCommandStyles.esriCommandStyleIconOnly);

添加面积测量的功能。

 

AreaMeasure.cs的实现如下:

using System;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ADF.CATIDs;
using System.Runtime.InteropServices;

namespace com.san30.wjcg.Commands
{
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("5C214724-BFA2-4e8c-BC5D-775C67FA6F56")]

    /// <summary>
    /// 测量距离功能
    /// </summary>
    public class AreaMeasure : ICommand, ITool
    {
        #region COM Registration Function(s)
        [ComRegisterFunction()]
        [ComVisible(false)]
        static void RegisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryRegistration(registerType);

            //
            // TODO: Add any COM registration code here
            //
        }

        [ComUnregisterFunction()]
        [ComVisible(false)]
        static void UnregisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryUnregistration(registerType);

            //
            // TODO: Add any COM unregistration code here
            //
        }

        #region ArcGIS Component Category Registrar generated code
        /// <summary>
        /// Required method for ArcGIS Component Category registration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryRegistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT//CLSID//{{{0}}}", registerType.GUID);
            ControlsCommands.Register(regKey);

        }
        /// <summary>
        /// Required method for ArcGIS Component Category unregistration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryUnregistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT//CLSID//{{{0}}}", registerType.GUID);
            ControlsCommands.Unregister(regKey);

        }

        #endregion
        #endregion
        [DllImport("gdi32.dll")]
        static extern bool DeleteObject(IntPtr hObject);//删除对象

        private System.Drawing.Bitmap m_bitmap;//工具显示图标
        private IntPtr m_hBitmap;//用于表示指针或者句柄的平台特殊类型
        private IHookHelper m_pHookHelper;//句柄
        private System.Windows.Forms.Cursor m_areaMeasureCur;//光标

        private bool m_enabled;//是否可用
        private bool m_check;//是否选中

        private bool m_isMouseDown;//鼠标是否按下

        private INewPolygonFeedback m_pNewPolyFeedback;//INewPolygonFeedback,控制新的多边形显示反馈
        private IActiveView pActiveView;//视图
        /// <summary>
        ///构造函数
        /// </summary>
        public AreaMeasure()
        {
            //Load resources
            string[] res = GetType().Assembly.GetManifestResourceNames();
            if (res.GetLength(0) > 0)
            {
                m_bitmap = new System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream(GetType(), "AreaMeasure.bmp"));
                if (m_bitmap != null)
                {
                    m_bitmap.MakeTransparent(m_bitmap.GetPixel(1, 1));
                    m_hBitmap = m_bitmap.GetHbitmap();
                }
            }
            m_pHookHelper = new HookHelperClass();
        }

        /// <summary>
        /// 释构函数
        /// </summary>
        ~AreaMeasure()
        {
            if (m_hBitmap.ToInt32() != 0)
                DeleteObject(m_hBitmap);

            m_pHookHelper = null;

            m_check = false;
            //m_measureCur = null;

        }

        #region ICommand Members

        //点击
        public void OnClick()
        {
        }

        //消息 属性
        public string Message
        {
            get
            {
                return "测量多边形面积";
            }
        }

        //图标 属性
        public int Bitmap
        {
            get
            {
                return m_hBitmap.ToInt32();
            }
        }

        /// <summary>
        /// 创建工具命令
        /// </summary>
        /// <param name="hook">hook句柄</param>
        public void OnCreate(object hook)
        {
            m_pHookHelper.Hook = hook;
            m_enabled = true;
            m_check = false;

            m_areaMeasureCur = new System.Windows.Forms.Cursor(GetType().Assembly.GetManifestResourceStream(GetType(), "Area Measure.cur"));
        }

        //标题 属性
        public string Caption
        {
            get
            {
                return "测面积";
            }
        }

        //提示 属性
        public string Tooltip
        {
            get
            {
                return "测面积";
            }
        }

        //HelpContextID 属性
        public int HelpContextID
        {
            get
            {
                // TODO:  Add AreaMeasure.HelpContextID getter implementation
                return 0;
            }
        }

        //工具名 属性
        public string Name
        {
            get
            {
                return "Commands/AreaMeasure";
            }
        }

        //是否选中 属性
        public bool Checked
        {
            get
            {
                return m_check;
            }
        }

        //是否可用 属性
        public bool Enabled
        {
            get
            {
                return m_enabled;
            }
        }

        //帮组文件 属性
        public string HelpFile
        {
            get
            {
                // TODO:  Add AreaMeasure.HelpFile getter implementation
                return null;
            }
        }

        //种类 属性
        public string Category
        {
            get
            {
                return "Commands/AreaMeasure";
            }
        }

        #endregion

        #region ITool Members

        /// <summary>
        /// 鼠标按下事件
        /// </summary>
        /// <param name="button">button按钮</param>
        /// <param name="shift">shift键</param>
        /// <param name="x">屏幕X坐标</param>
        /// <param name="y">屏幕Y坐标</param>
        public void OnMouseDown(int button, int shift, int x, int y)
        {
            //Create a point in map coordinates
            //IActiveView pActiveView = (IActiveView)m_pHookHelper.FocusMap;
            m_isMouseDown = true;
            if (pActiveView == null)
            {
                //Create a point in map coordinates
                pActiveView = (IActiveView)m_pHookHelper.FocusMap;
            }
            //点
            IPoint pPoint;
            pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
 
            //Check that user is not using an existing feedback
            if( m_pNewPolyFeedback == null ){

            // Create a symbol (and color) to use for the Feedback
            //this is optional - a default symbol is used if none is given
            ISimpleLineSymbol pSLineSymFeed;
            //颜色
            IRgbColor pRGB;
   
            m_pNewPolyFeedback = new  NewPolygonFeedbackClass();
            //Get the new Feedback's symbol by reference
            pSLineSymFeed = m_pNewPolyFeedback.Symbol as ISimpleLineSymbol;
   
            pRGB = new  RgbColorClass();
            //Make a color
            pRGB.Red = 140;
            pRGB.Green = 140;
            pRGB.Blue = 255;

   
            //Setup the symbol with color and style
            pSLineSymFeed.Color = pRGB;
            pSLineSymFeed.Style= esriSimpleLineStyle.esriSLSDot;
            //Set the new Feedback's Display and StartPoint
            m_pNewPolyFeedback.Display = pActiveView.ScreenDisplay;
            m_pNewPolyFeedback.Start(pPoint);
            }
            else{
           //Otherwise use the current mouse location to add a vertex to the current feedback
                m_pNewPolyFeedback.AddPoint(pPoint);

            }
        }

        /// <summary>
        /// 鼠标移动事件
        /// </summary>
        /// <param name="button">button按钮</param>
        /// <param name="shift">shift键</param>
        /// <param name="x">屏幕X坐标</param>
        /// <param name="y">屏幕Y坐标</param>
        public void OnMouseMove(int button, int shift, int x, int y)
        {
            if (!m_isMouseDown) return;

            //Check if the user is currently using the feedback
            if( m_pNewPolyFeedback!= null)
            {
                //Move the Feedback to the current mouse location
                if (pActiveView == null)
                {
                    //Create a point in map coordinates
                    pActiveView = (IActiveView)m_pHookHelper.FocusMap;
                }
                //坐标系中的点
                IPoint pPoint;
                pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
                m_pNewPolyFeedback.MoveTo(pPoint);
            }
        }

        /// <summary>
        /// 鼠标放开事件
        /// </summary>
        /// <param name="button">button按钮</param>
        /// <param name="shift">shift键</param>
        /// <param name="x">屏幕X坐标</param>
        /// <param name="y">屏幕Y坐标</param>
        public void OnMouseUp(int button, int shift, int x, int y)
        {
            // TODO:  Add AreaMeasure.OnMouseUp implementation
        }

        /// <summary>
        /// 键盘按下事件
        /// </summary>
        /// <param name="keyCode">键编码</param>
        /// <param name="shift">shift键</param>
        public void OnKeyDown(int keyCode, int shift)
        {
            if (m_isMouseDown)
            {
                if (keyCode == 27)
                {
                    m_isMouseDown = false;
                    m_pNewPolyFeedback = null;
                    m_pHookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
                }
            }
        }

        /// <summary>
        /// 键盘放开事件
        /// </summary>
        /// <param name="keyCode">键编码</param>
        /// <param name="shift">shift键</param>
        public void OnKeyUp(int keyCode, int shift)
        {
            if (m_isMouseDown)
            {
                if (keyCode == 27)
                {
                    m_isMouseDown = false;
                    m_pNewPolyFeedback = null;
                    m_pHookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
                }
            }
        }


        /// <summary>
        /// 光标
        /// </summary>
        public int Cursor
        {
            get
            {
                return m_areaMeasureCur.Handle.ToInt32();
            }
        }

        /// <summary>
        /// 上下文菜单事件
        /// </summary>
        /// <param name="x">屏幕X坐标</param>
        /// <param name="y">屏幕Y坐标</param>
        /// <returns>bool</returns>
        public bool OnContextMenu(int x, int y)
        {
            // TODO:  Add AreaMeasure.OnContextMenu implementation
            return false;
        }

        /// <summary>
        /// 解除事件
        /// </summary>
        /// <returns>bool</returns>
        public bool Deactivate()
        {
            return true;
        }

        /// <summary>
        /// 刷新
        /// </summary>
        /// <param name="hdc">hdc</param>
        public void Refresh(int hdc)
        {
            //Get a reference to the ActiveView
            if (m_pHookHelper != null)
            {
                pActiveView = (IActiveView)m_pHookHelper.FocusMap;
            }
        }

        /// <summary>
        /// 双击事件
        /// </summary>
        public void OnDblClick()
        {
            //图形
            IGeometry pGeompoly = null;

            //Get the geometry (Polygon) returned from the feedback
            if (m_pNewPolyFeedback != null)
            {
                pGeompoly = m_pNewPolyFeedback.Stop();
            }

            //' If it is valid then draw a Geompoly on the ActiveView using the
            // DrawGeompoly procedure
            if (pGeompoly != null)
            {
                //AddCreateElement(pGeompoly, pActiveView);
                if (pGeompoly.GeometryType.Equals(esriGeometryType.esriGeometryPolygon))
                {
                    DrawGeompoly(pGeompoly, pActiveView);

                }
                //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            //' Set the feedback to nothing for the next use
            m_pNewPolyFeedback = null;
        }

        /// <summary>
        /// 画多边形
        /// </summary>
        /// <param name="pGeompoly"></param>
        /// <param name="pAV"></param>
        public void DrawGeompoly(IGeometry pGeompoly, IActiveView pAV)
        {
            if ((pGeompoly == null) || (pAV == null))
            {
                return;
            }
            //Takes an IGeometry and IActiveView
            //in the ActiveView's BasicGraphicsLayer
            //填充样式
            ISimpleFillSymbol pSFillSym;
            //文本样式
            ITextSymbol pTextSymbol;
            //填充颜色
            IRgbColor pFillRGB;
            //文本颜色
            IRgbColor pTextRGB;
            //多边形
            IPolygon pPolygon = pGeompoly as IPolygon;
            //多边形区域
            IArea pArea = pPolygon as IArea;
            //多边形中心点
            IPoint pTextPoint = pArea.Centroid;
            //多边形面积
            double dArea = Math.Round(Math.Abs(pArea.Area),2);
            //格式化
            string strArea =  string.Format("{0:N}", dArea);
            strArea = strArea + " 平方米";
           
           
            //Create a new RGBColor
            pFillRGB = new RgbColorClass();

            pFillRGB.Red = 110;
            pFillRGB.Green = 40;
            pFillRGB.Blue = 255;

            //Create a new RGBColor
            pTextRGB = new RgbColorClass();

            pTextRGB.Red = 60;
            pTextRGB.Green = 120;
            pTextRGB.Blue = 230;
           
   
            //Create a new SimpleFillSymbol and set its Color and Style
            pSFillSym = new SimpleFillSymbolClass();
            pSFillSym.Color = pFillRGB;
            pSFillSym.Style = esriSimpleFillStyle.esriSFSSolid;

            //Text Symbol
            pTextSymbol = new ESRI.ArcGIS.Display.TextSymbolClass();
            pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
            pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
            pTextSymbol.Size = 16;
            pTextSymbol.Color = pTextRGB;
            //pSymbol = pTextSymbol as ISymbol;
            //pSymbol.ROP2 = esriRasterOpCode.esriROPBlack;
            pTextSymbol.Text = strArea;

            pAV.ScreenDisplay.StartDrawing(pAV.ScreenDisplay.hDC, -1);

            //Use existing symbols and draw existing text and Polygon
            pAV.ScreenDisplay.SetSymbol(pSFillSym as ISymbol);
            pAV.ScreenDisplay.DrawPolygon(pGeompoly as IPolygon);

            pActiveView.ScreenDisplay.SetSymbol(pTextSymbol as ISymbol);
            pActiveView.ScreenDisplay.DrawText(pTextPoint, pTextSymbol.Text);

            pAV.ScreenDisplay.FinishDrawing();

        }

        #endregion
    }
}

GisTool4.0说明: 一、功能说明: MAPGIS6.5实用工具,集成若干MAPGIS6.5不具有的实用功能,简单易用。 本软件有以下特色功能: 1、精确制图功能(类似于AutoCAD)。画线、移动、复制图元时,都可以输入距离和角度,还可以捕捉端点、垂足等,F2为正交开关。 2、支持鼠标滚轮窗口缩放操作。向前滚动图形放大,向后滚动图形缩小,按下滚轮图形平移。 3、格式刷功能。点、线、区都可以运用格式刷进行修改和编辑。 4、快速制表功能。利用画水平线、竖直线以及捕足功能,输入距离移动、复制、拉伸线条功能,可以快速绘制各种表格。 5、多种测量功能。测量面积不需要造区,且有多种简单快速的方法,带图上面积与实际面积转换的功能。可以直接测量线图元的方位角。 6、线段拉伸功能。能够将线图元进行拉伸操作,所有选中的线节点将同时拉伸,同时可以输入距离和角度。 7、属性编辑功能。采用电子表格的方式对图元属性进编辑,与excel、acsses能够直接互相复制、粘贴,并且能够实现图形联动、属性联动的操作。 8、条件删除图元功能。可以根据图元ID能及图元属性有条件地对图元批量删除,还可以自动删除重叠图元。 9、整图栽剪功能。不需要生成单独的栽剪框文件,只要选择工程文件中任一条封闭的线就会自动对工程中的所有可见文件进行栽剪,栽剪后的文件自动保存在新建的目录中,每次栽剪都会生成一个新的目录,栽剪后的文件名与原文件名一致。 10、CAD转MapGis。本功能可以将AutoCAD格式的图形文件转换成MapGis格式的图形文件,能将CAD中的充填图案直接转换成MapGis中的区图元,而且能将CAD中的内部块、多行文本直接转出,不需要在CAD中分解。完全按照CAD中的图层分层转出所有可见图元,颜色、线型自动转换,不需要对照表,所有操作全自动,速度快,是目前比较完美的转换程序。可打开安装目录中的 CADdata.dxf 文件试用。 11、Excel转MapGis。本功能可以将 Microsoft Office Excel 电子表格文件中的各种表格直接转换成MapGis格式的点、线、面文件。可打开安装目录中的 bookdata.xls 文件试用。 12、自动绘制钻孔柱状图。本功能可以将保存在 Microsoft Office Excel 电子表格文件中的钻孔数据绘制成钻孔柱状图,数据输入格式请参考软件安装目录中的 zkdata.xls,也可打开此文件试用。 13、自动绘等值线、等高线。将测量点数据录入到文本文件或电子表格中,然后打开点数据文件便可自动绘制等值线、等高线。 14、等值线、等高线加密。在绘制等值线、等高线时,可以先画计曲线,然后利用此功能在计曲线之间自动生成首曲线,可节省大量的绘图时间。 15、坐标转换功能。经纬度坐标、六度带坐标、三度带坐标都可以批量相互转换。 16、自动标注功能。等高线、等值线其值可以根据其线的方向自动调整角度标注。 17、坐标成图功能。可以根据坐标及比例尺生成点、生成线,可以在图上采集实际坐标,批量导入文本注释等。 18、图例排列功能。输入指定的间距,点或图例都可以进行横向、纵向的等距离自动排列。 19、显示顺序功能。点、线、区都可以调整其显示顺序,即图元置顶、图元置底。 20、常用注释功能。可以将常用的文本注释、子图等事先设置好,使用时直接从工具栏中调出。 21、图元搜索功能。可以根据图元的属性、颜色、注释、子图号在图面上将符合条件的图元逐个查找出来。 22、属性提取功能。输入属性提取条件,能够将点、线、区中的符合条件的图元提取到新的文件中。 23、储量计算功能。用来计算分段平均品位、剖面面积、体积公式判别、块段体积、单矿石类型体积等。 24、线头沿边处理。所有线头自动靠近线上(端点自动落到线上,用于拓朴前期处理)。 25、自动节点平差。周围线头自动相聚于一点。(端点自动相聚于一点,用于拓朴前期处理)。 26、编辑属性结构。用电子表格的方式编辑属性结构,整个文件的属性结构可以任意复制和粘贴。 注:拉框选点时,从左到右拉框,需要包住整个点才能选中;从右到左拉框,只要框压住点的任何部位都可选中(与AutoCAD类似)。 二、安装说明: 1、安装前,请先关闭XP的数据执行保护功能(我的电脑→右键→属性→高级→启动和故障恢复→设置→编辑→optin改为alwaysoff→保存→重启电脑),并重新启动计算机。 2、安装MapGis65,需要原版光盘提供的安装程序,版本号为021010,日期是2002-10-25,其它版本的可能不太好用。 3、先
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值