UpdateCursor
Zusammenfassung
The UpdateCursor function creates a cursor that lets you update or delete rows on the specified feature class, shapefile, or table. The cursor places a lock on the data that will remain until either the script completes or the update cursor object is deleted.
Syntax
Parameter | Erläuterung | Datentyp |
dataset |
The feature class, shapefile, or table containing the rows to be updated or deleted. | String |
where_clause |
An optional expression that limits the rows returned in the cursor. For more information on WHERE clauses and SQL statements, see About_building_an_SQL_expression. | String |
spatial_reference |
Coordinates are specified in the spatial_reference provided, and converted on the fly to the coordinate system of the dataset. | Object |
fields [fields,...] |
The fields to be included in the cursor. By default, all fields are included. | String |
sort_fields |
Fields used to sort the rows in the cursor. Ascending and descending order for each field is denoted by A and D. | String |
Datentyp | Erläuterung |
Object |
A Cursor object that can hand out row objects. |
Codebeispiel
Update field values in feature class, based on another field's value.
import arcpy # Create update cursor for feature class # rows = arcpy.UpdateCursor("D:/St_Johns/data.gdb/roads") # Update the field used in buffer so the distance is based on the road # type. Road type is either 1, 2, 3 or 4. Distance is in meters. # for row in rows: # Fields from the table can be dynamically accessed from the row object. # Here fields named BUFFER_DISTANCE and ROAD_TYPE are used row.BUFFER_DISTANCE = row.ROAD_TYPE * 100 rows.updateRow(row) # Delete cursor and row objects to remove locks on the data # del row del rows