一、shp文件的加载:
IWorkspaceFactory pWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
//获取当前路径和文件名
OpenFileDialog dlg=new OpenFileDialog();
dlg.ShowDialog();
string strFullPath=dlg.FileName;
if(strFullPath=="") return;
int Index=strFullPath.LastIndexOf("//");
string filePath=strFullPath.Substring(0,Index);
string fileName=strFullPath.Substring(Index+1);
//打开工作空间并添加shp文件
pWorkspaceFactory=new
ShapefileWorkspaceFactoryClass();
//注意此处的路径是不能带文件名的
pFeatureWorkspace=(IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath,0);
pFeatureLayer=new FeatureLayerClass();
//注意这里的文件名是不能带路径的
pFeatureLayer.FeatureClass=pFeatureWorkspace.OpenFeatureClass(fileName);
pFeatureLayer.Name =
pFeatureLayer.FeatureClass.AliasName;
axMapControl1.Map.AddLayer(pFeatureLayer);</

本文详细介绍了如何使用ArcGIS Engine加载不同类型的数据,包括shp文件、个人数据库、CAD文件和栅格数据。通过OpenFileDialog选择文件路径,利用各种WorkspaceFactory打开工作空间,并将数据加载到MapControl中展示。
最低0.47元/天 解锁文章
3740

被折叠的 条评论
为什么被折叠?



