ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Hilfe
  • Sign Out
ArcGIS Desktop

ArcGIS Online

Die Mapping-Plattform für Ihre Organisation

ArcGIS Desktop

Ein vollständiges professionelles GIS

ArcGIS Enterprise

GIS in Ihrem Unternehmen

ArcGIS Developers

Werkzeuge zum Erstellen standortbezogener Apps

ArcGIS Solutions

Kostenlose Karten- und App-Vorlagen für Ihre Branche

ArcGIS Marketplace

Rufen Sie Apps und Daten für Ihre Organisation ab.

  • Dokumentation
  • Support
Esri
  • Anmelden
user
  • Eigenes Profil
  • Abmelden

ArcMap

  • Startseite
  • Erste Schritte
  • Karte
  • Analysieren
  • Verwalten von Daten
  • Werkzeuge
  • Erweiterungen

Walk

  • Zusammenfassung
  • Auswertung
  • Syntax
  • Codebeispiel

Zusammenfassung

Erstellen Sie Datennamen in einem Verzeichnis/einer Datenbankstruktur, indem die Struktur von oben nach unten oder von unten nach oben durchlaufen wird. Jedes Verzeichnis/jeder Workspace in der Struktur ergibt einen Dreier-Tupel: Verzeichnispfad, Verzeichnisnamen und Dateinamen.

Auswertung

Das Python-Modul os enthält die Funktion os.walk, mit der eine Verzeichnisstruktur zum Suchen von Daten durchlaufen werden kann. os.walk ist dateibasiert und erkennt keine Datenbankinhalte wie z. B. Geodatabase-Feature-Classes, Tabellen oder Raster. arcpy.da.Walk kann zum Katalogisieren von Daten verwendet werden.

Syntax

Walk (top, {topdown}, {onerror}, {followlinks}, {datatype}, {type})
ParameterErklärungDatentyp
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.

(Der Standardwert ist 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.

Hinweis:

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

(Der Standardwert ist None)

Function
followlinks

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

(Der Standardwert ist 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']):

(Der Standardwert ist 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']):

(Der Standardwert ist None)

String

Rückgabewert

DatentypErklärung
Generator

Ergibt einen Dreier-Tupel aus Workspace, Verzeichnisnamen und Dateinamen.

  • dirpath ist der Pfad zu dem Workspace als Zeichenfolge.
  • dirnames ist eine Liste mit Namen von Unterverzeichnissen und anderen Workspaces in dirpath.
  • filenames ist eine Liste mit Namen von Inhalten in dirpath, die keine Workspaces sind.
Hinweis:

Die Namen in den Listen umfassen nur den Basisnamen und keine Pfadkomponenten. Verwenden Sie os.path.join(dirpath, name), um einen vollständigen Pfad (beginnt mit "top") zu einer Datei oder einem Verzeichnis in dirpath abzurufen.

Codebeispiel

Walk – Beispiel 1

Mit der Funktion Walk werden Polygon-Feature-Classes katalogisiert.

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 – Beispiel 2

Mit der Funktion Walk werden Raster-Daten katalogisiert. Jedes Raster im Ordner namens back_up wird ignoriert.

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))

Verwandte Themen

  • Erstellen von Datenlisten

ArcGIS Desktop

  • Startseite
  • Dokumentation
  • Support

ArcGIS

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

Über Esri

  • Über uns
  • Karriere
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Wir sind an Ihrer Meinung interessiert.
Copyright © 2021 Esri. | Datenschutz | Rechtliches