Arcpy TypeError:“元组”对象不支持项目分配,该字段定义为FLOAT

时间:2018-10-10 17:29:00

标签: python tuples arcgis arcpy

我正在处理Arcpy脚本,该脚本优先对下水道进行维修。我现在遇到的问题是寻找州际公路50'以内的下水道。到目前为止,脚本中已经运行了几个类似的代码节,而这些节没有遇到问题。
我不明白这里是什么问题。我从其他人那里继承了此脚本,因此我并没有真正理解其他代码节的工作方式(即使它们也被定义为FLOAT字段,应该是不可变的)。
     街道位置-请注意,必须在下面列出的文件夹中包含“街道”文件。选择所有主要街道,然后选择在指定缓冲区范围内的下水道交叉口。 错误返回到/arch:SSE2,这是它开始尝试修改新的row[1] = 5的时间 任何建议表示赞赏。谢谢!

WithinInterstates

下面显示的代码的较早部分可以正常工作,并按预期填写数据库:

arcpy.MakeFeatureLayer_management("C:/Python27/Shapefiles/Streets.shp", "Streets_fc")
streets = "Streets_fc"
arcpy.SelectLayerByAttribute_management(streets, "NEW_SELECTION", "(\"CFCC\" = 'A15') OR (\"CFCC\" = 'A63')")
arcpy.Buffer_analysis(streets, "Streets_Interstates", "50 Feet", "FULL", "ROUND", "ALL", "")
arcpy.SelectLayerByLocation_management("ruleset4nonfc", "INTERSECT", "Streets_Interstates", "", "NEW_SELECTION")
fieldname = arcpy.ValidateFieldName("WithinInterstates")
arcpy.AddField_management("ruleset4nonfc", fieldname, "FLOAT")
cursor = arcpy.da.UpdateCursor("ruleset4nonfc", ["ssGravity_Main_fullcctv_ASSET_ID", "WithinInterstates"])
with arcpy.da.SearchCursor ("ruleset4nonfc", ["ssGravity_Main_fullcctv_ASSET_ID", "WithinInterstates"]) as cursor:
    for row in cursor:
        if row[0] > 0:
        row[1] = 5
        elif row[0] <= 0:
        row[1] = " "
        else:
        pass
del cursor

据我所知,这些部分在功能上是相同的。谁能解释为什么州际公路不起作用而州际公路却不能起作用?

1 个答案:

答案 0 :(得分:0)

# Your Code
cursor = arcpy.da.UpdateCursor("ruleset4nonfc", ["ssGravity_Main_fullcctv_ASSET_ID", 
"WithinInterstates"])
with arcpy.da.SearchCursor ("ruleset4nonfc", ["ssGravity_Main_fullcctv_ASSET_ID", 
"WithinInterstates"]) as cursor:
    for row in cursor:
        if row[0] > 0:
        row[1] = 5
        elif row[0] <= 0:
        row[1] = " "
        else:
        pass
del cursor

您创建了一个更新游标,但随后使用了搜索光标?您不能使用searchcursor编辑行。您只需要使用searchCursor即可,就像在其他示例中一样。

with arcpy.da.UpdateCursor ("ruleset4nonfc", ["ssGravity_Main_fullcctv_ASSET_ID", 
"WithinInterstates"]) as cursor:
    for row in cursor:
        if row[0] > 0:
        row[1] = 5
        elif row[0] <= 0:
        row[1] = " "
        else:
        pass