Arcengine + C# 打开一个固定位置的shapefile的代码。。谢谢
2个回答
展开全部
/// <summary>
/// 打开Layer文件
/// </summary>
/// <param name="aFileName">要打开Shape文件的全路径</param>
/// <param name="axMapControl"></param>
public void OpenFile_LayerFile(string aFileName, AxMapControl axMapControl)//打开shapefile文件
{
string fullPath;
string path;//路径
string fileName;//文件名
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
fullPath = aFileName;
path = System.IO.Path.GetDirectoryName(fullPath);//路径
fileName = System.IO.Path.GetFileName(fullPath);//文件名
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(fileName);
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureClass;
pFeatureLayer.Name = pFeatureClass.AliasName;
ILayer pLayer = pFeatureLayer as ILayer;
axMapControl.Map.AddLayer(pLayer);
axMapControl.ActiveView.Refresh();
}
希望对你有帮助!
/// 打开Layer文件
/// </summary>
/// <param name="aFileName">要打开Shape文件的全路径</param>
/// <param name="axMapControl"></param>
public void OpenFile_LayerFile(string aFileName, AxMapControl axMapControl)//打开shapefile文件
{
string fullPath;
string path;//路径
string fileName;//文件名
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
fullPath = aFileName;
path = System.IO.Path.GetDirectoryName(fullPath);//路径
fileName = System.IO.Path.GetFileName(fullPath);//文件名
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(fileName);
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureClass;
pFeatureLayer.Name = pFeatureClass.AliasName;
ILayer pLayer = pFeatureLayer as ILayer;
axMapControl.Map.AddLayer(pLayer);
axMapControl.ActiveView.Refresh();
}
希望对你有帮助!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询