ArcObjects - 枚举地理数据库中的要素类和数据集

发布于 2024-08-26 13:48:30 字数 196 浏览 7 评论 0原文

我正在尝试使用 vba/arcobjects 枚举文件地理数据库的内容(要素类和要素数据集,对表不感兴趣等)。

我将文件 GDB 设置为 IGxDatabase 对象,但找不到进一步深入的方法。我查看了地理数据库对象模型并尝试使用 IFeatureClass 和 IFeatureDataset,但似乎都没有返回有用的结果。

预先感谢您的任何帮助

I'm trying to enumerate the contents (feature classes and feature datasets, not interested in tables, etc) of a file geodatabase using vba/arcobjects.

I have the file GDB set as an IGxDatabase object, but can't find a way of getting further in. I've had a look at the geodatabase object model and tried using IFeatureClass and IFeatureDataset but neither seem to return useful results.

Thanks in advance for any assistance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

四叶草在未来唯美盛开 2024-09-02 13:48:30

枚举地理数据库中包含的名称比枚举名称可以打开的内容要快得多。棘手的部分是循环遍历特征数据集中的名称。虽然 IFeatureWorkspace.Open 可用于打开要素类,而无需先打开包含它的要素数据集,但获取要素数据集中的要素类名称需要打开要素数据集。

如果您确定需要打开每个要素类,那么我想使用 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

函数 GetContents(pGxDB As IGxDatabase) 作为集合 Dim c 作为新系列 Dim pEnumDSName As IEnumDatasetName 设置 pEnumDSName = pGxDB.Workspace.DatasetNames(esriDTAny) Dim pDSName As IDatasetName 设置 pDSName = pEnumDSName.Next 执行直至 pDSName 为空 如果 TypeOf pDSName 是 IFeatureClassName 那么 c.添加pDSName ElseIf TypeOf pDSName 是 IFeatureDatasetName 那么 c.添加pDSName AddSubNames pDSName, c 结束如果 设置 pDSName = pEnumDSName.Next 环形 设置 GetContents = c End Function

Sub AddSubNames(pDSName1 As IDatasetName, c As Collection) Dim pEnumDSName As IEnumDatasetName 设置 pEnumDSName = pDSName1.SubsetNames pEnumDSName.重置 将 pDSName2 调暗为 IDatasetName 设置 pDSName2 = pEnumDSName.Next 执行此操作直至 pDSName2 不再存在 如果 TypeOf pDSName2 是 IFeatureClassName 那么 c.添加pDSName2 结束如果 设置 pDSName2 = pEnumDSName.Next 环形 结束子

It is much faster to enumerate the names contained in a geodatabase instead of the things that the names can open. The tricky part is looping through names in a featuredataset. While IFeatureWorkspace.Open can be used to open a featureclass without first opening the featuredataset that contains it, getting at featureclassnames within a featuredataset requires opening the featuredataset.

If you know for sure you'll need to open each featureclass, then I suppose it wouldn't hurt to use IWorkspace.Datasets, IEnumDataset, and IDataset instead of IWorkspaceDatasetNames, IEnumDatasetname and 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

凶凌 2024-09-02 13:48:30

您可以在地理处理器上使用 ListFeatureClasses 方法
(下面展示了如何在 C# 中完成此操作)

IGeoProcessor gp = new GeoProcessorClass(); 

gp.SetEnvironmentValue("workspace", @"C:\temp"); 

IGpEnumList gpEnumList = gp.ListFeatureClasses("*", "Polygon", ""); 
string fc = gpEnumList.Next(); 
while (fc != "") 
{ 
//Do whatever
}

you can use the ListFeatureClasses Method on the Geoprocessor
(the following shows how this can be done in C#)

IGeoProcessor gp = new GeoProcessorClass(); 

gp.SetEnvironmentValue("workspace", @"C:\temp"); 

IGpEnumList gpEnumList = gp.ListFeatureClasses("*", "Polygon", ""); 
string fc = gpEnumList.Next(); 
while (fc != "") 
{ 
//Do whatever
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文