如何打开磁盘上的shapefile文件

/// <summary>
/// Get the FeatureClass from a Shapefile on disk (hard drive).
/// </summary>
/// <param name="string_ShapefileDirectory">A System.String that is the directory where the shapefile is located. Example: "C:dataUSA"</param>
/// <param name="string_ShapefileName">A System.String that is the shapefile name. Note: the shapefile extension's (.shp, .shx, .dbf, etc.) is not provided! Example: "States"</param>
/// <returns>An IFeatureClass interface. Nothing (VB.NET) or null (C#) is returned if unsuccessful.</returns>
/// <remarks></remarks>

esri官网上抄来的文档
 1 public ESRI.ArcGIS.Geodatabase.IFeatureClass GetFeatureClassFromShapefileOnDisk(System.String string_ShapefileDirectory, System.String string_ShapefileName)
 2 {
 3 
 4     System.IO.DirectoryInfo directoryInfo_check = new System.IO.DirectoryInfo(string_ShapefileDirectory);
 5     if (directoryInfo_check.Exists)
 6     {
 7 
 8         //We have a valid directory, proceed
 9 
10         System.IO.FileInfo fileInfo_check = new System.IO.FileInfo(string_ShapefileDirectory + "\" + string_ShapefileName + ".shp");
11         if (fileInfo_check.Exists)
12         {
13 
14             //We have a valid shapefile, proceed
15 
16             ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
17             ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.OpenFromFile(string_ShapefileDirectory, 0);
18             ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explict Cast
19             ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(string_ShapefileName);
20 
21             return featureClass;
22         }
23         else
24         {
25 
26             //Not valid shapefile
27             return null;
28         }
29 
30     }
31     else
32     {
33 
34         // Not valid directory
35         return null;
36 
37     }
38     
39 }
原文地址:https://www.cnblogs.com/353373440qq/p/3629236.html