获取FeatureClass

1.从shape文件获取FeatureClass
 1 /// <summary>
 2 /// 读取shape文件为FeatureClass
 3 /// </summary>
 4 ///Example: shape文件路径:C:\data\USA\States.shp                      
 5 /// <param name="string_ShapefileDirectory">shape文件的目录. 此处: "C:\data\USA"</param>
 6 /// <param name="string_ShapefileName">shape文件的名字,不包括后缀,后缀大家都知道是shp. 此处: "States"</param>
 7 /// <returns>返回FeatureClass接口</returns>
 8 /// <remarks></remarks>
 9 public ESRI.ArcGIS.Geodatabase.IFeatureClass GetFeatureClassFromShapefileOnDisk(System.String string_ShapefileDirectory, System.String string_ShapefileName)
10 {
11     System.IO.DirectoryInfo directoryInfo_check = new System.IO.DirectoryInfo(string_ShapefileDirectory);
12     if (directoryInfo_check.Exists)
13     {
14         //We have a valid directory, proceed
15         System.IO.FileInfo fileInfo_check = new System.IO.FileInfo(string_ShapefileDirectory + "\\" + string_ShapefileName + ".shp");
16         if (fileInfo_check.Exists)
17         {
18             //We have a valid shapefile, proceed
19 
20             ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
21             ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.OpenFromFile(string_ShapefileDirectory, 0);
22             ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explict Cast
23             ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(string_ShapefileName);
24 
25             return featureClass;
26         }
27         else
28         {
29             //Not valid shapefile
30             return null;
31         }
32     }
33     else
34     {
35         // Not valid directory
36         return null;
37     }    
38 }

源:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//00490000008m000000


2.从FeatureLayer选中要素获取FeatureClass
 1 ///<summary>Returns a reference to the currently selected featureclass from the given contents view.从当前内容视图中选中的要素返回要素类的引用</summary>
 2 ///  
 3 ///<param name="currentContentsView">An IContentsView interface.内容视图接口</param>
 4 ///  
 5 ///<returns>An IFeatureClass interface or Nothing if not found.返回值</returns>
 6 ///   
 7 ///<remarks></remarks>
 8 public ESRI.ArcGIS.Geodatabase.IFeatureClass GetFeatureClassOfSelectedFeatureLayerInContentsView(ESRI.ArcGIS.ArcMapUI.IContentsView currentContentsView)
 9 {
10   if (currentContentsView == null)
11   {
12     return null;
13   }
14   if (currentContentsView.SelectedItem is ESRI.ArcGIS.Carto.IFeatureLayer)
15   {
16     ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)currentContentsView.SelectedItem; // Explicit Cast
17     ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;
18 
19     return featureClass;
20   }
21   return null;
22 }

 

源:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_FeatureClass_of_Selected_Feature_Layer_in_Contents_View_Snippet/00490000004r000000/



3.从Personal Geodatabase获取FeatureClass


4.从File Geodatabase获取FeatureClass

5.从SDE获取FeatureClass



posted @ 2016-09-04 10:52  道义相勖  Views(1871)  Comments(0Edit  收藏  举报