ArcGIS for Desktop

  • 文档
  • 合约
  • 支持

  • My Profile
  • 帮助
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS for Desktop

全面的专业性 GIS

ArcGIS for Server

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 合约
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

帮助

  • 主页
  • 入门
  • 制图
  • 分析
  • 管理数据
  • 工具
  • 更多...

Walk

  • 摘要
  • 讨论
  • 语法
  • 代码实例

摘要

通过从上至下或从下至上遍历树,在目录/数据库结构中生成数据名称。各目录/工作空间提供一个三元组:目录路径、目录名称和文件名称。

讨论

注:

Walk 函数在 ArcGIS 10.1 Service Pack 1 中可用。

Python os 模块包含 os.walk 函数,可用于遍历目录树并查找数据。os.walk 基于文件,不识别地理数据要素类、表或栅格等数据库内容。arcpy.da.Walk 可用于为数据编目录。

语法

Walk (top, {topdown}, {onerror}, {followlinks}, {datatype}, {type})
参数说明数据类型
top

The top-level workspace that will be used.

String
topdown

If topdown is True or not specified, the tuple for a directory is generated before the tuple for any of its workspaces (workspaces are generated top-down). If topdown is False, the tuple for a workspace is generated after the tuple for all of its subworkspaces (workspaces are generated bottom-up).

When topdown is True, the dirnames list can be modified in-place, and Walk() will only recurse into the subworkspaces whose names remain in dirnames. This can be used to limit the search, impose a specific order of visiting, or even to inform Walk() about directories the caller creates or renames before it resumes Walk() again. Modifying dirnames when topdown is Falseis ineffective, because in bottom-up mode the workspaces in dirnames are generated before dirpath itself is generated.

(默认值为 True)

Boolean
onerror

Errors are ignored by default. The onerror function will be called with an OSError instance.

The function can be used to report the error and continue with the walk or raise an exception to abort.

注:

The file name is available as the filename attribute of the exception object.

(默认值为 None)

Function
followlinks

By default, Walk() does not walk into connection files. Set followlinks to True to visit connection files.

(默认值为 False)

Boolean
datatype

The data type to limit the results returned. Valid data types are the following:

  • Any —All data types are returned. Equivalent to using None or skipping the argument.
  • CadDrawing
  • CadastralFabric
  • Container
  • FeatureClass
  • FeatureDataset
  • Geo
  • GeometricNetwork
  • LasDataset
  • Layer
  • Locator
  • Map
  • MosaicDataset
  • NetworkDataset
  • PlanarGraph
  • RasterCatalog
  • RasterDataset
  • RelationshipClass
  • RepresentationClass
  • Style
  • Table
  • Terrain
  • Text
  • Tin
  • Tool
  • Toolbox
  • Topology

Multiple data types are supported if entered as a list or tuple.

for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,
    datatype=['MosaicDataset', 'RasterDataset']):

(默认值为 None)

String
type

Feature and raster data types can be further limited by type.

  • All —All types are returned. Equivalent to using None or skipping the argument.
  • Any —All types are returned. Equivalent to using None or skipping the argument.

Valid feature types are the following:

  • Multipatch — Only multipatch feature classes are returned.
  • Multipoint —Only multipoint feature classes are returned.
  • Point —Only point feature classes are returned.
  • Polygon —Only polygon feature classes are returned.
  • Polyline —Only polyline feature classes are returned.

Valid raster types are:

  • BIL — Esri Band Interleaved by Line file
  • BIP — Esri Band Interleaved by Pixel file
  • BMP — Bitmap graphic raster dataset format
  • BSQ — Esri Band Sequential file
  • DAT — ENVI DAT file
  • GIF — Graphic Interchange Format for raster datasets
  • GRID — Esri Grid raster dataset format
  • IMG — ERDAS IMAGINE raster data format
  • JP2 — JPEG 2000 raster dataset format
  • JPG — Joint Photographic Experts Group raster dataset format
  • PNG — Portable Network Graphic raster dataset format
  • TIF — Tag Image File Format for raster datasets

Multiple data types are supported if entered as a list or tuple.

for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,
    datatype='FeatureClass', type=['Polygon', 'Polyline']):

(默认值为 None)

String

返回值

数据类型说明
Generator

提供的三元组包括:工作空间、目录名称和文件名称 (dirpath, dirnames, and filenames)。

  • dirpath 是以字符串形式存在的工作空间路径。
  • dirnames 是子目录和 dirpath 中其他工作空间的名称列表。
  • filenames 是 dirpath 中非工作空间内容的名称列表。
注:

列表中的名称仅包括基本名称,不包括路径组件。要获得 dirpath 中的文件或目录的完整路径(从顶部开始),请执行 os.path.join(dirpath, name)。

代码实例

Walk 示例 1

使用 Walk 函数为面要素类创建目录。

import arcpy
import os

workspace = "c:/data"
feature_classes = []

walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="Polygon")

for dirpath, dirnames, filenames in walk:
    for filename in filenames:
        feature_classes.append(os.path.join(dirpath, filename))
Walk 示例 2

使用 Walk 函数为栅格数据创建目录。将忽略文件夹中所有名为 back_up 的栅格。

import arcpy
import os

workspace = "c:/data"
rasters = []

walk = arcpy.da.Walk(workspace, topdown=True, datatype="RasterDataset")

for dirpath, dirnames, filenames in walk:
    # Disregard any folder named 'back_up' in creating list of rasters
    if "back_up" in dirnames:
        dirnames.remove('back_up')
    for filename in filenames:
        rasters.append(os.path.join(dirpath, filename))

相关主题

  • 创建数据列表
有关此主题的反馈?

ArcGIS for Desktop

  • 主页
  • 文档
  • 合约
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • 内部人员博客
  • 用户大会
  • 开发者峰会
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | 隐私政策 | 法律声明