1

This code is meant to apply an update cursor to a field called "New_Sq_Mile" when I am populating the field with the area of the polygons. Unfortunately the units are in meters and I need to do a calculation to change those values to miles before they are updated into the table. Here is what I have so far.

cursor = arcpy.UpdateCursor(FinalErase, ["SHAPE@AREA", "New_Sq_Mile"]) for row in cursor: row[1] = row[0] update.row del row del cursor 

Is there a way I can do a calculation in the for loop such as

row[1] = row[0]/1606.344 
1
  • Btw: 1 square meter is not 1/1606,344 square mile Commented May 2, 2017 at 19:27

1 Answer 1

3

You should use the newer Data Access module Cursors, for example da.UpdateCursor. They are alot faster. In your case like this:

import arcpy with arcpy.da.UpdateCursor(FinalErase,["SHAPE@AREA","New_Sq_Mile"]) as cursor: for row in cursor: row[1]=row[0]/1606.344 cursor.updateRow(row) 
1
  • 1
    It worked! Thank you. I am a student and did not realize there was a difference between cursors and data access module cursors. Commented May 2, 2017 at 19:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.