private void iWorkSpaceToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "加载shapefile数据";//设置title
openFileDialog.Filter = "(*.shp)|*.shp";//设置过滤模式
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//设置路径
string fullPath = openFileDialog.FileName;//全部路径
string path = fullPath.Substring(0, fullPath.LastIndexOf("\\"));//截取字符串:除了名称之前的数据
string name = fullPath.Substring(fullPath.LastIndexOf("\\") + 1);//一直截取到末尾
}
IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace featureworkspace = workspaceFactory.OpenFromFile(path, 0) as IFeatureWorkspace;
IFeatureLayer featurelayer = new FeatureLayerClass();
featurelayer.FeatureClass = featureworkspace.OpenFeatureClass(name);
featurelayer.Name = featurelayer.FeatureClass.AliasName;
if (MessageBox.Show("要素类已打开,名称为"+featurelayer.Name+",是否加载进地图?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
{
MapControl.AddLayer(featurelayer);
MapControl.Refresh();
}
}
07-31
511
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-25
1185
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交