ListDatasets

摘要

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

说明

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

语法

ListDatasets ({wild_card}, {feature_type})
参数说明数据类型
wild_card

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

符号说明示例

*

表示零个或多个字符。

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

String
feature_type

The type of dataset that will be returned.

  • CoverageOnly coverages.
  • FeatureCoverage or geodatabase dataset, depending on the workspace.
  • GeometricNetworkOnly geometric network datasets.
  • MosaicOnly mosaic datasets.
  • NetworkOnly network datasets.
  • ParcelFabricOnly parcel fabric datasets.
  • ParcelFabricForArcmapOnly ArcMap parcel fabric datasets.
  • RasterOnly raster datasets.
  • RasterCatalogOnly raster catalog datasets.
  • SchematicOnly schematic datasets.
  • TerrainOnly terrain datasets.
  • TinOnly TIN datasets.
  • TopologyOnly topology datasets.
  • AllAll datasets in the workspace. This is the default.

(默认值为 All)

String
返回值
数据类型说明
String

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

代码示例

ListDatasets 示例

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

import arcpy

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

# Print to the Interactive window 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 to the interactive window all the feature datasets in the
#   workspaces that start with the letter c or f.
datasets1 = list(set(arcpy.ListDatasets("c*", "Feature")) |
                 set(arcpy.ListDatasets("f*", "Feature")))
print(datasets1)

#   workspaces that start with the letters except c
datasets2 = list(set(arcpy.ListDatasets("*", "Feature")) -
                 set(arcpy.ListDatasets("c*", "Feature")))
print(datasets2)

#   workspaces that contain both the letter c and f
datasets3 = list(set(arcpy.ListDatasets("*c*", "Feature")) &
                 set(arcpy.ListDatasets("*f*", "Feature")))
print(datasets3)

相关主题