/// <summary>
/// 打开shp
/// </summary>
/// <param name="shpfile"></param>
/// <returns></returns>
private IFeatureLayer openShpLayer(string shpfile)
{
string path = shpfile;
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
//由于shp文件的特殊性,要通过文件名和文件路径获取
string pFilePath = System.IO.Path.GetDirectoryName(path);
string pFileName = System.IO.Path.GetFileName(path);
//打开工作空间
IFeatureWorkspace pFeaWorkspace = pWorkspaceFactory.OpenFromFile(pFilePath, 0) as IFeatureWorkspace;
//创建并实例化要素集
IFeatureClass pFeatureClass = pFeaWorkspace.OpenFeatureClass(pFileName); //打开文件
//将要素添加到显示
IFeatureLayer pFeatureLyr = new FeatureLayer();
pFeatureLyr.FeatureClass = pFeatureClass;
pFeatureLyr.Name = pFileName;
return pFeatureLyr;
}
打开shp文件
最新推荐文章于 2024-09-26 18:19:52 发布