Monday, June 8, 2009

Update Cursor & Example

In python, the update cursor either updates or deletes a row in a specific table. This is very helpful when you need to modify an attribute.

Example:
import arcgisscriptinggp = arcgisscripting.create(9.3)
# Create update cursor for feature class
#
rows = gp.UpdateCursor("D:/St_Johns/data.mdb/roads")
row = rows.Next()
# 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.
#
while row:
row.buffer_distance = row.road_type *
100
rows.UpdateRow(row)
row = rows.Next()
# Delete cursor and row objects to remove locks on
the data
#
del row
del rows


Enjoy

No comments: