ListDatasets (arcpy)

摘要

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

讨论

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

语法

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

wild_card 可限制返回的结果。如果未指定任何 wild_card,则会返回所有值。

String
feature_type

The feature type to limit the results returned by the wildcard argument. Valid dataset types are:

  • CoverageOnly coverages.
  • FeatureCoverage or geodatabase dataset, depending on the workspace.
  • GeometricNetworkOnly geometric network datasets.
  • MosaicOnly mosaic datasets.
  • NetworkOnly network datasets.
  • ParcelFabricOnly 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 value.

(默认值为 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)

相关主题

5/10/2014