/* 说明:C#中添加多个shp文件,默认对象为axMap1,如果名称改变,秩序修改最后一句即可 注:需要引用System.Windows.Forms、System.IO和ESRI.MapObjects2.Core; */
/*
说明:C#中添加多个shp文件,默认对象为axMap1,如果名称改变,秩序修改最后一句即可
注:需要引用System.Windows.Forms、System.IO和ESRI.MapObjects2.Core;
*/
public void AddShpFile()
{
string FilePath ;//定义文件路径
DataConnection dc=new DataConnectionClass();//定义连接
MapLayer layer = null;
ESRI.MapObjects2.Core.GeoDataset gds = null;
OpenFileDialog openShpFile = new OpenFileDialog();
openShpFile.Multiselect=true;
openShpFile.Filter="shp文件(*.shp)|*.shp";
openShpFile.RestoreDirectory=true;
if( openShpFile.ShowDialog() == DialogResult.OK )
{
if(( openShpFile.OpenFile()) != null )
{
string[] fileNames=openShpFile.FileNames;
FilePath=Path.GetDirectoryName(fileNames[0]);
dc.Database=FilePath;
dc.Connect();
if (dc.Connected == true)
{
foreach( string shpFileWithPath in fileNames )
{
gds = dc.FindGeoDataset(Path.GetFileNameWithoutExtension(shpFileWithPath));
if ( gds != null )
{
layer = new MapLayerClass();
layer.GeoDataset = gds;
axMap1.Layers.Add ( layer );
}
}
}
}
}
}
本文介绍如何使用C#编程语言批量加载多个shp文件到地图应用中。通过使用ESRI.MapObjects2.Core库,文章提供了一个示例代码,展示了如何通过对话框选择多个shp文件,并将它们作为图层添加到地图上。
5178

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



