Copyright©2004ESRI.Allrightsreserved.DevelopingApplicationswithArcGISEngineArcGISEngine应用开发基础2-2DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.课2目录ArcObjects库ArcObjectsEngineAPIsEngine应用程序开发许可2-3DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ArcGIS体系结构共享ArcObjectsEngine包括了ArcObjects的核心功能ArcGISDesktopArcGISEngineArcGISServer2-4DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ArcGIS库共享AO库有些库不可以共享如:esriArcMapUI识别属于不同产品的库理解库的从属关系开发工具ArcGISDeveloperHelpESRIAutomaticReferenceadd-in2-5DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ArcGISEngine类库体系结构2-6DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ArcObjects由ArcObjects组成的ArcObjects是C++对象通过不同的APIs来访问本地接口是COM2-7DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.Component(Map.dll)ClientArcMapCOM软件模块之间连接的协议跨语言二进制规范使用接口和组件来设计模型客户调用服务器并等待服务器的响应所有的通信都是通过接口来进行2-8DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ArcObjects和COMAPI所有ArcObjectsCOM类型都在类型库中定义类型库是二进制的文件,描述:Classes:CLSIDs和ProgIDsInterfaces:IIDsConstants和enumerations接口的实现在DLL和EXE文件开发者工具ArcGISDeveloperHelp(VB6或VC++)LibraryLocator,EOBrowserandOleView*ArcObjectsC++*.dllfiles*COMTypeLibraries*.olbfiles2-9DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.COMclassesCOM类实现接口所有类都实现Iunknown接口管理对象生命周期成员:QueryInterface,AddRef和ReleaseCoclasses是可创建的PublicSubmapName()DimpMapAsIMap'YoucancreateanewinstanceofacoclassSetpMap=NewMapEndSubPublicSubmapName()DimpMapAsIMap'YoucancreateanewinstanceofacoclassSetpMap=NewMapEndSubIUnknown2-10DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.COM接口定义了函数和属性的一个逻辑组从IUnknown(默认)继承ArcObjects支持自定义interfaces通过QueryInterface(QI)来访问接口PublicSubmapName()DimpMapAsIMapSetpMap=NewMap'YouhaveaccesstopropertiesandmethodsofIMapthroughpMapMsgBoxpMap.NameEndSubPublicSubmapName()DimpMapAsIMapSetpMap=NewMap'YouhaveaccesstopropertiesandmethodsofIMapthroughpMapMsgBoxpMap.NameEndSub2-11DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.COM出接口提供了一种激活客户端事件的途径连接到一个对象并接收它的出接口在ArcObjects中可获得多级别的事件例如:documentloadevents,mapdrawingevents,editingevents,…PrivateWithEventsMxDocEventsAsMxDocumentPrivateSubsetNewValues()...SetMxDocEvents=pMxDoc'NowcanaccesseventsEndSubPrivateFunctionMxDocEvents_NewDocument()AsBooleanMsgBoxNewArcMapdocumentEndFunctionPrivateWithEventsMxDocEventsAsMxDocumentPrivateSubsetNewValues()...SetMxDocEvents=pMxDoc'NowcanaccesseventsEndSubPrivateFunctionMxDocEvents_NewDocument()AsBooleanMsgBoxNewArcMapdocumentEndFunction2-12DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.其它类型库包括了所有COM类型每一个类型有一个全球唯一标识符(GUID)CLSID,IID,Progid,…esriSystem.UID表示对象的GUID(例子代码)指定CLSID或ProgID(ProjectName.ClassName)DimuAsNewUIDu.Value={4FDD8858-DF31-4D6B-8679-1FED633262DA}'CLSIDofControlsMapRotateToolDimuAsNewUIDu.Value=esriControlCommands.ControlsMapRotateTool“'ProgIDofControlsMapRotateToolDimuAsNewUIDu.Value={4FDD8858-DF31-4D6B-8679-1FED633262DA}'CLSIDofControlsMapRotateToolDimuAsNewUIDu.Value=esriControlCommands.ControlsMapRotateTool“'ProgIDofControlsMapRotateToolDimcommandAsICommandcommand=AxToolbarControl1.CommandPool.FindByUID(u)IfNotcommandIsNothingThenMsgBox(command.Name)EndIfDimcommandAsICommandcommand=AxToolbarControl1.CommandPool.FindByUID(u)IfNotcommandIsNothingThenMsgBox(command.Name)EndIf2-13DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ArcObjects和.NETAPI所有ArcObjects类型在.NETassemblies(汇编集)中定义PrimaryInteropAssemblies(主互操作程序集)在导入COM类库后产生PIA暴露所有的类,接口和常量,作为.NET托管类需要.NETFramework1.1开发工具ArcGISDeveloperHelp(.NET)ILDASM.exeArcObjectsC++COMTypeLibraries.NETAssembliesInterop2-14DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved.ArcGIS.NETassemblies和namespaces所有.NET工程必须引用ESRIassembliesExample:ESRI.ArcGIS.Carto.dll导入命名空间来访问ArcObjects.NET类型Example:ESRI.ArcGIS.CartoAssemblies有从属...ImportsESRI.ArcGIS.CatalogUIImportsESRI.ArcGIS.ArcMapUIImportsESRI.ArcGIS.Framework......ImportsESRI.ArcGIS.CatalogUIImportsESRI.ArcGIS.ArcMapUIImportsESRI.ArcGIS.Framework...2-15DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved..NET类.NET托管类代表ArcObjects对象有两种类型COMobjectName”Class”:在类中实现所有的接口和成员函数COMobjectName:代表真正的ArcObjects对象创建类实例化真正的COM对象DimmapasMapClassmap=NewMapClass()map.Extent=envelopeDimmapasMapClassmap=NewMapClass()map.Extent=envelope2-16DevelopingApplicationswithArcGISEngineCopyright©2004ESRI.Allrightsreserved..NET接口.NET接口代表ArcObjects接口QueryInterface的不同技巧Implicitcasting(常用)Explicitcasting(语法复杂且易丢失数据,不常用)VB.NET中使用TypeOf以避免处理ImplicitCasting带来的InvalidCastException异常(C#中通常使用as符)geometry=point‘Implicitcastgeometry=CType(point,IGeometry)‘Explicitcastgeometry=point‘Implicitcastgeometry=CType(point,IGeometry)‘ExplicitcastDimpointAsNewPointClassDimgeometryAsIGeometryIf(TypeOfpointIsIGeometry)Thengeometry=pointEndIfDimpoint