最近又捞起了ARCGIS Engine,从原来的9.3到现在的10.3,想深度来着,但是一直都是看看demo,并没有怎么深入。这几天吧打开加载数据的代码写写。
Engine一直是跑32位,跑X64就会报错,听说以前9.3的时候用的是GDAL,只能跑X86,但是为啥10以后不是不再用GDAL了吗?怎么还是不能跑X64呢?希望有共同开发的友友看到了研究研究,10系列怎么跑在X64平台上。好了不费话了,直接开始说打开数据。
Engine打开数据是个基础,说三个方法,前两个基本上是同一套内容,使用系统工具加载数据,后面使用代码的方式打开。
一、 直接加载系统工具
这个方式最简单,就是连接控件直接添加加载数据的按钮。
二、使用代码直接调用系统功能:
//系统添加命令
ICommand CmdOpenData = new ControlsAddDataCommand();
CmdOpenData.OnCreate(axMapControl1.Object);
CmdOpenData.OnClick();
三、通过OpenFileDialog打开本地shp文件
OpenFileDialog OpenShpFile = new OpenFileDialog();
OpenShpFile.Title = "打开shp数据";
OpenShpFile.Filter = "Shp数据|*.shp";//文件过滤条件
OpenShpFile.Multiselect = false;//禁止多选
OpenShpFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);//初始化文档目录,目前指向个人文档
OpenShpFile.RestoreDirectory = true;//记录文件夹位置
DialogResult ShpFileopenDia = OpenShpFile.ShowDialog();
//判断打开文件对话框选择状态
if (ShpFileopenDia == DialogResult.OK)
{
string ShpFolder = System.IO.Path.GetDirectoryName(OpenShpFile.FileName);
IWorkspaceFactory ShpWorkSpaceFactory = new ShapefileWorkspaceFactory();
IWorkspace ShpWorkSpace = ShpWorkSpaceFactory.OpenFromFile(ShpFolder, 0);
IFeatureWorkspace FeatureWorkSpace = ShpWorkSpace as IFeatureWorkspace;
IFeatureClass FeatureClass = FeatureWorkSpace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(OpenShpFile.FileName));
IFeatureLayer Layer = new FeatureLayer();
Layer.FeatureClass = FeatureClass;
Layer.Name = FeatureClass.AliasName;
Layer.Visible = true;
IMap Map = axMapControl1.Map;
Map.AddLayer(Layer);
axMapControl1.Extent = axMapControl1.FullExtent;
axMapControl1.ActiveView.Refresh();
}