Shape数据加载(同时打开多个文件)

 
OpenFileDialog dlg=new OpenFileDialog();
   dlg.Filter="Shape file(*.shp)|*.shp";
   dlg.Title="打开Shape数据文档";
   dlg.Multiselect=true;
   //定义存放打开IFeatureClass的字符串数组
   string[] FilePath;
   if(dlg.ShowDialog()==DialogResult.OK)
   {
   FilePath=new string[dlg.FileNames.Length];
   FilePath=dlg.FileNames;
   if(FilePath.Length > 0)
   {
   string WorkSpacePath =System.IO.Path.GetDirectoryName(FilePath[0]);
   string[] ShapeFilePath=new string[FilePath.Length] ;
   //获得打开IFeatureClass的字符串数组
   for(int i=0;i<FilePath.Length;i++)
   {
   ShapeFilePath[i]=System.IO.Path.GetFileName(FilePath[i]);
   }
   IWorkspaceFactory pWorkspaceFactory=new ShapefileWorkspaceFactoryClass();
   IWorkspace pWorkspace=pWorkspaceFactory.OpenFromFile(WorkSpacePath,0);
   IFeatureWorkspace pFeatureWorkspace=pWorkspace as IFeatureWorkspace;
   for(int i=0;i<ShapeFilePath.Length;i++)
   {
   IFeatureClass pFeatureClass=pFeatureWorkspace.OpenFeatureClass(ShapeFilePath[i]);
   IDataset pDataset=pFeatureClass as IDataset;
   IFeatureLayer pFeatureLayer=new FeatureLayerClass();
   pFeatureLayer.FeatureClass=pFeatureClass;
   pFeatureLayer.Name=pDataset.Name;
   ILayer pLayer=pFeatureLayer as ILayer;
   this.axMapControl2.Map.AddLayer(pLayer);
    }
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值