VB.NET对抗ArcGIS 10.1 我有一个函数可以在geodb中搜索要素类名称。如果找到我想显示它的位置。目前我只返回FeatureClass对象,如下所示:
Dim fcTest As IFeatureClass = FindFeatureClassByName(pWorkspace, fcName)
它工作得很好,但现在我想显示要素类对象的完整目录路径。那可能吗?我一直在找几个小时,但似乎无法做到。要素类可以存在于要素数据集中。因此要素类可以位于
之类的位置 E:\Batch\Delivered.gdb\Bridges
D:\Data\Final\Infrastructure.gdb\EastValley\powerlines
C:/projects/RedRiverBasin/data.mdb/streams
C:/projects/Airports/USA.mdb/West/lax
这些信息是否包含在FeatureClass对象中,还是我必须调整我的功能?
我试过
Dim pDataset As IDataset = CType(fcTest, IDataset)
但是pDataset.Name只是要素类的名称,而不是完整的目录路径和名称,包括任何要素数据集(如果它位于其中)。
答案 0 :(得分:0)
找到了一个解决方案,它非常简单:
''' <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