ArcEngine面积测量实现_第1页
ArcEngine面积测量实现_第2页
ArcEngine面积测量实现_第3页
ArcEngine面积测量实现_第4页
ArcEngine面积测量实现_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、ArcEngine 距离测量和面积测量实现上一篇 / 下一篇  2010-08-13 17:08:13 / 个人分类:ArcEngine 查看( 171 ) / 评论( 0 ) / 评分( 0 / 0 ) 本文来自CSDN博客,转载请标明出处:觉得这个自定义ITool实现的很完整,所以就借鉴过来了。面积测量中最主要的接口就是INewPolygonFeedback。下面就是AreaMeasure.cs的全部内容,这是将实现和调用分开的。/自定义画多边形,测面积ToolbarControl.AddItem(new AreaMeasure(), -1, -1, true, 0, 

2、               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.System

3、UI;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>&#

4、160;   / 测量距离功能    / </summary>    public class AreaMeasure : ICommand, ITool            #region COM Registration Function(s)        ComRegisterFunction()  

5、60;     ComVisible(false)        static void RegisterFunction(Type registerType)                    / Required for ArcGIS Component Category Registrar supp

6、ort            ArcGISCategoryRegistration(registerType);            /            / TODO: Add any COM registration code here  

7、          /                ComUnregisterFunction()        ComVisible(false)        static void UnregisterFunction(T

8、ype registerType)                    / Required for ArcGIS Component Category Registrar support            ArcGISCategoryUnregistration(registerType); 

9、;           /            / TODO: Add any COM unregistration code here            /          

10、60;     #region ArcGIS Component Category Registrar generated code        / <summary>        / Required method for ArcGIS Component Category registration -        / Do n

11、ot modify the contents of this method with the code editor.        / </summary>        private static void ArcGISCategoryRegistration(Type registerType)             

12、;       string regKey = string.Format("HKEY_CLASSES_ROOTCLSID0", registerType.GUID);            ControlsCommands.Register(regKey);             &#

13、160;  / <summary>        / Required method for ArcGIS Component Category unregistration -        / Do not modify the contents of this method with the code editor.        / </summary

14、>        private static void ArcGISCategoryUnregistration(Type registerType)                    string regKey = string.Format("HKEY_CLASSES_ROOTCLSID0", registerT

15、ype.GUID);            ControlsCommands.Unregister(regKey);                #endregion        #endregion      &#

16、160; DllImport("gdi32.dll")        static extern bool DeleteObject(IntPtr hObject);/删除对象        private System.Drawing.Bitmap m_bitmap;/工具显示图标        private IntPtr m_hBitmap;/用于表示指针或者句

17、柄的平台特殊类型        private IHookHelper m_pHookHelper;/句柄        private System.Windows.Forms.Cursor m_areaMeasureCur;/光标        private bool m_enabled;/是否可用       

18、 private bool m_check;/是否选中        private bool m_isMouseDown;/鼠标是否按下        private INewPolygonFeedback m_pNewPolyFeedback;/INewPolygonFeedback,控制新的多边形显示反馈        private IActiveView pActiveView

19、;/视图        / <summary>        /构造函数         / </summary>        public AreaMeasure()           &#

20、160;        /Load resources            string res = GetType().Assembly.GetManifestResourceNames();            if (res.GetLength(0) > 0)   

21、;                         m_bitmap = new System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream(GetType(), "AreaMeasure.bmp");      &

22、#160;         if (m_bitmap != null)                                    m_bitmap.MakeTransp

23、arent(m_bitmap.GetPixel(1, 1);                    m_hBitmap = m_bitmap.GetHbitmap();                     

24、                   m_pHookHelper = new HookHelperClass();                / <summary>        / 释构函数 

25、       / </summary>        AreaMeasure()                    if (m_hBitmap.ToInt32() != 0)        &#

26、160;       DeleteObject(m_hBitmap);            m_pHookHelper = null;            m_check = false;          

27、0; /m_measureCur = null;                #region ICommand Members        /点击        public void OnClick()          &

28、#160;             /消息 属性        public string Message                    get       &#

29、160;                    return "测量多边形面积"                            /图标 属性&

30、#160;       public int Bitmap                    get                      &

31、#160;     return m_hBitmap.ToInt32();                            / <summary>        / 创建工具命令   

32、0;    / </summary>        / <param name="hook">hook句柄</param>        public void OnCreate(object hook)               

33、     m_pHookHelper.Hook = hook;            m_enabled = true;            m_check = false;            m_areaMeasureCu

34、r = new System.Windows.Forms.Cursor(GetType().Assembly.GetManifestResourceStream(GetType(), "Area Measure.cur");                /标题 属性        public string Caption   

35、0;                get                            return "测面积"     

36、;                       /提示 属性        public string Tooltip                  

37、60; get                            return "测面积"                    

38、60;       /HelpContextID 属性        public int HelpContextID                    get          

39、60;                 / TODO:  Add AreaMeasure.HelpContextID getter implementation                return 0;      

40、0;                     /工具名 属性        public string Name                    get 

41、                           return "Commands/AreaMeasure"                   

42、         /是否选中 属性        public bool Checked                    get             

43、               return m_check;                            /是否可用 属性      

44、60; public bool Enabled                    get                            return

45、 m_enabled;                            /帮组文件 属性        public string HelpFile           &#

46、160;        get                            / TODO:  Add AreaMeasure.HelpFile getter implementation     &#

47、160;          return null;                            /种类 属性        public string Category 

48、;                   get                            return "Commands/AreaMeasure&

49、quot;                            #endregion        #region ITool Members        / <summary> &#

50、160;      / 鼠标按下事件        / </summary>        / <param name="button">button按钮</param>        / <param name="shift">shift键</

51、param>        / <param name="x">屏幕X坐标</param>        / <param name="y">屏幕Y坐标</param>        public void OnMouseDown(int button, int shift, int x, in

52、t y)                    /Create a point in map coordinates            /IActiveView pActiveView = (IActiveView)m_pHookHelper.FocusMap;   

53、0;        m_isMouseDown = true;            if (pActiveView = null)                         

54、;   /Create a point in map coordinates                pActiveView = (IActiveView)m_pHookHelper.FocusMap;                   &#

55、160;    /点            IPoint pPoint;            pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);         

56、0;    /Check that user is not using an existing feedback            if( m_pNewPolyFeedback = null )            / Create a symbol (and color) to use for the Feedback  

57、;          /this is optional - a default symbol is used if none is given            ISimpleLineSymbol pSLineSymFeed;            /颜色  &#

58、160;         IRgbColor pRGB;                m_pNewPolyFeedback = new  NewPolygonFeedbackClass();            /Get the new Feedback&

59、#39;s symbol by reference            pSLineSymFeed = m_pNewPolyFeedback.Symbol as ISimpleLineSymbol;                pRGB = new  RgbColorClass();    &#

60、160;       /Make a color            pRGB.Red = 140;            pRGB.Green = 140;            pRGB.Blue = 2

61、55;                /Setup the symbol with color and style            pSLineSymFeed.Color = pRGB;            pSLineSymFee

62、d.Style= esriSimpleLineStyle.esriSLSDot;            /Set the new Feedback's Display and StartPoint            m_pNewPolyFeedback.Display = pActiveView.ScreenDisplay;   

63、60;        m_pNewPolyFeedback.Start(pPoint);                        else           /Otherwise use the cur

64、rent mouse location to add a vertex to the current feedback                m_pNewPolyFeedback.AddPoint(pPoint);                    

65、0;       / <summary>        / 鼠标移动事件        / </summary>        / <param name="button">button按钮</param>    

66、0;   / <param name="shift">shift键</param>        / <param name="x">屏幕X坐标</param>        / <param name="y">屏幕Y坐标</param>      

67、;  public void OnMouseMove(int button, int shift, int x, int y)                    if (!m_isMouseDown) return;            /Check if the user is curren

68、tly using the feedback            if( m_pNewPolyFeedback!= null)                            /Move the Feedback to t

69、he current mouse location                if (pActiveView = null)                           

70、0;        /Create a point in map coordinates                    pActiveView = (IActiveView)m_pHookHelper.FocusMap;         &#

71、160;                      /坐标系中的点                IPoint pPoint;          &#

72、160;     pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);                m_pNewPolyFeedback.MoveTo(pPoint);             

73、;               / <summary>        / 鼠标放开事件        / </summary>        / <param name="button">button按钮

74、</param>        / <param name="shift">shift键</param>        / <param name="x">屏幕X坐标</param>        / <param name="y">屏幕Y坐标</pa

75、ram>        public void OnMouseUp(int button, int shift, int x, int y)                    / TODO:  Add AreaMeasure.OnMouseUp implementation    

76、0;           / <summary>        / 键盘按下事件        / </summary>        / <param name="keyCode">键编码</param>  &

77、#160;     / <param name="shift">shift键</param>        public void OnKeyDown(int keyCode, int shift)                    if (m_isMouseD

78、own)                            if (keyCode = 27)                     

