C#AE加载shp文件

 using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "矢量数据(*.shp)|*.shp";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
 


                    string fullFilePath = ofd.FileName;
                    int index = fullFilePath.LastIndexOf("\\");
                    //获得文件路径
                    string filePath = fullFilePath.Substring(0, index);
                    //获得文件名
                    string fileName = fullFilePath.Substring(index + 1);

                    IWorkspaceFactory workspcFac = new ShapefileWorkspaceFactory();
                    IFeatureWorkspace featureWorkspace;
                    IFeatureLayer featureLayer = new FeatureLayerClass();
                    //打开路径
                    featureWorkspace = workspcFac.OpenFromFile(filePath,0) as IFeatureWorkspace;
                    //打开类要素
                    featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(fileName);
                    featureLayer.Name = fileName;
                    mapControl.AddLayer(featureLayer);

                   //刷新

                    mapControl.Refresh();
                }
            }

猜你喜欢

转载自blog.csdn.net/qq_38370387/article/details/89144654
今日推荐