ArcEngine 面积测量实现
更新时间:2023-09-10 07:00:01 阅读量: 教育文库 文档下载
- arcengine推荐度:
- 相关推荐
ArcEngine 距离测量和面积测量实现
上一篇 / 下一篇 2010-08-13 17:08:13 / 个人分类:ArcEngine
查看( 171 ) / 评论( 0 ) / 评分( 0 / 0 )
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/chyocean/archive/2008/04/28/2337310.aspx 觉得这个自定义ITool实现的很完整,所以就借鉴过来了。 面积测量中最主要的接口就是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(\ ///
///
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 ///
/// Required method for ArcGIS Component Category registration - /// Do not modify the contents of this method with the code editor. ///
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format(\ ControlsCommands.Register(regKey); }
///
/// Required method for ArcGIS Component Category unregistration - /// Do not modify the contents of this method with the code editor. ///
private static void ArcGISCategoryUnregistration(Type registerType) {
string regKey = string.Format(\ ControlsCommands.Unregister(regKey); }
#endregion #endregion
[DllImport(\
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;//视图 ///
/// public AreaMeasure() {
//Load resources
string[] res = GetType().Assembly.GetManifestResourceNames(); if (res.GetLength(0) > 0) {
m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream(GetType(), \ if (m_bitmap != null) {
m_bitmap.MakeTransparent(m_bitmap.GetPixel(1, 1)); m_hBitmap = m_bitmap.GetHbitmap(); } }
m_pHookHelper = new HookHelperClass(); }
///
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(); } }
///
/// public void OnCreate(object hook) {
m_pHookHelper.Hook = hook; m_enabled = true; m_check = false;
/// /// ///
public void OnMouseUp(int button, int shift, int x, int y) {
// TODO: Add AreaMeasure.OnMouseUp implementation }
///
/// /// 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); } } }
///
/// /// 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); } } }
///
return m_areaMeasureCur.Handle.ToInt32(); } }
///
/// /// ///
public bool OnContextMenu(int x, int y) {
// TODO: Add AreaMeasure.OnContextMenu implementation return false; }
///
///
return true; }
///
///
//Get a reference to the ActiveView if (m_pHookHelper != null) {
pActiveView = (IActiveView)m_pHookHelper.FocusMap; } }
///
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; }
///
///
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(\ 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 } }
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 } }
正在阅读:
ArcEngine 面积测量实现09-10
《汽车专业英语》冷却系统教学设计12-15
社区防溺水活动实施方案范文5篇04-03
《改革政府》奥斯本读书笔记04-25
高中生物竞赛辅导05-14
风景园林概论期中前总结04-29
高考物理真题分类汇编力学实验03-10
索达吉堪布:大乘佛教对治抑郁症的五种方法04-21
机械设计作业习题04-04
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- ArcEngine
- 测量
- 面积
- 实现
- 2018-2024年中国计算机行业市场发展现状及投资前景预测报告
- 高三地理时间计算
- 过桥问题
- 南大网校201610月份离散数学第一次作业
- 三年级数上册14周周周清
- 中央财经大学硕士研究生招生目录和考试参考书目
- 特种作业人员安全教育培训记录
- 单回路控制系统的工程整定
- 企业文化在线作业4
- 数码相机摄影基本常识和教程
- 情景式默写
- 最高院案例与观点 合同债权篇
- 铁磁材料的磁滞回线和基本磁化曲线
- 最新最新初三物理中考模拟试题(5、6) - 图文
- 1978年海员培训、发证和值班标准国际公约概述
- 隧道管理站2015年度工作总结 - 图文
- 城市管理学简答论述
- 应用文写作教学大纲
- 八年级物理下册11.1功导学案无答案新版新人教版
- Windows7系统手动优化