79、               m_isMouseDown = false;                    m_pNewPolyFeedback = null;        

80、0;           m_pHookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);                         &#

81、160;                  / <summary>        / 键盘放开事件        / </summary>        / <param name="keyCode&

82、quot;>键编码</param>        / <param name="shift">shift键</param>        public void OnKeyUp(int keyCode, int shift)               &#

83、160;    if (m_isMouseDown)                            if (keyCode = 27)              

84、                      m_isMouseDown = false;                    m_pNewPolyFeedback = null;  

85、60;                 m_pHookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);                   &

86、#160;                        / <summary>        / 光标        / </summary>       

87、; public int Cursor                    get                            return m_a

88、reaMeasureCur.Handle.ToInt32();                            / <summary>        / 上下文菜单事件        / &l

89、t;/summary>        / <param name="x">屏幕X坐标</param>        / <param name="y">屏幕Y坐标</param>        / <returns>bool</returns>  &#

90、160;     public bool OnContextMenu(int x, int y)                    / TODO:  Add AreaMeasure.OnContextMenu implementation          

91、0; return false;                / <summary>        / 解除事件        / </summary>        / <returns>bool</re

92、turns>        public bool Deactivate()                    return true;                / <summary>

93、;        / 刷新        / </summary>        / <param name="hdc">hdc</param>        public void Refresh(int hdc)    

