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
-
Btw: 1 square meter is not 1/1606,344 square mileBera– Bera2017年05月02日 19:27:38 +00:00Commented May 2, 2017 at 19:27
1 Answer 1
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)
-
1It worked! Thank you. I am a student and did not realize there was a difference between cursors and data access module cursors.Noah P– Noah P2017年05月02日 19:05:01 +00:00Commented May 2, 2017 at 19:05