Geographic Information Systems Asked on March 1, 2021
I’m running an arcpy code in IDLE that update a field in shapefile. After updating it get the following error:
Traceback (most recent call last): File “C:/Users/10/Desktop/test.py”, line 21, in cursor.updateRow(row_st) RuntimeError: Object invalid or no longer set.
And, here is the code:
from arcpy.sa import *
import arcpy
from arcpy import env
env.workspace = r"D:Phd-Filesdataset.mdb"
env.overwriteOutput = True
fields_Street=["OBJECTID","SHAPE@","t_light_de", "st_dense", "bikeLn_den", "Buff_area", "len"]
cursor= arcpy.UpdateCursor("Boston_Street_Buff_10_Joint", fields_Street)
for row_st in cursor:
geom = row_st.getValue('Shape')
# calculate street density
_area_buff=0
arcpy.Buffer_analysis(geom, "geom_buff", "10 Meters")
cursor_buff= arcpy.SearchCursor("geom_buff", ["ORIG_FID", "Shape_Area"])
for row_buff in cursor_buff:
_area_buff=_area_buff+ row_buff.getValue('Shape_Area')
row_st.setValue ('st_dense' , row_st.getValue('Buff_area')/_area_buff)
del cursor_buff, row_buff
print ('street_ObjectID={0}, bike_lane density= {1}'.format(row_st.getValue('OBJECTID'), row_st.getValue('st_dense')))
cursor.updateRow(row_st)
arcpy.Delete_management("geom_buff")
I use shp file instead of mdb and it dosent get error. As it works on shp, i have to update Shape_Area at the buffer. i use expression1 = "{0}".format("!SHAPE.area@SQUERMETERS!")
arcpy.CalculateField_management("geom_buff.shp", "Shape_Area", expression1, "PYTHON")
and that works for me.
Answered by Reza on March 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP