版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、ArcEngine 距離測量和面積測量實現(xiàn)上一篇 / 下一篇 2010-08-13 17:08:13 / 個人分類:ArcEngine 查看( 171 ) / 評論( 0 ) / 評分( 0 / 0 ) 本文來自CSDN博客,轉(zhuǎn)載請標明出處:覺得這個自定義ITool實現(xiàn)的很完整,所以就借鑒過來了。面積測量中最主要的接口就是INewPolygonFeedback。下面就是AreaMeasure.cs的全部內(nèi)容,這是將實現(xiàn)和調(diào)用分開的。/自定義畫多邊形,測面積ToolbarControl.AddItem(new AreaMeasure(), -1, -1, true, 0,
2、 esriCommandStyles.esriCommandStyleIconOnly);添加面積測量的功能。AreaMeasure.cs的實現(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; / 測量距離功能 / </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> /構(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 /點擊 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> / 創(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"); /標題 屬性 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; /多邊形區(qū)域 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年安全生產(chǎn)責(zé)任基金抵押合同
- 2025年在線醫(yī)療健康平臺用戶注冊協(xié)議
- 2025年保密協(xié)議信息轉(zhuǎn)換書
- 2025年代理渠道合作協(xié)議
- 2025年旅游項目管理標準協(xié)議
- 《英語選修課》課件
- 2024 浙江公務(wù)員考試行測試題(A 類)
- 2025版美容護膚中心場地租賃合同范本4篇
- 2025版基礎(chǔ)設(shè)施建設(shè)工程施工合同終止補充協(xié)議2篇
- 買賣墓地合同(2024版)
- 2025年度房地產(chǎn)權(quán)證辦理委托代理合同典范3篇
- 職業(yè)衛(wèi)生培訓(xùn)課件
- 柴油墊資合同模板
- 湖北省五市州2023-2024學(xué)年高一下學(xué)期期末聯(lián)考數(shù)學(xué)試題
- 城市作戰(zhàn)案例研究報告
- 【正版授權(quán)】 ISO 12803:1997 EN Representative sampling of plutonium nitrate solutions for determination of plutonium concentration
- 道德經(jīng)全文及注釋
- 2024中考考前地理沖刺卷及答案(含答題卡)
- 多子女贍養(yǎng)老人協(xié)議書范文
- 彩票市場銷售計劃書
- 骨科抗菌藥物應(yīng)用分析報告
評論
0/150
提交評論