ArcGIS Desktop

  • Dokumentation
  • Support

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

UpdateCursor

  • Zusammenfassung
  • Beschreibung
  • Syntax
  • Eigenschaften
  • Methodenübersicht
  • Methoden
  • Codebeispiel

Zusammenfassung

UpdateCursor establishes read-write access to records returned from a feature class or table.

Returns an iterator of lists. The order of values in the list matches the order of fields specified by the field_names argument.

Beschreibung

Update cursors can be iterated using a for loop.

Hinweis:

Opening simultaneous insert or update operations on the same workspace using different cursors requires the start of an edit session.

Hinweis:

The Calculate Field tool provides another approach for updating field values.

Hinweis:

arcpy.da.UpdateCursor should not be confused with the arcpy.UpdateCursor.

Syntax

UpdateCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause})
ParameterErläuterungDatentyp
in_table

The feature class, layer, table, or table view.

String
field_names
[field_names,...]

A list (or tuple) of field names. For a single field, you can use a string instead of a list of strings.

Use an asterisk (*) instead of a list of fields if you want to access all fields from the input table (raster and BLOB fields are excluded). However, for faster performance and reliable field order, it is recommended that the list of fields be narrowed to only those that are actually needed.

Raster fields are not supported.

Additional information can be accessed using tokens (such as OID@) in place of field names:

  • SHAPE@XY —Ein Tupel von XY-Koordinaten für den Feature-Schwerpunkt.
  • SHAPE@TRUECENTROID —Ein Tupel von XY-Koordinaten für den tatsächlichen Feature-Schwerpunkt.
  • SHAPE@X —Duplikat der X-Koordinate des Features.
  • SHAPE@Y —Duplikat der Y-Koordinate des Features.
  • SHAPE@Z —Duplikat der Z-Koordinate des Features.
  • SHAPE@M —Duplikat des M-Wertes des Features.
  • SHAPE@JSON — Die Esri JSON-Zeichenfolge für die Geometrie.
  • SHAPE@WKB —Das Well-known Binary (WKB)-Format für OGC-Geometrie. Es bietet eine übertragbare Darstellung eines Geometriewertes in Form eines zusammenhängenden Datenstroms.
  • SHAPE@WKT —Das Well-Known Text (WKT)-Format für OGC-Geometrie. Es bietet eine übertragbare Darstellung eines Geometriewertes in Form einer Textzeichenfolge.
  • SHAPE@ —Ein Geometrie-Objekt für das Feature.
  • SHAPE@AREA —Duplikat der Fläche des Features.
  • SHAPE@LENGTH —Duplikat der Länge des Features.
  • OID@ —Der Wert des ObjectID-Feldes.
String
where_clause

An optional expression that limits the records returned. For more information on WHERE clauses and SQL statements, see .

(Der Standardwert ist None)

String
spatial_reference

The Spatial Reference of the feature class can be specified with either a SpatialReference object or string equivalent.

(Der Standardwert ist None)

SpatialReference
explode_to_points

Deconstruct a feature into its individual points or vertices. If explode_to_points is set to True, a multipoint feature with five points, for example, is represented by five rows.

(Der Standardwert ist False)

Boolean
sql_clause

An optional pair of SQL prefix and postfix clauses organized in a list or tuple.

SQL prefix supports None, DISTINCT, and TOP. SQL postfix supports None, ORDER BY, and GROUP BY.

An SQL prefix clause is positioned in the first position and will be inserted between the SELECT keyword and the SELECT COLUMN LIST. The SQL prefix clause is most commonly used for clauses such as DISTINCT or ALL.

An SQL postfix clause is positioned in the second position and will be appended to the SELECT statement, following the where clause. The SQL postfix clause is most commonly used for clauses such as ORDER BY.

Hinweis:

DISTINCT, ORDER BY, and ALL are only supported when working with databases. They are not supported by other data sources (such as dBASE or INFO tables).

TOP is only supported by SQL Server and MS Access databases.

(Der Standardwert ist (None, None))

tuple

Eigenschaften

EigenschaftErläuterungDatentyp
fields
(Nur lesen)

A tuple of field names used by the cursor.

The tuple will include all fields (and tokens) specified by the field_names argument. If the field_names argument is set to "*", the fields property will include all fields used by the cursor. When using "*", geometry values will be returned in a tuple of the x,y-coordinates (equivalent to the SHAPE@XY token).

tuple

Methodenübersicht

MethodeErläuterung
deleteRow ()

Deletes the current row.

next ()

Returns the next row as a tuple. The order of fields will be returned in the order they were specified when creating the cursor.

reset ()

Resets the cursor back to the first row.

updateRow (row)

Updates the current row in the table.

Methoden

deleteRow ()
next ()

Rückgabewert

DatentypErläuterung
tuple
reset ()
updateRow (row)
ParameterErläuterungDatentyp
row

A list or tuple of values. The order of values should be in the same order as the fields.

When updating fields, if the incoming values match the type of field, the values will be cast as necessary. For example, a value of 1.0 to a string field will be added as "1.0", and a value of "25" added to a float field will be added as 25.0.

tuple

Codebeispiel

UpdateCursor example 1

Use UpdateCursor to update a field value by evaluating the values of other fields.

import arcpy

fc = 'c:/data/base.gdb/well'
fields = ['WELL_YIELD', 'WELL_CLASS']

# Create update cursor for feature class 
with arcpy.da.UpdateCursor(fc, fields) as cursor:
    # For each row, evaluate the WELL_YIELD value (index position 
    # of 0), and update WELL_CLASS (index position of 1)
    for row in cursor:
        if (row[0] >= 0 and row[0] <= 10):
            row[1] = 1
        elif (row[0] > 10 and row[0] <= 20):
            row[1] = 2
        elif (row[0] > 20 and row[0] <= 30):
            row[1] = 3
        elif (row[0] > 30):
            row[1] = 4

        # Update the cursor with the updated list
        cursor.updateRow(row)
UpdateCursor example 2

Use UpdateCursor to update a field of buffer distances for use with the Buffer tool.

import arcpy

arcpy.env.workspace = 'c:/data/output.gdb'
fc = 'c:/data/base.gdb/roads'
fields = ['ROAD_TYPE', 'BUFFER_DISTANCE']

# Create update cursor for feature class 
with arcpy.da.UpdateCursor(fc, fields) as cursor:
    # Update the field used in Buffer so the distance is based on road 
    # type. Road type is either 1, 2, 3 or 4. Distance is in meters. 
    for row in cursor:
        # Update the BUFFER_DISTANCE field to be 100 times the 
        # ROAD_TYPE field.
        row[1] = row[0] * 100
        cursor.updateRow(row) 

# Buffer feature class using updated field values
arcpy.Buffer_analysis(fc, 'roads_buffer', 'BUFFER_DISTANCE')

Verwandte Themen

  • SearchCursor
  • InsertCursor
  • Zugreifen auf Daten mit Cursorn

ArcGIS Desktop

  • Startseite
  • Dokumentation
  • Support

ArcGIS Plattform

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

Über Esri

  • Über uns
  • Karriere
  • Insider-Blog
  • User Conference
  • Developer Summit
Esri
Wir sind an Ihrer Meinung interessiert.
© Copyright 2016 Environmental Systems Research Institute, Inc. | Datenschutz | Rechtliches