ArcGIS Engine中加载数据

ArcGIS Engine中加载数据

http://blog.csdn.net/gisstar/article/details/4206822

分类: AE开发积累2009-05-21 16:491118人阅读评论(0)收藏举报

database数据库serveruser工作class

1.加载Shapefile数据

1 IWorkspaceFactory pWorkspaceFactory;
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.加载栅格数据

1 IWorkspaceFactory pWorkspaceFactory;
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数据

1 IWorkspaceFactory pWorkspaceFactory;
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数据

1 IWorkspaceFactory pAccessWorkspaceFactory;
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数据库数据

1 public ESRI.ArcGIS.Geodatabase.IWorkspace arcSDEWorkspaceOpen(String server, String instance, String user, String password, String database, String version)
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中加载数据

时间: 2024-10-01 06:34:28

ArcGIS Engine中加载数据的相关文章

Flexigrid从对象中加载数据

Flexigrid是用来动态加载数据的一种比较好(老)的Jquery表插件,然后有些时候,我们需要其从本地或者jQuery对象中加载数据,比如有这么个需求,页面显示中有两个表格A和B,其中A表格从服务器端加载数据,B表格需要根据用户的操作来动态更新,例如当用户勾选住A表格的某些项时,B表格就把这些项显示在其中.对于这么个请求,可以如下解决: 1)建立一个Jquery对象C,用于保存B表格的信息: 2)当用户选择A表格中的某些项时,C更新它所保存的内容: 3)当C的内容发生变化时,B表格更新其显示

七. 从文件中加载数据

从文件中加载数据有两种方法,一种是利用内置的csv模块,一种是利用第三方模块numpy import matplotlib.pyplot as plt import csv import numpy as np # csv 方法 x = [] y = [] with open('example.txt','r') as csvfile: plots = csv.reader(csvfile, delimiter=',') for row in plots: x.append(int(row[0]

caffe使用MemoryDataLayer从内存中加载数据

最近在搞caffe的应用,因为很多时候我们需要进行服务器来进行特征的抽取,所以我们需要很将单张图片丢入caffe的网络进行一次传递,这样就诞生了一个从内存中如何加载数据进入caffe的需求,这里我直接贴出代码来先: #include <boost/make_shared.hpp> // these need to be included after boost on OS X #include <string> // NOLINT(build/include_order) #inc

DHTMLX 前端框架 建立你的一个应用程序 教程(六)-- 表格加载数据

从数据库加载数据 这篇我们介绍从MySQL数据库中加载数据到表格 我们使用 MySql的数据库dhtmlx_tutorial 和表contacts 示例使用的是PHP平台和dhtmlxConnector 帮助库  因为这是实现服务器端逻辑最简单的方法   数据以XML格式输出. 环境自己搭建  相信C#的朋友 从数据库获取数据转化盛XML也不是难事. 加载数据到表格: 1.找到”db.sql“文件将表导入到本地数据库 2.在codebase 文件中添加一个php文件codebase 3.下载dh

Android仿美团加载数据 小人奔跑进度动画对话框(附顺丰快递员奔跑效果)

我们都知道在Android中,常见的动画模式有两种:一种是帧动画(Frame Animation),一种是补间动画(Tween Animation).帧动画是提供了一种逐帧播放图片的动画方式,播放事先做好的图像,与gif图片原理类似,就像是在放电影一样.补间动画可以实现View组件的移动.放大.缩小以及渐变等效果. 今天我们主要来模仿一下美团中加载数据时小人奔跑动画的对话框效果,取个有趣的名字就是Running Man,奔跑吧,兄弟!话不多少,先上效果图,让各位大侠看看是不是你想要实现的效果,然

ArcGIS Engine中数据的加载 (转)

1.加载Shapefile数据 1 IWorkspaceFactory pWorkspaceFactory; 2 IFeatureWorkspace pFeatureWorkspace; 3 IFeatureLayer pFeatureLayer; 4 5 //获取当前路径和文件名 6 OpenFileDialog dlg = new OpenFileDialog(); 7 dlg.Filter = "Shape(*.shp)|*.shp|All Files(*.*)|*.*"; 8

Arcgis for js,Openlayers中加载GeoJSON

概述: 在前文中,讲述了在JAVA环境下如何将shp转换为GeoJSON,在本文,分别讲述在Arcgis for js,Openlayers2和Openlayers3中加载展示GeoJSON. 实现: 1.Openlayers2中加载GeoJSON 在OL2中,可以直接调用OL2的借口实现GeoJSON的加载,代码示例: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UT

visual studio2010中C#生成的,ArcGIS二次开发的basetool的dll,注册为COM组件tlb文件,并在arcmap中加载使用

写了个标题好长啊~~~~ 这两天又认识了一个新玩意,记录一下下,啦啦啦~~~~~ 话说,认识arcgis快十年了,从桌面版到engine的二次开发,其实不过才认识到它的冰山一角, 它总是能带来很多还未知的东西,实话说,就是如此的热爱着它,因为从来都觉得遨游其中,没有边界~~~~~ arcengine二次开发,这个玩意现在已经不流行了,但是其奥妙和乐趣依然无穷~~~~ 言归: 一. 之前写的basetool,basecommand等类都是在独立的系统中运行的,没有单独注册成过组件在桌面版arcma

ArcGIS API for Silverlight中加载Google地形图(瓦片图)

原文:ArcGIS API for Silverlight中加载Google地形图(瓦片图) 在做水利.气象.土地等行业中,若能使用到Google的地形图那是再合适不过了,下面就介绍如何在ArcGIS API for Silverlight中加载Google地 形图.先上一个图,初步制作,待后续继续改进 ArcGIS API for Silverlight 中的ArcGISTiledMapServiceLayer图层,继承自TiledMapServiceLayer.如果想实现自己的缓存地图图 层