94、                /Get a reference to the ActiveView             if (m_pHookHelper != null)               &

95、#160;            pActiveView = (IActiveView)m_pHookHelper.FocusMap;                            / <summary> &#

96、160;      / 双击事件        / </summary>        public void OnDblClick()                    /图形   

97、         IGeometry pGeompoly = null;            /Get the geometry (Polygon) returned from the feedback            if (m_pNewPolyFeedback != null) 

98、;                           pGeompoly = m_pNewPolyFeedback.Stop();                   

99、     /' If it is valid then draw a Geompoly on the ActiveView using the            / DrawGeompoly procedure            if (pGeompoly != null)    &

100、#160;                       /AddCreateElement(pGeompoly, pActiveView);                if (pGeompoly.GeometryType.Equals(

101、esriGeometryType.esriGeometryPolygon)                                    DrawGeompoly(pGeompoly, pActiveView);   &#

102、160;                            /pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);          &

103、#160;             /' Set the feedback to nothing for the next use            m_pNewPolyFeedback = null;              

104、0; / <summary>        / 画多边形        / </summary>        / <param name="pGeompoly"></param>        / <param name="pAV&q

105、uot;></param>        public void DrawGeompoly(IGeometry pGeompoly, IActiveView pAV)                    if (pGeompoly = null) | (pAV = null)    

106、60;                       return;                        /Takes an IGeometry and IAct

107、iveView             /in the ActiveView's BasicGraphicsLayer            /填充样式            ISimpleFillSymbol pSFillSym;  

108、60;         /文本样式            ITextSymbol pTextSymbol;            /填充颜色            IRgbColor pFi

109、llRGB;            /文本颜色            IRgbColor pTextRGB;            /多边形           

110、; IPolygon pPolygon = pGeompoly as IPolygon;            /多边形区域            IArea pArea = pPolygon as IArea;            /多边形中心点 

111、0;          IPoint pTextPoint = pArea.Centroid;            /多边形面积            double dArea = Math.Round(Math.Abs(pArea.Area),2);            /格式化   &

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论