ArcGIS Engine中加载数据

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

1.加载Shapefile数据

1ArcGIS Engine中加载数据 IWorkspaceFactory pWorkspaceFactory;
2ArcGIS Engine中加载数据 IFeatureWorkspace pFeatureWorkspace;
3ArcGIS Engine中加载数据 IFeatureLayer pFeatureLayer;
4ArcGIS Engine中加载数据
5ArcGIS Engine中加载数据 //获取当前路径和文件名
6ArcGIS Engine中加载数据 OpenFileDialog dlg = new OpenFileDialog();
7ArcGIS Engine中加载数据 dlg.Filter = "Shape(*.shp)|*.shp|All Files(*.*)|*.*";
8ArcGIS Engine中加载数据 dlg.Title = "Open Shapefile data";
9ArcGIS Engine中加载数据 dlg.ShowDialog();
10ArcGIS Engine中加载数据 string strFullPath = dlg.FileName;
11ArcGIS Engine中加载数据 if (strFullPath == "") return;
12ArcGIS Engine中加载数据 int Index = strFullPath.LastIndexOf("//");
13ArcGIS Engine中加载数据 string filePath = strFullPath.Substring(0, Index);
14ArcGIS Engine中加载数据 string fileName = strFullPath.Substring(Index + 1);
15ArcGIS Engine中加载数据
16ArcGIS Engine中加载数据 //打开工作空间并添加shp文件
17ArcGIS Engine中加载数据 pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
18ArcGIS Engine中加载数据 pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
19ArcGIS Engine中加载数据 pFeatureLayer = new FeatureLayerClass();
20ArcGIS Engine中加载数据 
21ArcGIS Engine中加载数据 pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(fileName);
22ArcGIS Engine中加载数据 pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
23ArcGIS Engine中加载数据 axMapControl1.Map.AddLayer(pFeatureLayer);
24ArcGIS Engine中加载数据 axMapControl1.ActiveView.Refresh();

2.加载栅格数据

1ArcGIS Engine中加载数据 IWorkspaceFactory pWorkspaceFactory;
2ArcGIS Engine中加载数据 IRasterWorkspace pRasterWorkspace;
3ArcGIS Engine中加载数据
4ArcGIS Engine中加载数据 OpenFileDialog dlg = new OpenFileDialog();
5ArcGIS Engine中加载数据 dlg.Filter = "Layer File(*.lyr)|*.jpg;*.bmp;*.tiff";
6ArcGIS Engine中加载数据 dlg.Title = "Open Raster Data File";
7ArcGIS Engine中加载数据 dlg.ShowDialog();
8ArcGIS Engine中加载数据 //获取当前路径和文件名
9ArcGIS Engine中加载数据 string strFullPath = dlg.FileName;
10ArcGIS Engine中加载数据 if (strFullPath == "") return;
11ArcGIS Engine中加载数据 int Index = strFullPath.LastIndexOf("//");
12ArcGIS Engine中加载数据 string fileName = strFullPath.Substring(Index + 1);
13ArcGIS Engine中加载数据 string filePath = strFullPath.Substring(0, Index);
14ArcGIS Engine中加载数据
15ArcGIS Engine中加载数据 pWorkspaceFactory = new RasterWorkspaceFactoryClass();
16ArcGIS Engine中加载数据 pRasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
17ArcGIS Engine中加载数据 IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(fileName);
18ArcGIS Engine中加载数据 IRasterLayer pRasterLayer = new RasterLayerClass();
19ArcGIS Engine中加载数据 pRasterLayer.CreateFromDataset(pRasterDataset);
20ArcGIS Engine中加载数据 axMapControl1.Map.AddLayer(pRasterLayer);
21ArcGIS Engine中加载数据 axMapControl1.ActiveView.Refresh();

3.加载CAD数据

