I just started out with ArcObjects and I've been stuck on this for days.How do you open up a File GDB and read out a simple feature class?
The snippet for retreiving a shapefile from a regular forlder on disk works, and I suppose I can use the same code but with a different kind of workspace?
Any help?
''' ''' Get the FeatureClass from a Shapefile on disk (hard drive).''' ''' A System.String that is the directory where the shapefile is located. Example: "C:\data\USA"''' A System.String that is the shapefile name. Note: the shapefile extension's (.shp, .shx, .dbf, etc.) is not provided! Example: "States"''' An IFeatureClass interface. Nothing (VB.NET) or null (C#) is returned if unsuccessful.''' Public Function GetFeatureClassFromShapefileOnDisk(ByVal string_ShapefileDirectory As System.String, ByVal string_ShapefileName As System.String) As ESRI.ArcGIS.Geodatabase.IFeatureClass Dim directoryInfo_check As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(string_ShapefileDirectory) If directoryInfo_check.Exists Then 'We have a valid directory, proceed Dim fileInfo_check As System.IO.FileInfo = New System.IO.FileInfo(string_ShapefileDirectory + "\" + string_ShapefileName + ".shp") If fileInfo_check.Exists Then 'We have a valid shapefile, proceed Dim workspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass Dim workspace As ESRI.ArcGIS.Geodatabase.IWorkspace = workspaceFactory.OpenFromFile(string_ShapefileDirectory, 0) Dim featureWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace = CType(workspace, ESRI.ArcGIS.Geodatabase.IFeatureWorkspace) ' Explict Cast Dim featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass = featureWorkspace.OpenFeatureClass(string_ShapefileName) Return featureClass Else 'Not valid shapefile Return Nothing End If Else ' Not valid directory Return Nothing End IfEnd FunctionThanks in advance!
أكثر...
The snippet for retreiving a shapefile from a regular forlder on disk works, and I suppose I can use the same code but with a different kind of workspace?
Any help?
''' ''' Get the FeatureClass from a Shapefile on disk (hard drive).''' ''' A System.String that is the directory where the shapefile is located. Example: "C:\data\USA"''' A System.String that is the shapefile name. Note: the shapefile extension's (.shp, .shx, .dbf, etc.) is not provided! Example: "States"''' An IFeatureClass interface. Nothing (VB.NET) or null (C#) is returned if unsuccessful.''' Public Function GetFeatureClassFromShapefileOnDisk(ByVal string_ShapefileDirectory As System.String, ByVal string_ShapefileName As System.String) As ESRI.ArcGIS.Geodatabase.IFeatureClass Dim directoryInfo_check As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(string_ShapefileDirectory) If directoryInfo_check.Exists Then 'We have a valid directory, proceed Dim fileInfo_check As System.IO.FileInfo = New System.IO.FileInfo(string_ShapefileDirectory + "\" + string_ShapefileName + ".shp") If fileInfo_check.Exists Then 'We have a valid shapefile, proceed Dim workspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass Dim workspace As ESRI.ArcGIS.Geodatabase.IWorkspace = workspaceFactory.OpenFromFile(string_ShapefileDirectory, 0) Dim featureWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace = CType(workspace, ESRI.ArcGIS.Geodatabase.IFeatureWorkspace) ' Explict Cast Dim featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass = featureWorkspace.OpenFeatureClass(string_ShapefileName) Return featureClass Else 'Not valid shapefile Return Nothing End If Else ' Not valid directory Return Nothing End IfEnd FunctionThanks in advance!
أكثر...