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
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 2, 2017 at 18:53
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)
answered May 2, 2017 at 19:02
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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.