ArcGIS Engine中加载数据
1.加载Shapefile数据
2 IFeatureWorkspace pFeatureWorkspace;
3 IFeatureLayer pFeatureLayer;
4
5 //获取当前路径和文件名
6 OpenFileDialog dlg = new OpenFileDialog();
7 dlg.Filter = "Shape(*.shp)|*.shp|All Files(*.*)|*.*";
8 dlg.Title = "Open Shapefile data";
9 dlg.ShowDialog();
10 string strFullPath = dlg.FileName;
11 if (strFullPath == "") return;
12 int Index = strFullPath.LastIndexOf("//");
13 string filePath = strFullPath.Substring(0, Index);
14 string fileName = strFullPath.Substring(Index + 1);
15
16 //打开工作空间并添加shp文件
17 pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
18 pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
19 pFeatureLayer = new FeatureLayerClass();
20
21 pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(fileName);
22 pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
23 axMapControl1.Map.AddLayer(pFeatureLayer);
24 axMapControl1.ActiveView.Refresh();
2.加载栅格数据
2 IRasterWorkspace pRasterWorkspace;
3
4 OpenFileDialog dlg = new OpenFileDialog();
5 dlg.Filter = "Layer File(*.lyr)|*.jpg;*.bmp;*.tiff";
6 dlg.Title = "Open Raster Data File";
7 dlg.ShowDialog();
8 //获取当前路径和文件名
9 string strFullPath = dlg.FileName;
10 if (strFullPath == "") return;
11 int Index = strFullPath.LastIndexOf("//");
12 string fileName = strFullPath.Substring(Index + 1);
13 string filePath = strFullPath.Substring(0, Index);
14
15 pWorkspaceFactory = new RasterWorkspaceFactoryClass();
16 pRasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
17 IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(fileName);
18 IRasterLayer pRasterLayer = new RasterLayerClass();
19 pRasterLayer.CreateFromDataset(pRasterDataset);
20 axMapControl1.Map.AddLayer(pRasterLayer);
21 axMapControl1.ActiveView.Refresh();
3.加载CAD数据
2 IFeatureWorkspace pFeatureWorkspace;
3 IFeatureLayer pFeatureLayer;
4 IFeatureDataset pFeatureDataset;
5 //获取当前路径和文件名
6 OpenFileDialog dlg = new OpenFileDialog();
7 dlg.Filter = "CAD(*.dwg)|*.dwg|All Files(*.*)|*.*";
8 dlg.Title = "Open CAD Data file";
9 dlg.ShowDialog();
10 string strFullPath = dlg.FileName;
11 if (strFullPath == "") return;
12 int Index = strFullPath.LastIndexOf("//");
13 string filePath = strFullPath.Substring(0, Index);
14 string fileName = strFullPath.Substring(Index + 1);
15 //打开CAD数据集
16 pWorkspaceFactory = new CadWorkspaceFactoryClass();
17 pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
18 //打开一个要素集
19 pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(fileName);
20 //IFeaturClassContainer可以管理IFeatureDataset中的每个要素类
21 IFeatureClassContainer pFeatClassContainer = (IFeatureClassContainer)pFeatureDataset;
22 //对CAD文件中的要素进行遍历处理
23 for (int i = 0; i < pFeatClassContainer.ClassCount - 1; i++)
24 {
25 IFeatureClass pFeatClass = pFeatClassContainer.get_Class(i);
26 if (pFeatClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
27 //如果是注记,则添加注记层
28 pFeatureLayer = new CadAnnotationLayerClass();
29 else//如果是点、线、面,则添加要素层
30 {
31 pFeatureLayer = new FeatureLayerClass();
32 pFeatureLayer.Name = pFeatClass.AliasName;
33 pFeatureLayer.FeatureClass = pFeatClass;
34 axMapControl1.Map.AddLayer(pFeatureLayer);
35 axMapControl1.ActiveView.Refresh();
36 }
37 }
4.加载PersonGeodatabase数据
2 IFeatureWorkspace pFeatureWorkspace;
3 IFeatureLayer pFeatureLayer;
4 IFeatureDataset pFeatureDataset;
5
6 //获取当前路径和文件名
7 OpenFileDialog dlg = new OpenFileDialog();
8 dlg.Filter = "Personal Geodatabase(*.mdb)|*.mdb|All Files(*.*)|*.*";
9 dlg.Title = "Open PersonGeodatabase file";
10 dlg.ShowDialog();
11 string strFullPath = dlg.FileName;
12 if (strFullPath == "") return;
13
14 //打开personGeodatabase,并添加图层
15 pAccessWorkspaceFactory = new AccessWorkspaceFactoryClass();
16 //打开工作空间并遍历数据集
17 IWorkspace pWorkspace = pAccessWorkspaceFactory.OpenFromFile(strFullPath, 0);
18 IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
19 pEnumDataset.Reset();
20 IDataset pDataset = pEnumDataset.Next();
21 //如果数据集是IFeatureDataset,则遍历它下面的子类
22 if (pDataset is IFeatureDataset)
23 {
24 pFeatureWorkspace = (IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(strFullPath, 0);
25 pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
26 IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
27 pEnumDataset1.Reset();
28 IDataset pDataset1 = pEnumDataset1.Next();
29 //如果子类是FeatureClass,则添加到axMapControl1中
30 if (pDataset1 is IFeatureClass)
31 {
32 pFeatureLayer = new FeatureLayerClass();
33 pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset1.Name);
34 pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
35 axMapControl1.Map.AddLayer(pFeatureLayer);
36 axMapControl1.ActiveView.Refresh();
37 }
38 else
39 {
40 MessageBox.Show("No FeatureLayer!");
41 }
42 }
43 else
44 {
45 pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
46 pFeatureLayer = new FeatureLayerClass();
47 pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass("图层名");
48 pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
49 axMapControl1.Map.AddLayer(pFeatureLayer);
50 axMapControl1.ActiveView.Refresh();
51 }
5.加载SDE数据库数据
2 {
3 try
4 {
5 // Create and populate the property set
6 ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
7 propertySet.SetProperty("SERVER", server);
8 propertySet.SetProperty("INSTANCE", instance);
9 propertySet.SetProperty("DATABASE", database);
10 propertySet.SetProperty("USER", user);
11 propertySet.SetProperty("PASSWORD", password);
12 propertySet.SetProperty("VERSION", version);
13
14 ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 workspaceFactory;
15 workspaceFactory = (ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2)new SdeWorkspaceFactoryClass();
16 return workspaceFactory.Open(propertySet, 0);
17 }
18 catch (Exception e)
19 {
20 throw new Exception(String.Format("arcSDEWorkspaceOpen: {0}", e.Message), e);
21 }
22 }
23
24 IWorkspace pWorkspace = arcSDEWorkspaceOpen("计算机名", "5151", "数据库用户", "密码", "", "sde.DEFAULT");
25
26 IFeatureWorkspace pFeattureWS = (IFeatureWorkspace)pWorkspace;
27 IFeatureClass pFeatureClass = pFeattureWS.OpenFeatureClass("图层名");
28 IFeatureLayer pFeatureLayer = new FeatureLayerClass();
29 pFeatureLayer.FeatureClass = pFeatureClass;
30
31 axMapControl1.AddLayer(pFeatureLayer);
32 axMapControl1.Refresh();
ArcGIS Engine中加载数据的更多相关文章
- Flexigrid从对象中加载数据
(有问题,在找…………) Flexigrid是用来动态加载数据的一种比较好(老)的Jquery表插件,然后有些时候,我们需要其从本地或者jQuery对象中加载数据,比如有这么个需求,页面显示中有两个表 ...
- ML.NET Cookbook --- 1.如何从文本文件中加载数据?
使用ML.NET中的TextLoader扩展方法从文本文件中加载数据.你需要知道在文本文件中数据列在那里,它们的类型是什么,在文本文件中什么位置可以找到它们. 请注意:对于ML.NET只读取文件的某些 ...
- 机器学习:从sklearn中加载数据
一.sklearn模块 sklearn模块下有很多子模块,常用的数据集在:sklearn.datasets模块下: 通过数据集中DESCR来查看数据集的文档: 从datasets中加载数据: impo ...
- python数据可视化-matplotlib入门(6)-从文件中加载数据
前几篇都是手动录入或随机函数产生的数据.实际有许多类型的文件,以及许多方法,用它们从文件中提取数据来图形化. 比如之前python基础(12)介绍打开文件的方式,可直接读取文件中的数据,扩大了我们的数 ...
- 向treeview中加载数据
1.获取树节点的值,用事件AfterSelect加载(id值的获取,用name来获取) 2.双击treeview控件得到 private void treeView1_AfterSelect(obje ...
- java多线程向数据库中加载数据
读取本地文件,每行为一条记录,文件大小550M,200万条数据.先将文件读取的内存中,再开启6个线程连接postgresql不同coordinator端口导入数据.代码如下: import java. ...
- Vue完成页面切换中加载数据
created() { // 拿到路由传递来的car主键 let pk = this.$route.query.pk || this.$route.params.pk; // 主键不存在,就直接结束方 ...
- DHTMLX 前端框架 建立你的一个应用程序 教程(六)-- 表格加载数据
从数据库加载数据 这篇我们介绍从MySQL数据库中加载数据到表格 我们使用 MySql的数据库dhtmlx_tutorial 和表contacts 示例使用的是PHP平台和dhtmlxConnecto ...
- Android动画之仿美团加载数据等待时,小人奔跑进度动画对话框(附顺丰快递员奔跑效果)
Android动画之仿美团加载数据等待时,小人奔跑进度动画对话框(附顺丰快递员奔跑效果) 首句依然是那句老话,你懂得! finddreams :(http://blog.csdn.net/finddr ...
随机推荐
- 常用ARM汇编指令
常用ARM汇编指令 [日期:2012-07-14] 来源:Linux社区 作者:xuyuanfan77 [字体:大 中 小] 在嵌入式开发中,汇编程序常常用于非常关键的地方,比如系统启动时初 ...
- C语言文法定义及C程序的推导过程
program à external_declaration | program external_declaration <程序> -> <外部声明> | < ...
- mysql源码重启
1.通过rpm包安装的MySQL service mysqld restart /etc/inint.d/mysqld start 2.从源码包安装的MySQL // linux关闭MySQL的命令 ...
- php--纯静态和伪静态的区别与关系
先前说了什么是纯静态和伪静态,现在介绍一下他们的区别? 首先肯定的是纯静态和伪静态都是SEO的产物,但纯静态和伪静态还是有很大区别的.纯静态是生成真实的HTML页面保存到服务器端,用户访问时直接访问这 ...
- 设计模式:组合模式(Composite)
定 义:将对象组合树形结构以表示“部分-整体”的层次结构.组合模式使得用户对单个对象和组合对象使用具有一致性. 结构图: Component类: abstract class Component ...
- iOS 调出storyboard里面起始Controller的箭头
在storyboard里面,如果第一个ViewController不是默认的ViewController的时候,我们就需要拖拽一个出来. 如果把默认的ViewController删掉的话,前面的箭头, ...
- Excel导入数据到Sql server 中出错:“文本被截断,或者一个或多个字符在目标代码页中没有匹配项”
从Excel导入数据到Sql server 时,由于表中的数据有的很长,导入时出现如下错误(如果数据不是很长,255内以内,则不会出现错误): 出错原因: SQL Server的导入导出为了确定数据表 ...
- https://my.oschina.net/huangyong/blog/161419
https://my.oschina.net/huangyong/blog/161419
- 人脸识别的ppt
http://wenku.baidu.com/link?url=GWiNRy_9mzqBZ9_2DDZbHRZbBbaBofhs1Y0pBS7aiE5oab8TY78r_z6aAlqo_L9AZzD4 ...
- nc 反弹链接
nc -l -v -p 80在本机监听80端口,此时80端口是打开的,我们可以在浏览器输入127.0.0.1进行浏览,此时就会出现连接,我们再在监听窗口输入字符,就会在浏览器上显示了.知道上面的作用后 ...