1ArcGIS Engine中加载数据 IWorkspaceFactory pWorkspaceFactory;
2ArcGIS Engine中加载数据 IFeatureWorkspace pFeatureWorkspace;
3ArcGIS Engine中加载数据 IFeatureLayer pFeatureLayer;
4ArcGIS Engine中加载数据 IFeatureDataset pFeatureDataset;
5ArcGIS Engine中加载数据 //获取当前路径和文件名
6ArcGIS Engine中加载数据 OpenFileDialog dlg = new OpenFileDialog();
7ArcGIS Engine中加载数据 dlg.Filter = "CAD(*.dwg)|*.dwg|All Files(*.*)|*.*";
8ArcGIS Engine中加载数据 dlg.Title = "Open CAD Data file";
9ArcGIS Engine中加载数据 dlg.ShowDialog();
10ArcGIS Engine中加载数据 string strFullPath = dlg.FileName;
11ArcGIS Engine中加载数据 if (strFullPath == "") return;
12ArcGIS Engine中加载数据 int Index = strFullPath.LastIndexOf("//");
13ArcGIS Engine中加载数据 string filePath = strFullPath.Substring(0, Index);
14ArcGIS Engine中加载数据 string fileName = strFullPath.Substring(Index + 1);
15ArcGIS Engine中加载数据 //打开CAD数据集
16ArcGIS Engine中加载数据 pWorkspaceFactory = new CadWorkspaceFactoryClass();
17ArcGIS Engine中加载数据 pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
18ArcGIS Engine中加载数据 //打开一个要素集
19ArcGIS Engine中加载数据 pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(fileName);
20ArcGIS Engine中加载数据 //IFeaturClassContainer可以管理IFeatureDataset中的每个要素类 
21ArcGIS Engine中加载数据 IFeatureClassContainer pFeatClassContainer = (IFeatureClassContainer)pFeatureDataset;
22ArcGIS Engine中加载数据 //对CAD文件中的要素进行遍历处理 
23ArcGIS Engine中加载数据 for (int i = 0; i < pFeatClassContainer.ClassCount - 1; i++)
24ArcGIS Engine中加载数据 {
25ArcGIS Engine中加载数据 IFeatureClass pFeatClass = pFeatClassContainer.get_Class(i);
26ArcGIS Engine中加载数据 if (pFeatClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
27ArcGIS Engine中加载数据 //如果是注记,则添加注记层
28ArcGIS Engine中加载数据 pFeatureLayer = new CadAnnotationLayerClass();
29ArcGIS Engine中加载数据 else//如果是点、线、面,则添加要素层
30ArcGIS Engine中加载数据 {
31ArcGIS Engine中加载数据 pFeatureLayer = new FeatureLayerClass();
32ArcGIS Engine中加载数据 pFeatureLayer.Name = pFeatClass.AliasName;
33ArcGIS Engine中加载数据 pFeatureLayer.FeatureClass = pFeatClass;
34ArcGIS Engine中加载数据 axMapControl1.Map.AddLayer(pFeatureLayer);
35ArcGIS Engine中加载数据 axMapControl1.ActiveView.Refresh();
36ArcGIS Engine中加载数据 }
37ArcGIS Engine中加载数据 }

4.加载PersonGeodatabase数据

1ArcGIS Engine中加载数据 IWorkspaceFactory pAccessWorkspaceFactory;
2ArcGIS Engine中加载数据 IFeatureWorkspace pFeatureWorkspace;
3ArcGIS Engine中加载数据 IFeatureLayer pFeatureLayer;
4ArcGIS Engine中加载数据 IFeatureDataset pFeatureDataset;
5ArcGIS Engine中加载数据
6ArcGIS Engine中加载数据 //获取当前路径和文件名
7ArcGIS Engine中加载数据 OpenFileDialog dlg = new OpenFileDialog();
8ArcGIS Engine中加载数据 dlg.Filter = "Personal Geodatabase(*.mdb)|*.mdb|All Files(*.*)|*.*";
9ArcGIS Engine中加载数据 dlg.Title = "Open PersonGeodatabase file";
10ArcGIS Engine中加载数据 dlg.ShowDialog();
11ArcGIS Engine中加载数据 string strFullPath = dlg.FileName;
12ArcGIS Engine中加载数据 if (strFullPath == "") return;
13ArcGIS Engine中加载数据
14ArcGIS Engine中加载数据 //打开personGeodatabase,并添加图层
15ArcGIS Engine中加载数据 pAccessWorkspaceFactory = new AccessWorkspaceFactoryClass();
16ArcGIS Engine中加载数据 //打开工作空间并遍历数据集
17ArcGIS Engine中加载数据 IWorkspace pWorkspace = pAccessWorkspaceFactory.OpenFromFile(strFullPath, 0);
18ArcGIS Engine中加载数据 IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
19ArcGIS Engine中加载数据 pEnumDataset.Reset();
20ArcGIS Engine中加载数据 IDataset pDataset = pEnumDataset.Next();
21ArcGIS Engine中加载数据 //如果数据集是IFeatureDataset,则遍历它下面的子类
22ArcGIS Engine中加载数据 if (pDataset is IFeatureDataset)
23ArcGIS Engine中加载数据 {
24ArcGIS Engine中加载数据 pFeatureWorkspace = (IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(strFullPath, 0);
25ArcGIS Engine中加载数据 pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
26ArcGIS Engine中加载数据 IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
27ArcGIS Engine中加载数据 pEnumDataset1.Reset();
28ArcGIS Engine中加载数据 IDataset pDataset1 = pEnumDataset1.Next();
29ArcGIS Engine中加载数据 //如果子类是FeatureClass,则添加到axMapControl1中
30ArcGIS Engine中加载数据 if (pDataset1 is IFeatureClass)
31ArcGIS Engine中加载数据 {
32ArcGIS Engine中加载数据 pFeatureLayer = new FeatureLayerClass();
33ArcGIS Engine中加载数据 pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset1.Name);
34ArcGIS Engine中加载数据 pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
35ArcGIS Engine中加载数据 axMapControl1.Map.AddLayer(pFeatureLayer);
36ArcGIS Engine中加载数据 axMapControl1.ActiveView.Refresh();
37ArcGIS Engine中加载数据 }
38ArcGIS Engine中加载数据 else
39ArcGIS Engine中加载数据 {
40ArcGIS Engine中加载数据 MessageBox.Show("No FeatureLayer!");
41ArcGIS Engine中加载数据 }
42ArcGIS Engine中加载数据 }
43ArcGIS Engine中加载数据 else
44ArcGIS Engine中加载数据 {
45ArcGIS Engine中加载数据 pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
46ArcGIS Engine中加载数据 pFeatureLayer = new FeatureLayerClass();
47ArcGIS Engine中加载数据 pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass("图层名");
48ArcGIS Engine中加载数据 pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
49ArcGIS Engine中加载数据 axMapControl1.Map.AddLayer(pFeatureLayer);
50ArcGIS Engine中加载数据 axMapControl1.ActiveView.Refresh();
51ArcGIS Engine中加载数据 }

5.加载SDE数据库数据

1ArcGIS Engine中加载数据 public ESRI.ArcGIS.Geodatabase.IWorkspace arcSDEWorkspaceOpen(String server, String instance, String user, String password, String database, String version)
2ArcGIS Engine中加载数据 {
3ArcGIS Engine中加载数据 try
4ArcGIS Engine中加载数据 {
5ArcGIS Engine中加载数据 // Create and populate the property set
6ArcGIS Engine中加载数据 ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
7ArcGIS Engine中加载数据 propertySet.SetProperty("SERVER", server);
8ArcGIS Engine中加载数据 propertySet.SetProperty("INSTANCE", instance);
9ArcGIS Engine中加载数据 propertySet.SetProperty("DATABASE", database);
10ArcGIS Engine中加载数据 propertySet.SetProperty("USER", user);
11ArcGIS Engine中加载数据 propertySet.SetProperty("PASSWORD", password);
12ArcGIS Engine中加载数据 propertySet.SetProperty("VERSION", version);
13ArcGIS Engine中加载数据
14ArcGIS Engine中加载数据 ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 workspaceFactory;
15ArcGIS Engine中加载数据 workspaceFactory = (ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2)new SdeWorkspaceFactoryClass();
16ArcGIS Engine中加载数据 return workspaceFactory.Open(propertySet, 0);
17ArcGIS Engine中加载数据 }
18ArcGIS Engine中加载数据 catch (Exception e)
19ArcGIS Engine中加载数据 {
20ArcGIS Engine中加载数据 throw new Exception(String.Format("arcSDEWorkspaceOpen: {0}", e.Message), e);
21ArcGIS Engine中加载数据 }
22ArcGIS Engine中加载数据 }
23ArcGIS Engine中加载数据
24ArcGIS Engine中加载数据 IWorkspace pWorkspace = arcSDEWorkspaceOpen("计算机名", "5151", "数据库用户", "密码", "", "sde.DEFAULT");
25ArcGIS Engine中加载数据
26ArcGIS Engine中加载数据 IFeatureWorkspace pFeattureWS = (IFeatureWorkspace)pWorkspace;
27ArcGIS Engine中加载数据 IFeatureClass pFeatureClass = pFeattureWS.OpenFeatureClass("图层名");
28ArcGIS Engine中加载数据 IFeatureLayer pFeatureLayer = new FeatureLayerClass();
29ArcGIS Engine中加载数据 pFeatureLayer.FeatureClass = pFeatureClass;
30ArcGIS Engine中加载数据
31ArcGIS Engine中加载数据 axMapControl1.AddLayer(pFeatureLayer);
32ArcGIS Engine中加载数据 axMapControl1.Refresh();  
上一篇:2017上海QCon之旅总结(上)


下一篇:支付宝sdk集成过程中报 openssl/asn1.h file not found错误的解决办法