Select to view content in your preferred language

# Doubts in arcpy.da.UpdateCursor

377
2
11-09-2019 10:34 AM
Occasional Contributor II

Hi,

My statement below create and update one new colunm with area calculated and after convert to other mensure splitting by 43560.

import arcpy
arcpy.env.workspace = "C://EsriTraining/PYTH/Cursors/Corvallis.gdb"

with arcpy.da.UpdateCursor("Parcel", ["SHAPE@AREA", "ACRES"]) as cursor:
for row in cursor:
geom = row[0]
row[1] = geom / 43560
cursor.updateRow(row)

Why have I to use geom equals row [0]?? There is no geom colunm in my feature...

Thank´s

Tags (1)
1 Solution

Accepted Solutions
Esri Esteemed Contributor

Hi André Souza ,

The sample script indeed does not return the actual geometry, but a specific property of the geometry (in this case the area of the geometry using the SHAPE@AREA token). See UpdateCursor—Help | ArcGIS Desktop

The cursor is a collection of rows and each row is represented as a tuple. The way to access the values in each row is by using the index. row[0] refers to the first item in the tuple that corresponds to the order of your field list, in this case the area in sq ft (SHAPE@AREA). To convert this to acres you have to divide by 43560. The result is written to row[1] which refers to the ACRES field.

2 Replies
Esri Esteemed Contributor

Hi André Souza ,

The sample script indeed does not return the actual geometry, but a specific property of the geometry (in this case the area of the geometry using the SHAPE@AREA token). See UpdateCursor—Help | ArcGIS Desktop

The cursor is a collection of rows and each row is represented as a tuple. The way to access the values in each row is by using the index. row[0] refers to the first item in the tuple that corresponds to the order of your field list, in this case the area in sq ft (SHAPE@AREA). To convert this to acres you have to divide by 43560. The result is written to row[1] which refers to the ACRES field.

Occasional Contributor II

Thank´s