arcengine不同数据的加载处理 arcengine 镶嵌数据集

1.加载Shapefile数据
1IWorkspaceFactorypWorkspaceFactory;
2IFeatureWorkspacepFeatureWorkspace;
3IFeatureLayerpFeatureLayer;
4
5//获取当前路径和文件名
6OpenFileDialogdlg=newOpenFileDialog();
7dlg.Filter="Shape(*.shp)|*.shp|AllFiles(*.*)|*.*";
8dlg.Title="OpenShapefiledata";
9dlg.ShowDialog();
10stringstrFullPath=dlg.FileName;
11if(strFullPath=="")return;
12intIndex=strFullPath.LastIndexOf("\");
13stringfilePath=strFullPath.Substring(0,Index);
14stringfileName=strFullPath.Substring(Index+1);
15
16//打开工作空间并添加shp文件
17pWorkspaceFactory=newShapefileWorkspaceFactoryClass();
18pFeatureWorkspace=(IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath,0);
19pFeatureLayer=newFeatureLayerClass();
20
21pFeatureLayer.FeatureClass=pFeatureWorkspace.OpenFeatureClass(fileName);
22pFeatureLayer.Name=pFeatureLayer.FeatureClass.AliasName;
23axMapControl1.Map.AddLayer(pFeatureLayer);
24axMapControl1.ActiveView.Refresh();
2.加载栅格数据
1IWorkspaceFactorypWorkspaceFactory;
2IRasterWorkspacepRasterWorkspace;
3
4OpenFileDialogdlg=newOpenFileDialog();
5dlg.Filter="LayerFile(*.lyr)|*.jpg;*.bmp;*.tiff";
6dlg.Title="OpenRasterDataFile";
7dlg.ShowDialog();
8//获取当前路径和文件名
9stringstrFullPath=dlg.FileName;
10if(strFullPath=="")return;
11intIndex=strFullPath.LastIndexOf("\");
12stringfileName=strFullPath.Substring(Index+1);
13stringfilePath=strFullPath.Substring(0,Index);
14
15pWorkspaceFactory=newRasterWorkspaceFactoryClass();
16pRasterWorkspace=(IRasterWorkspace)pWorkspaceFactory.OpenFromFile(filePath,0);
17IRasterDatasetpRasterDataset=(IRasterDataset)pRasterWorkspace.OpenRasterDataset(fileName);
18IRasterLayerpRasterLayer=newRasterLayerClass();
19pRasterLayer.CreateFromDataset(pRasterDataset);
20axMapControl1.Map.AddLayer(pRasterLayer);
21axMapControl1.ActiveView.Refresh();
3.加载CAD数据
1IWorkspaceFactorypWorkspaceFactory;
2IFeatureWorkspacepFeatureWorkspace;
3IFeatureLayerpFeatureLayer;
4IFeatureDatasetpFeatureDataset;
5//获取当前路径和文件名
6OpenFileDialogdlg=newOpenFileDialog();
7dlg.Filter="CAD(*.dwg)|*.dwg|AllFiles(*.*)|*.*";
8dlg.Title="OpenCADDatafile";
9dlg.ShowDialog();
10stringstrFullPath=dlg.FileName;
11if(strFullPath=="")return;
12intIndex=strFullPath.LastIndexOf("\");
13stringfilePath=strFullPath.Substring(0,Index);
14stringfileName=strFullPath.Substring(Index+1);
15//打开CAD数据集
16pWorkspaceFactory=newCadWorkspaceFactoryClass();
17pFeatureWorkspace=(IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath,0);
18//打开一个要素集
19pFeatureDataset=pFeatureWorkspace.OpenFeatureDataset(fileName);
20//IFeaturClassContainer可以管理IFeatureDataset中的每个要素类
21IFeatureClassContainerpFeatClassContainer=(IFeatureClassContainer)pFeatureDataset;
22//对CAD文件中的要素进行遍历处理
23for(inti=0;i<pFeatClassContainer.ClassCount-1;i++)
24{
25IFeatureClasspFeatClass=pFeatClassContainer.get_Class(i);
26if(pFeatClass.FeatureType==esriFeatureType.esriFTCoverageAnnotation)
27//如果是注记,则添加注记层
28pFeatureLayer=newCadAnnotationLayerClass();
29else//如果是点、线、面,则添加要素层
30{
31pFeatureLayer=newFeatureLayerClass();
32pFeatureLayer.Name=pFeatClass.AliasName;
33pFeatureLayer.FeatureClass=pFeatClass;
34axMapControl1.Map.AddLayer(pFeatureLayer);
35axMapControl1.ActiveView.Refresh();
36}
37}4.加载PersonGeodatabase数据
1IWorkspaceFactorypAccessWorkspaceFactory;
2IFeatureWorkspacepFeatureWorkspace;
3IFeatureLayerpFeatureLayer;
4IFeatureDatasetpFeatureDataset;
5
6//获取当前路径和文件名
7OpenFileDialogdlg=newOpenFileDialog();
8dlg.Filter="PersonalGeodatabase(*.mdb)|*.mdb|AllFiles(*.*)|*.*";
9dlg.Title="OpenPersonGeodatabasefile";
10dlg.ShowDialog();
11stringstrFullPath=dlg.FileName;
12if(strFullPath=="")return;
13
14//打开personGeodatabase,并添加图层
15pAccessWorkspaceFactory=newAccessWorkspaceFactoryClass();
16//打开工作空间并遍历数据集
17IWorkspacepWorkspace=pAccessWorkspaceFactory.OpenFromFile(strFullPath,0);
18IEnumDatasetpEnumDataset=pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
19pEnumDataset.Reset();
20IDatasetpDataset=pEnumDataset.Next();
21//如果数据集是IFeatureDataset,则遍历它下面的子类
22if(pDatasetisIFeatureDataset)
23{
24pFeatureWorkspace=(IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(strFullPath,0);
25pFeatureDataset=pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
26IEnumDatasetpEnumDataset1=pFeatureDataset.Subsets;
27pEnumDataset1.Reset();
28IDatasetpDataset1=pEnumDataset1.Next();
29//如果子类是FeatureClass,则添加到axMapControl1中
30if(pDataset1isIFeatureClass)
31{
32pFeatureLayer=newFeatureLayerClass();
33pFeatureLayer.FeatureClass=pFeatureWorkspace.OpenFeatureClass(pDataset1.Name);
34pFeatureLayer.Name=pFeatureLayer.FeatureClass.AliasName;
35axMapControl1.Map.AddLayer(pFeatureLayer);
36axMapControl1.ActiveView.Refresh();
37}
38else
39{
40MessageBox.Show("NoFeatureLayer!");
41}
42}
43else
arcengine不同数据的加载处理 arcengine 镶嵌数据集
44{
45pFeatureWorkspace=(IFeatureWorkspace)pWorkspace;
46pFeatureLayer=newFeatureLayerClass();
47pFeatureLayer.FeatureClass=pFeatureWorkspace.OpenFeatureClass("图层名");
48pFeatureLayer.Name=pFeatureLayer.FeatureClass.AliasName;
49axMapControl1.Map.AddLayer(pFeatureLayer);
50axMapControl1.ActiveView.Refresh();
51}5.加载SDE数据库数据
1publicESRI.ArcGIS.Geodatabase.IWorkspacearcSDEWorkspaceOpen(Stringserver,Stringinstance,Stringuser,Stringpassword,Stringdatabase,Stringversion)
2{
3try
4{
5//Createandpopulatethepropertyset
6ESRI.ArcGIS.esriSystem.IPropertySetpropertySet=newESRI.ArcGIS.esriSystem.PropertySetClass();
7propertySet.SetProperty("SERVER",server);
8propertySet.SetProperty("INSTANCE",instance);
9propertySet.SetProperty("DATABASE",database);
10propertySet.SetProperty("USER",user);
11propertySet.SetProperty("PASSWORD",password);
12propertySet.SetProperty("VERSION",version);
13
14ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2workspaceFactory;
15workspaceFactory=(ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2)newSdeWorkspaceFactoryClass();
16returnworkspaceFactory.Open(propertySet,0);
17}
18catch(Exceptione)
19{
20thrownewException(String.Format("arcSDEWorkspaceOpen:{0}",e.Message),e);
21}
22}
23
24IWorkspacepWorkspace=arcSDEWorkspaceOpen("计算机名","5151","数据库用户","密码","","sde.DEFAULT");
25
26IFeatureWorkspacepFeattureWS=(IFeatureWorkspace)pWorkspace;
27IFeatureClasspFeatureClass=pFeattureWS.OpenFeatureClass("图层名");
28IFeatureLayerpFeatureLayer=newFeatureLayerClass();
29pFeatureLayer.FeatureClass=pFeatureClass;
30
31axMapControl1.AddLayer(pFeatureLayer);
32axMapControl1.Refresh();

6、文件地理数据库加载

IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
IFeatureDataset pFeatureDataset;

string filePath = @"D:MyDocumentsArcGIS新建文件地理数据库.gdb";
string filename = "haha";
//打开personGeodatabase,并添加图层
IWorkspaceFactory pAccessWorkspaceFactory = newFileGDBWorkspaceFactoryClass();
//打开工作空间并遍历数据集
IWorkspace pWorkspace =pAccessWorkspaceFactory.OpenFromFile(filePath, 0);
IEnumDataset pEnumDataset =pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
pEnumDataset.Reset();
IDataset pDataset = pEnumDataset.Next();
//如果数据集是IFeatureDataset,则遍历它下面的子类
if (pDataset is IFeatureDataset)
{
pFeatureWorkspace =(IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(filePath,0);
pFeatureDataset =pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
pEnumDataset1.Reset();
IDataset pDataset1 = pEnumDataset1.Next();
//如果子类是FeatureClass,则添加到axMapControl1中
if (pDataset1 is IFeatureClass)
{
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass =pFeatureWorkspace.OpenFeatureClass(filename);
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;

IRgbColor pRgbColor = new RgbColorClass();
pRgbColor.Red = 255;
pRgbColor.Green = 255;
pRgbColor.Blue = 0;

pRgbColor.Transparency = 1;
ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = pRgbColor;
pRgbColor.Transparency = 1;
pLineSymbol.Color = pRgbColor;
pLineSymbol.Width = 0;
pFillSymbol.Outline = pLineSymbol;
ISimpleRenderer pSimpleRender = new SimpleRendererClass();
pSimpleRender.Symbol = pFillSymbol as ISymbol;
IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer asIGeoFeatureLayer;
pGeoFeatureLayer.Renderer = pSimpleRender asIFeatureRenderer;
pFeatureLayer = pGeoFeatureLayer as IFeatureLayer;

axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}
}

}

  

爱华网本文地址 » http://www.aihuau.com/a/25101012/106364.html

更多阅读

驱动加载失败怎么解决? 代练猫加载驱动失败

源:U大师当我们想要重新去更新加载驱动,难免会遇到驱动加载失败的情况,此时该如何处理?今天小编就来教大家在驱动出现加载失败时如何解决的方法。故障原因一、驱动加载失败可能原因是驱动程序本身不完全,其次就是在下载更新

加载SolidWorks宏格式*.swb 模型文件 solidworks人体3d模型

加载SolidWorks宏格式(*.swb)模型文件——简介由LinkAble PARTcommunity下载的SolidWorks模型文件,由包含SolidWorks宏文件(SWB扩展名)的ZIP压缩包提供,请按照如下方法加载模型数据。SWB文件的优势,不丢失螺纹、色彩和装配等特征,且文件容

ExtJS中FormPanel实现数据加载和提交 extjs3 formpanel

在使用使用FormPanel时我们通常需要使用它的form对象来加载数据或提交数据。FormPanel中的 form对象为Ext.form.BasicForm类型的对象,它有load和submit方法分别用于加载数据和提交数据。而这两个方法都是通过调用 Ext.form.BasicForm

加载宏Addin 使用方法 2010加载宏怎么使用

Office VBA Addin加载宏是一种使用VBA编写的程序,它通过加载设置,可以随Office程序启动而自动加载运行,是制作Excel自定义函数、Office菜单和功能区按钮、添加常用辅助功能的常用载体。在Excel、PPT中都可以编制加载宏文件,Word则可以

声明:《arcengine不同数据的加载处理 arcengine 镶嵌数据集》为网友温柔姐分享!如侵犯到您的合法权益请联系我们删除