Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to Python, so sorry for such a trivial question. There is a shapefile (let's call it Structures.shp) and the script I'm writing needs to update the value of only one record in only one field (let's call the field structuretype). The field is the subtype field and the default value is (for example) 3, but the script needs to change the value for this particular record to 4. What is the easiest way for the script to update the value of this one cell?

share|improve this question
up vote 14 down vote accepted

This should do it and is a little simpler than the examples in the online help for UpdateCursor which is nevertheless worth a read.

I've assumed your shapefile is in a folder called C:\temp and that structuretype is an integer field. If it is a text field just use "3" and "4" instead of 3 and 4.

import arcpy

features = arcpy.UpdateCursor(r"C:\temp\Structures.shp")
for feature in features:
    if feature.structuretype == 3:
        feature.structuretype = 4
        features.updateRow(feature)
del feature,features

Warning: The way I am referencing field values here only works for old style cursors and not for the superior and faster cursors in the Data Access (arcpy.da) module, which was introduced with ArcGIS 10.1.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.