C# AE 通过要素类工作空间将shp路径string类型对象转换为IFeatureClass;

こ雲淡風輕ζ 提交于 2019-12-06 09:59:42

IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();//打开shapefile工作空间
openFileDialog1.Filter = ("shapefile文件(*.shp)|*.shp");//文件过滤
openFileDialog1.InitialDirectory=@"C:\Program Files\ARCGIS\GIS-Data";//默认路径吧
openFileDialog1.Multiselect = false;//只能单选
DialogResult pDialogResult = openFileDialog1.ShowDialog();
if (pDialogResult != DialogResult.OK)
return;//如果没点击确认 ,返回
string pPath = openFileDialog1.FileName;//获得文件的路径
string pFloder = Path.GetDirectoryName(pPath);//得到文件所在的文件夹位置
string pFileName = Path.GetFileName(pPath);//得到文件名
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFloder, 0);//打开工作空间
IFeatureWorkspace pFeatureWokkspace = pWorkspace as IFeatureWorkspace;//转换工作空间为要素工作空间
IFeatureClass pFC = pFeatureWokkspace.OpenFeatureClass(pFileName);//打开要素类
IFeatureLayer pFLayer = new FeatureLayerClass();
pFLayer.FeatureClass = pFC;//设置图层的featureclass为上面打开的文件
pFLayer.Name = pFC.AliasName;//设置图层的名称
ILayer pLayer = pFLayer as ILayer;//转换featurelayer为layer
IMap pMap = axMapControl1.Map;
pMap.AddLayer(pLayer);//添加图层
axMapControl1.ActiveView.Refresh();//刷新

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!