这段代码有什么问题?setValue行出错

import arcpy
fc = r"C:\Users\songwk.songwk-PC2.000\Documents\ArcGIS\Default.gdb\GX_DSL_Intersect"
with arcpy.da.UpdateCursor(fc, ["SHAPE@","SX","SY","EX","EY"]) as cursor:
for row in cursor:
#print("QD:X = {0},Y = {1}",row[0].firstPoint.X,row[0].firstPoint.Y)
#print("ZD:X = {0},Y = {1}",row[0].lastPoint.X,row[0].lastPoint.Y)
row.setValue("SX",row[0].firstPoint.Y)
row.setValue("SY",row[0].firstPoint.Y)
row.setValue("EX",row[0].lastPoint.X)
row.setValue("EY",row[0].lastPoint.Y)
cursor.updateRow(row)
del cursor, row
已邀请:

turtle

赞同来自:

注意区分下arcpy.UpdateCursor与arcpy.da.UpdateCursor的区别;
具体的差别查看帮助文档
代码改成下面就可以
import arcpy
fc = r"C:\Users\songwk.songwk-PC2.000\Documents\ArcGIS\Default.gdb\GX_DSL_Intersect"
with arcpy.da.UpdateCursor(fc, ["SHAPE@","SX","SY","EX","EY"]) as cursor:
for row in cursor:
row[1]=row[0].firstPoint.X
row[2]=row[0].firstPoint.Y
row[3]=row[0].lastPoint.X
row[4]=row[0].lastPoint.Y
cursor.updateRow(row)

要回复问题请先登录注册