我正在尝试使用vba / arcobjects枚举文件地理数据库的内容(要素类和要素数据集,对表等不感兴趣)。
我将文件GDB设置为IGxDatabase对象,但无法找到进一步的方法。我已经看过地理数据库对象模型并尝试使用IFeatureClass和IFeatureDataset但似乎都没有返回有用的结果
提前感谢您的任何帮助
答案 0 :(得分:6)
枚举地理数据库中包含的名称要快得多,而不是名称可以打开的名称。棘手的部分是在特色广告中循环显示名称。虽然可以使用IFeatureWorkspace.Open打开一个功能类而无需先打开包含它的featureataset,但获取featureataset中的featureclassnames需要打开featureataset。
如果你确定你需要打开每个功能类,那么我认为使用IWorkspace.Datasets,IEnumDataset和IDataset而不是IWorkspaceDatasetNames,IEnumDatasetname和IDatasetname都没有坏处。
Option Explicit
Sub TestGetContents()
Dim pGxApp As IGxApplication
Set pGxApp = Application
If Not TypeOf pGxApp.SelectedObject Is IGxDatabase Then
Debug.Print "select a geodb first"
Exit Sub
End If
Dim c As Collection
Set c = GetContents(pGxApp.SelectedObject)
Dim l As Long
For l = 1 To c.Count
Dim pName As IName
Set pName = c.Item(l)
If TypeOf pName Is IFeatureClassName Then
Dim pFC As IFeatureClass
Set pFC = pName.Open
Debug.Print pFC.AliasName, pFC.FeatureCount(Nothing)
ElseIf TypeOf pName Is IFeatureDatasetName Then
Dim pDSName As IDatasetName
Set pDSName = pName
Debug.Print pDSName.name, "(featuredataset)"
End If
Next l
End Sub
Function GetContents(pGxDB As IGxDatabase) As Collection
Dim c As New Collection
Dim pEnumDSName As IEnumDatasetName
Set pEnumDSName = pGxDB.Workspace.DatasetNames(esriDTAny)
Dim pDSName As IDatasetName
Set pDSName = pEnumDSName.Next
Do Until pDSName Is Nothing
If TypeOf pDSName Is IFeatureClassName Then
c.Add pDSName
ElseIf TypeOf pDSName Is IFeatureDatasetName Then
c.Add pDSName
AddSubNames pDSName, c
End If
Set pDSName = pEnumDSName.Next
Loop
Set GetContents = c
End Function
Sub AddSubNames(pDSName1 As IDatasetName, c As Collection)
Dim pEnumDSName As IEnumDatasetName
Set pEnumDSName = pDSName1.SubsetNames
pEnumDSName.Reset
Dim pDSName2 As IDatasetName
Set pDSName2 = pEnumDSName.Next
Do Until pDSName2 Is Nothing
If TypeOf pDSName2 Is IFeatureClassName Then
c.Add pDSName2
End If
Set pDSName2 = pEnumDSName.Next
Loop
End Sub
答案 1 :(得分:0)
您可以在地理处理器上使用ListFeatureClasses方法 (以下显示了如何在C#中完成此操作)
IGeoProcessor gp = new GeoProcessorClass();
gp.SetEnvironmentValue("workspace", @"C:\temp");
IGpEnumList gpEnumList = gp.ListFeatureClasses("*", "Polygon", "");
string fc = gpEnumList.Next();
while (fc != "")
{
//Do whatever
}