【引用】C# +AE加载shp、栅…

//添加ArcGIS命名空间

using ESRI.ArcGIS.Carto;

using ESRI.ArcGIS.Geometry;

using ESRI.ArcGIS.Geodatabase;

using ESRI.ArcGIS.DataSourcesFile;

using ESRI.ArcGIS.DataSourcesRaster;

//存储打开文件的全路径

        string fullFilePath;

//设置OpenFileDialog的属性,使其能打开多种类型文件

            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter = "shape文件(*.shp)|*.shp|";

openFile.Filter +="栅格数据(*.jpg,*.bmp,*.tiff)|*.jpg;*.bmp;*.tiff|";

openFile.Filter +="地图文档(*.mxd,*.mxt,*.jmf)|*.mxd;*.mxt;*.jmf";

            openFile.Title = "打开文件";

          

            try

            {

                if (openFile.ShowDialog() == DialogResult.OK)

                {

                  

                    fullFilePath = openFile.FileName;

                    //获得文件路径

                    int index = fullFilePath.LastIndexOf("");

                    string filePath = fullFilePath.Substring(0, index);

                    //获得文件名称

                    string fileNam = fullFilePath.Substring(index + 1);

                    //加载shape文件

                    if (openFile.FilterIndex == 1)

                    {

                        //打开工作空间工厂

                        IWorkspaceFactory workspcFac = new ShapefileWorkspaceFactory();

                        IFeatureWorkspace featureWorkspc;

                        IFeatureLayer featureLay = new FeatureLayerClass();

                        //打开路径

                featureWorkspc = workspcFac.OpenFromFile(filePath, 0) as IFeatureWorkspace;

                        //打开类要素

                        featureLay.FeatureClass = featureWorkspc.OpenFeatureClass(fileNam);

                        //清空图层

                        axMapControl1.ClearLayers();

                        //添加图层

                        axMapControl1.AddLayer(featureLay);

                        axMapControl1.Refresh();

                    }

                        //加载栅格图像

                    else if (openFile.FilterIndex == 2)

                    {

                        IWorkspaceFactory workspcFac = new RasterWorkspaceFactory();

                        IRasterWorkspace rasterWorkspc;

                        IRasterDataset rasterDatst = new RasterDatasetClass();

                        IRasterLayer rasterLay = new RasterLayerClass();

                 rasterWorkspc = workspcFac.OpenFromFile(filePath, 0) as IRasterWorkspace;

                        rasterDatst = rasterWorkspc.OpenRasterDataset(fileNam );

                        rasterLay.CreateFromDataset(rasterDatst);

                        axMapControl1.ClearLayers();

                        axMapControl1.AddLayer(rasterLay);

                        axMapControl1.Refresh();

                    }

                    //加载地图文档

                    else if (openFile.FilterIndex == 3)

                    {

                        IMapDocument mapDoc = new MapDocumentClass();

                        mapDoc.Open(filePath ,"");

                        axMapControl1.ClearLayers();

                        for (int i = 0; i < mapDoc.MapCount - 1; i++)

                        {

                            axMapControl1.Map =mapDoc.get_Map (i);

                        }

                        IActiveView activeViw = axMapControl1.Map as IActiveView;

                        activeViw.Extent = axMapControl1.FullExtent;

                        axMapControl1.Refresh();

                    }

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message.ToString ());

            }

        }

    }




引文来源    C# +AE加载shp、栅格、地图文档数据 -ArcGIS家园
<script type="text/javascript" id="wumiiRelatedItems"> </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值