




已阅读5页,还剩12页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1新建一个空的工程命名为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:ArcGIS;namespace AoWrapperpublic ref class GeometryWrapperpublic:GeometryWrapper()ESRI:ArcGIS:RuntimeManager:Bind(ProductCode:Engine);IAoInitialize pAoInitialize=gcnew AoInitializeClass();pAoInitialize-Initialize(esriLicenseProductCode:esriLicenseProductCodeEngineGeoDB);GeometryWrapper()public: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:WriteLine(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 once#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 win32 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 (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_implementation添加一个头文件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,修改后如下:/ 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(ArcGISVersionLib: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(esriLicenseProductCode: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 添加新项目,命名为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(); RefAoWrapper(); 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 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 ESRI.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(); 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 System;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 runtime. Application will be shut down.); return; IAoInitialize pAoInitialize = new AoInitializeClass(); esriLicenseStatus licenseStatus = pAoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine); if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut) return; Console.WriteLine(进行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.CSha
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 停车场监控施工方案
- 绿化养护招标方案范本
- 仿古水磨石地面施工方案
- 浆嵌卵石路面施工方案
- 空调管井立管施工方案
- 装修施工方案的要求包括
- 企业品牌推广方案设计要点
- 徐州食品安全员考试题库及答案解析
- 不锈钢铠装施工方案
- 库房管理工作汇报
- 神经外科危重症患者的观察与护理
- 做最勇敢的自己
- 《中国象棋基础教程》课件
- 保险销售技巧培训课件
- 《支气管动脉栓塞术》课件
- 2025年河北石家庄市高速公路集团限公司面向社会公开招聘收费人员150名高频重点提升(共500题)附带答案详解
- 地面铺装室外施工合同
- 人员分级管理
- 2024-2025年江苏专转本英语历年真题(含答案)
- 《铁路轨道维护》课件-钢轨母材探伤
- 餐饮服务工作培训
评论
0/150
提交评论