Skip to main content

ListDatasets

汇总

返回当前工作空间中的数据集的列表。 可针对数据集名称和数据集类型指定搜索条件,从而限制返回的列表。

讨论

必须先设置工作空间环境,然后才能使用多个列表函数,包括 ListDatasetsListFeatureClassesListFilesListRastersListTablesListWorkspaces

语法

ListDatasets({wild_card}, {feature_type})

参数 说明 数据类型

wild_card

限制返回的结果。如果未指定某一值,则返回所有值。通配符不区分大小写。

符号

说明

示例

*

表示零个或多个字符。

Te* 可找到田纳西州和德克萨斯州。

*

feature_type

Specifies the type of dataset that will be returned.

  • Coverage—Coverages will be returned.

  • Feature—Coverages or geodatabase datasets will be returned, depending on the workspace.

  • GeometricNetwork—Geometric network datasets will be returned.

  • LasDataset—LAS datasets will be returned.

  • Mosaic—Mosaic datasets will be returned.

  • Network—Network datasets will be returned.

  • ParcelFabric—Parcel fabric datasets will be returned.

  • ParcelFabricForArcmap—ArcMap parcel fabric datasets will be returned.

  • Raster—Raster datasets will be returned.

  • RasterCatalog—Raster catalog datasets will be returned.

  • Terrain—Terrain datasets will be returned.

  • Tin—TIN datasets will be returned.

  • Topology—Topology datasets will be returned.

  • TraceNetwork—Trace network datasets will be returned.

  • UtilityNetwork—Utility network datasets will be returned.

  • All—All datasets in the workspace will be returned.

(默认值为 All)

String

返回值

数据类型 说明

String

该函数返回包含数据集名称的列表,该列表受通配符和要素类型参数限制。

代码示例

ListDatasets 示例

列出以 C 开头的要素数据集名称。

import arcpy

arcpy.env.workspace = "c:/data"

# Print all the feature datasets in the workspace that start with the letter C.
datasets = arcpy.ListDatasets("C*", "Feature")

for dataset in datasets:
    print(dataset)
ListDatasets 示例 2

列出以 c 或 f 开头、以 c 以外的其他字母开头或同时包含 c 和 f 的要素数据集名称。

import arcpy
arcpy.env.workspace = 'c:/data'

# Print all the feature datasets in the workspace that start with the letter c
# or f.
datasets1 = list(set(arcpy.ListDatasets("c*", "Feature")) |
                 set(arcpy.ListDatasets("f*", "Feature")))
print(datasets1)

# Print all the feature datasets in the workspace that start with the letters
# except c.
datasets2 = list(set(arcpy.ListDatasets("*", "Feature")) -
                 set(arcpy.ListDatasets("c*", "Feature")))
print(datasets2)

# Print all the feature datasets in the workspace that contain both the letter c
# and f.
datasets3 = list(set(arcpy.ListDatasets("*c*", "Feature")) &
                 set(arcpy.ListDatasets("*f*", "Feature")))
print(datasets3)
ListDatasets 示例 3

使用 feature_type 关键字参数列出追踪网络数据集。

import arcpy

arcpy.env.workspace = 'c:/data/myGDB.gdb/TN_dataset'

# Print all the trace networks in the workspace.
datasets = arcpy.ListDatasets(feature_type="tracenetwork")
for dataset in datasets:
    print(dataset)
ListDatasets 示例 4

使用位置参数列出地理数据库中的栅格数据集。

import arcpy

arcpy.env.workspace = 'c:/data/mySQLserver.sde'

# Print all the raster datasets in the workspace.
datasets = arcpy.ListDatasets("", "Raster")
for dataset in datasets:
    print(dataset)
ListDatasets 示例 5

列出企业级地理数据库中所有者为特定用户的要素数据集。

import arcpy
arcpy.env.workspace = 'c:/data/mySQLserver.sde'

# Print all the feature datasets owned by 'user1' in the enterprise gdb
datasets = arcpy.ListDatasets("user1*", "Feature")
for dataset in datasets:
    print(dataset)