ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:1,003.47KB ,
资源ID:7888963      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7888963.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C++CLI调用ArcObjects.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C++CLI调用ArcObjects.docx

1、C+CLI调用ArcObjects1新建一个空的工程命名为AoWrapperDemo2 添加一个新项目,命名为AoWrapper右键项目-属性,添加ESRI.ArcGIS相关引用将配置类型改为动态链接库添加一个c+文件,命名为GeometryWrapper由于该类功能简单,没必要添加头文件using namespace System;using namespace System:Diagnostics;using namespace ESRI:ArcGIS:Geometry;using namespace ESRI:ArcGIS:esriSystem;using namespace ESRI:

2、ArcGIS;namespace AoWrapper public ref class GeometryWrapper public: GeometryWrapper() ESRI:ArcGIS:RuntimeManager:Bind(ProductCode:Engine); IAoInitialize pAoInitialize=gcnew AoInitializeClass(); pAoInitialize-Initialize(esriLicenseProductCode:esriLicenseProductCodeEngineGeoDB); GeometryWrapper() publ

3、ic: int line_test() IPoint ipPt1 =gcnew PointClass(); IPoint ipPt2 =gcnew PointClass(); ipPt1-PutCoords(1, 2); ipPt2-PutCoords(2, 3); ILine ipLine=gcnew LineClass(); Stopwatch watch=gcnew Stopwatch(); watch-Start(); for(long i=0;iPutCoords(ipPt1,ipPt2); /Console:WriteLine(i); watch-Stop(); Console:W

4、riteLine(watch-ElapsedMilliseconds); return 0; ;完成C+/CLI对ArcObjects的调用封装类库3 添加一个新项目,命名为NAoHelper,利用本地c+直接操作AO修改头文件stdafx.h,导入ArcObjects相关库/ stdafx.h : include file for standard system include files,/ or project specific include files that are used frequently, but/ are changed infrequently/#pragma on

5、ce#include targetver.h#define WIN32_LEAN_AND_MEAN / Exclude rarely-used stuff from Windows headers/ Windows Header Files:#include / TODO: reference additional headers your program requires here#pragma warning(push)#pragma warning(disable : 4192) /* Ignore warnings for types that are duplicated in wi

6、n32 header files */#pragma warning(disable : 4146) /* Ignore warnings for use of minus on unsigned types */#import C:Program Files (x86)ArcGISDesktop10.1comesriSystem.olb raw_interfaces_only, raw_native_types, no_namespace, named_guids, exclude(OLE_COLOR, OLE_HANDLE, VARTYPE)#import C:Program Files

7、(x86)ArcGISDesktop10.1comesriGeometry.olb raw_interfaces_only, raw_native_types, no_namespace, named_guids,exclude(OLE_COLOR)/ Load the ArcGISVersion library./ This code is commonly placed in the StdAfx.h header file.#import libid:6FCCEDE0-179D-4D12-B586-58C88D26CA78 raw_interfaces_only,no_implement

8、ation添加一个头文件NAoHelper.h修改后的头文件如下:#ifndef AOHELPER_H_#define AOHELPER_H_#ifdef NAOHELPER_EXPORTS#define DAPI _declspec(dllexport)#else#define DAPI _declspec(dllimport)#endif/导出这个类class DAPI AoHelperpublic: AoHelper(); AoHelper(); int line_test();private: int InitializeAo();#endif打开NAoHelper.cpp,修改后如下

9、:/ NAoHelper.cpp : Defines the exported functions for the DLL application./#include stdafx.h#include NAoHelper.hAoHelper:AoHelper() :CoInitialize(NULL); /不初始化也可以 /InitializeAo();AoHelper:AoHelper() :CoUninitialize();int AoHelper:InitializeAo() ArcGISVersionLib:IArcGISVersionPtr ipVer(_uuidof(ArcGISV

10、ersionLib:VersionManager); VARIANT_BOOL succeeded; if (FAILED(ipVer-LoadVersion(ArcGISVersionLib:esriArcGISDesktop , L10.1,&succeeded) return 0; IAoInitializePtr m_AoInit;/(CLSID_AoInitialize); m_AoInit.CreateInstance (CLSID_AoInitialize); esriLicenseStatus ls; HRESULT h= m_AoInit-Initialize(esriLic

11、enseProductCode:esriLicenseProductCodeEngineGeoDB ,&ls); return 0;int AoHelper:line_test() IPointPtr ipPt1(CLSID_Point); IPointPtr ipPt2(CLSID_Point); ipPt1-PutCoords(1, 2); ipPt2-PutCoords(2, 3); ILinePtr ipLine(CLSID_Line); for(long i = 0; i PutCoords(ipPt1,ipPt2); return 0;编译,完成本地c+调用AO封装类库4 添加新项

12、目,命名为NAoWrapper,利用C+/CLI对NAoHelper进行封装的库,以便于C#调用编辑包含文件(头文件)目录修改头文件NAoHelper.h/ NAoWrapper.h#pragma once#include NAoHelper.husing namespace System;namespace NAoWrapper public ref class RefAoWrapper / TODO: Add your methods for this class here. private: AoHelper *ao; public: int line_test(); RefAoWrap

13、per(); RefAoWrapper(); ;修改NAoWrapper.cpp/ This is the main DLL file.#include stdafx.h#include NAoWrapper.husing namespace System:Diagnostics;namespace NAoWrapper RefAoWrapper:RefAoWrapper() ao=new AoHelper(); RefAoWrapper:RefAoWrapper() delete ao; int RefAoWrapper :line_test() Stopwatch watch=gcnew

14、Stopwatch(); watch-Start(); ao-line_test(); watch-Stop(); Console:WriteLine(watch-ElapsedMilliseconds); return 0; 5 添加新项目,命名为CSharpAoHeleper,C#直接调用ArcObjects添加ESRI.ArcGIS.相关引用将Class1.cs重命名为CSharpAoHeleper,代码如下using System;using System.Collections.Generic;using System.Linq;using System.Text;using ESR

15、I.ArcGIS.Geometry;using System.Diagnostics;namespace CSharpAoHeleper public class CSharpAoHeleper public int line_test() IPoint ipPt1 = new PointClass(); IPoint ipPt2 = new PointClass(); ipPt1.PutCoords(1, 2); ipPt2.PutCoords(2, 3); ILine ipLine = new LineClass(); Stopwatch watch = new Stopwatch();

16、watch.Start(); for (long i = 0; i = 10000000; i+) ipLine.PutCoords(ipPt1, ipPt2); /Console:WriteLine(i); watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds); return 0; 编译,完成C#直接操作AO封装库6 添加新项目,命名为Test右键项目属性,修改输出路径(Output path):即AoWrapperDemoDebug目录添加ESRI.AcrGIS.相关引用添加项目引用修改Program.csusing Syst

17、em;using ESRI.ArcGIS;using ESRI.ArcGIS.esriSystem;namespace Test static class Program / / The main entry point for the application. / STAThread static void Main() if (!RuntimeManager.Bind(ProductCode.Engine) if (!RuntimeManager.Bind(ProductCode.Desktop) Console.WriteLine(Unable to bind to ArcGIS run

18、time. Application will be shut down.); return; IAoInitialize pAoInitialize = new AoInitializeClass(); esriLicenseStatus licenseStatus = pAoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine); if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut) return; Console.WriteLi

19、ne(进行10000000次运算测试rn); Console.WriteLine(=C+/CLI测试开始=); AoWrapper.GeometryWrapper geo = new AoWrapper.GeometryWrapper(); geo.line_test(); Console.WriteLine(=C+/CLI封装本地Api测试开始=); NAoWrapper.RefAoWrapper refAoWrapper = new NAoWrapper.RefAoWrapper(); refAoWrapper.line_test(); Console.WriteLine(=C#测试开始=); CSharpAoHeleper.CSharpAoHeleper sharpAo = new CSharpAoHeleper.CSharpAoHeleper(); sharpAo.line_test(); Console.WriteLine(rn=测试结束=); Console.ReadKey(); 编译,Debug模式运行结果如下Release模式运行结果如下可以发现C+/CLI封装本地Api性能有明显提高!C+/CLI直接调用ArcObjects和C#直接操作ArcObjects并无明显变化。源码下载:

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1