ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • ヘルプ
  • Sign Out
ArcGIS Desktop

ArcGIS Online

組織のマッピング プラットフォーム

ArcGIS Desktop

完全なプロ仕様の GIS

ArcGIS Enterprise

エンタープライズ GIS

ArcGIS Developers

位置情報利用アプリの開発ツール

ArcGIS Solutions

各種業界向けの無料のテンプレート マップおよびテンプレート アプリケーション

ArcGIS Marketplace

組織で使えるアプリとデータを取得

  • ドキュメント
  • サポート
Esri
  • サイン イン
user
  • マイ プロフィール
  • サイン アウト

ArcMap

  • ホーム
  • はじめに
  • マップ
  • 解析
  • データ管理
  • ツール
  • エクステンション

Walk

  • 概要
  • ディスカッション
  • 構文
  • コードのサンプル

概要

上から下または下から上にツリーを操作することによって、ディクショナリ/データベース構造でデータ名を生成します。 各ディレクトリ/ワークスペースから、ディレクト パス、ディレクトリ名、ファイル名の 3 つの組み合わせが得られます。

ディスカッション

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 False is 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
  • 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

ワークスペース、ディレクトリ名、ファイル名の 3 つの組み合わせが得られます。

  • 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 Desktop

  • ホーム
  • ドキュメント
  • サポート

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

Esri について

  • 会社概要
  • 採用情報
  • Esri ブログ
  • ユーザ カンファレンス
  • デベロッパ サミット
Esri
ご意見・ご感想をお寄せください。
Copyright © 2021 Esri. | プライバシー | リーガル