c#+mo2.3添加多个shp文件

本文介绍如何使用C#编程语言批量加载多个shp文件到地图应用中。通过使用ESRI.MapObjects2.Core库,文章提供了一个示例代码,展示了如何通过对话框选择多个shp文件,并将它们作为图层添加到地图上。

/*   说明: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 );

       }  

      }            

     }     

    }

   }  

  }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值