ArcObjects基础

来源:互联网 发布:tensorflow查看变量值 编辑:程序博客网 时间:2024/05/25 08:15

AO 基础

基本资料

1、许可绑定

RuntimeManager.Bind(ProductCode.Engine)

2、参考资料

  • ArcObjects SDK 10 Microsoft .NET Framework
  • http://resources.arcgis.com/
  • http://help.arcgis.com/zh-cn/arcgisdesktop/10.0/help/
  • ArcGIS 开发工具包中的文档,包括ArcGIS开发帮助、组件帮助、对象模- 型图和示例

3、查询接口

由接口的整体介绍在去查询接口文档学习较方便,下面是接口的整体介绍方便对AO有一个整体的认识。防止盲人摸象。

接口

1 IApplication接口 (ESRI.ArcGIS.Framework)

IApplication定义了ArcGIS中所有桌面应用程序的一般功能。

2 IMxApplication2接口 (ESRI.ArcGIS.ArcMapUI)

这是ArcMap程序特有的接口,用于管理SelectionEnvironment、Display、Paper和Printer等对象。

3 IWindowPosition接口 (ESRI.ArcGIS.Framework)

  • 任何有可视化窗体的类都实现了IWindowPosition接口,如DockableWindow、CommandBar和各种Application类。
  • 这个接口定义了窗体的尺寸和位置,如width和height确定了窗体的大小,而left和top规定了窗体的左上角距离屏幕的左上角之间的距离。
  • 这个接口还定义了一个属性state,它用于确定程序窗口的形式,如esriWSNormal(正常模式)、esriWSMaximize(最大化模式)、esriWSMinimize(最小化模式)和esriWSFloating(浮动模式)四种。

4 Document对象

应用程序一次只能有一个文档对象存在。不同的ArcGIS桌面应用程序,使用的文档对象也不一样

  • ArcMap:MxDocument
  • ArcCatalog:GxDocument
  • ArcScene:SxDocument

用户可以通过IApplication::Document来获取文档对象。

5 IMxDocument接口(ESRI.ArcGIS.ArcMapUI)

IMxDocument是MxDocument的默认接口,也是最主要的接口。该接口定义的方法如下:

public void UpdateContents ( )

刷新现在的内容视图。UpdateContents是捷径。连通现在的视图需要通过IMxDocument.CurrentContentsView。

m_application = hook as IApplication;IDocument document = m_application.Document;IMxDocument mapDocument = document  as IMxDocument;如果通过某种途径先获得了文档对象mapDocument(IMxDocument) 则IDocument document = mapDocument as IDocument;IApplication m_application = document.Parent; 

6 IDocumentDefaultSymbols接口

IDocumentDefaultSymbols接口是文档缺省符号设置接口,用于设置缺省颜色、符号。

7 IDocumentEvents接口

  • IDocumentEvents是MxDocument对象的一个外向事件接口,使用这个接口可以监听与地图文档对象有关的事件,如NewDocument事件,CloseDocument事件等。
  • IDocumentEvents和lDocumentEventsDisp非常相似,但是后者可以在VBA的编辑器中自动使用。使用VBA进行编程的时候,可以直接使用文档对象的一系列事件。IDocumentEventsDisp定义了诸如MapsChanged、CloseDocument等事件。

在C#环境下,可以通过以下步骤来监听文档事件:

1. 从应用获得document对象using ESRI.ArcGIS.Framework;…IApplication app = hook as IApplication;IDocument appDocument = app.Document2. 定义IDocumentEvents_Event variable. using ESRI.ArcGIS.Framework;using ESRI.ArcGIS.ArcMapUI;public class howToClass{  private IDocumentEvents_Event m_docEvents = null;    private void SetUpDocumentEvent( IDocument myDocument)  {    m_docEvents = myDocument as IDocumentEvents_Event;      …  }}3. 实现时间处理方法void OnNewDocument(){   ……….}4. 将NewDocument事件与方法绑定m_docEvents.NewDocument +=   new IDocumentEvents_NewDocumentEventHandler (OnNewDocument);

通过文档对象放大到范围

public void ZoomToLayer( IMxDocument mxDocument){          IMap map = mxDocument.FocusMap;          IActiveView activeView = (IActiveView)map;           IContentsView IContentsView = mxDocument.CurrentContentsView;                      ILayer layer = (ILayer)IContentsView.SelectedItem;           if (!(layer is ILayer))            {   return;   }           activeView.Extent = layer.AreaOfInterest;           activeView.Refresh();}

命令与命令条概述

ArcObjects提供了三类命令:
- 单击命令(简单命令,Command):仅实现ICommand接口。用户单击事件会导致对ICommand::OnClick方法的调用,并立即执行某种动作。
- 工具(Tool):实现了ICommand接口和ITool接口,工具的执行需要用户与地图显示进行交互。
- 工具控件:实现了ICommand接口和IToolControl接口,如ArcMap中标准工具条上显示比例尺的控件,与下拉列表框类似。

IHookHelper接口

为开发时需要使用MapControl, PageLayoutControl, ArcMap等工具和应用的开发者提供了连接手段。
Provides access to members needed when developing commands to work with the and custom controls and applications.

   IHookHelper m_hookHelper = new HookHelperClass();   m_hookHelper.Hook = this.axMapControl1.Object;