VB.NET 反对 ArcGIS 10.1 我有一个函数,可以在地理数据库中搜索要素类名称。如果找到,我想显示找到它的位置。目前我只返回要素类对象,如下所示:
Dim fcTest As IFeatureClass = FindFeatureClassByName(pWorkspace, fcName)
它工作得很好,但现在我想显示要素类对象的完整目录路径。这可能吗?我一直在寻找几个小时,但似乎做不到。要素类可以存在于要素数据集中。因此,要素类可能位于以下位置
E:BatchDelivered.gdbBridges
D:DataFinalInfrastructure.gdbEastValleypowerlines
C:/projects/RedRiverBasin/data.mdb/streams
C:/projects/Airports/USA.mdb/West/lax
该信息是否包含在要素类对象中,或者我是否必须调整我的函数?
我试过了
Dim pDataset As IDataset = CType(fcTest, IDataset)
但 pDataset.Name 只是要素类的名称,而不是完整的目录路径和名称(包括任何要素数据集((如果位于该位置(。
找到了一个解决方案,它相当简单:
''' <summary>
''' this routine will return the full catalog path and name of a feature class.
''' </summary>
''' <param name="pFeatClass">the feature class object</param>
''' <returns>a string representing the catalog path of the feature class</returns>
''' <remarks>https://geonet.esri.com/thread/4280</remarks>
Public Function GetCatalogPath(ByVal pFeatClass As IFeatureClass) As String
Try
'check for valid object
If pFeatClass Is Nothing Then Return Nothing
'cast to dataset and get workspace
Dim pDataset As IDataset = CType(pFeatClass, IDataset)
Dim pWksp As IWorkspace = pDataset.Workspace
'the full path may be in a fetaure dataset so check it
Dim pFeatDs As IFeatureDataset = pFeatClass.FeatureDataset
If pFeatDs Is Nothing Then
Return System.IO.Path.Combine(pWksp.PathName, pDataset.Name)
Else
Return System.IO.Path.Combine(pWksp.PathName, pFeatDs.Name, pDataset.Name)
End If
Catch ex As Exception
Return Nothing
End Try
End Function