ArcEngine面積測(cè)量實(shí)現(xiàn)_第1頁(yè)
ArcEngine面積測(cè)量實(shí)現(xiàn)_第2頁(yè)
ArcEngine面積測(cè)量實(shí)現(xiàn)_第3頁(yè)
ArcEngine面積測(cè)量實(shí)現(xiàn)_第4頁(yè)
ArcEngine面積測(cè)量實(shí)現(xiàn)_第5頁(yè)
已閱讀5頁(yè),還剩12頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、ArcEngine 距離測(cè)量和面積測(cè)量實(shí)現(xiàn)上一篇 / 下一篇  2010-08-13 17:08:13 / 個(gè)人分類:ArcEngine 查看( 171 ) / 評(píng)論( 0 ) / 評(píng)分( 0 / 0 ) 本文來(lái)自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:覺(jué)得這個(gè)自定義ITool實(shí)現(xiàn)的很完整,所以就借鑒過(guò)來(lái)了。面積測(cè)量中最主要的接口就是INewPolygonFeedback。下面就是AreaMeasure.cs的全部?jī)?nèi)容,這是將實(shí)現(xiàn)和調(diào)用分開(kāi)的。/自定義畫(huà)多邊形,測(cè)面積ToolbarControl.AddItem(new AreaMeasure(), -1, -1, true, 0, 

2、               esriCommandStyles.esriCommandStyleIconOnly);添加面積測(cè)量的功能。AreaMeasure.cs的實(shí)現(xiàn)如下: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;   / 測(cè)量距離功能    / </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);/刪除對(duì)象        private System.Drawing.Bitmap m_bitmap;/工具顯示圖標(biāo)        private IntPtr m_hBitmap;/用于表示指針或者句

17、柄的平臺(tái)特殊類型        private IHookHelper m_pHookHelper;/句柄        private System.Windows.Forms.Cursor m_areaMeasureCur;/光標(biāo)        private bool m_enabled;/是否可用       

18、 private bool m_check;/是否選中        private bool m_isMouseDown;/鼠標(biāo)是否按下        private INewPolygonFeedback m_pNewPolyFeedback;/INewPolygonFeedback,控制新的多邊形顯示反饋        private IActiveView pActiveView

19、;/視圖        / <summary>        /構(gòu)造函數(shù)         / </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>        / 釋構(gòu)函數(shù) 

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        /點(diǎn)擊        public void OnClick()          &

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

29、160;                    return "測(cè)量多邊形面積"                            /圖標(biāo) 屬性&

30、#160;       public int Bitmap                    get                      &

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

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");                /標(biāo)題 屬性        public string Caption   

35、0;                get                            return "測(cè)面積"     

36、;                       /提示 屬性        public string Tooltip                  

37、60; get                            return "測(cè)面積"                    

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;      / 鼠標(biāo)按下事件        / </summary>        / <param name="button">button按鈕</param>        / <param name="shift">shift鍵</

51、param>        / <param name="x">屏幕X坐標(biāo)</param>        / <param name="y">屏幕Y坐標(biāo)</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;    /點(diǎn)            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>        / 鼠標(biāo)移動(dòng)事件        / </summary>        / <param name="button">button按鈕</param>    

66、0;   / <param name="shift">shift鍵</param>        / <param name="x">屏幕X坐標(biāo)</param>        / <param name="y">屏幕Y坐標(biāo)</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;                      /坐標(biāo)系中的點(diǎn)                IPoint pPoint;          &#

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

73、;               / <summary>        / 鼠標(biāo)放開(kāi)事件        / </summary>        / <param name="button">button按鈕

74、</param>        / <param name="shift">shift鍵</param>        / <param name="x">屏幕X坐標(biāo)</param>        / <param name="y">屏幕Y坐標(biāo)</pa

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

76、0;           / <summary>        / 鍵盤(pán)按下事件        / </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>        / 鍵盤(pán)放開(kāi)事件        / </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>        / 光標(biāo)        / </summary>       

87、; public int Cursor                    get                            return m_a

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

89、t;/summary>        / <param name="x">屏幕X坐標(biāo)</param>        / <param name="y">屏幕Y坐標(biāo)</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>        / 畫(huà)多邊形        / </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;            /多邊形區(qū)域            IArea pArea = pPolygon as IArea;            /多邊形中心點(diǎn) 

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

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論