我对 Python 很陌生,正在尝试编写一个用于 ArcGIS 10.1 (arcpy) 的脚本;基本思想是添加一个新字段(francis),检查其他几个字段中的值,如果有的话为空(-99)然后输出 0 到 Francis,否则运行一个简单的计算。但是,我得到了这个错误和我无法超越它:
回溯(最近一次通话最后):
文件“C:\gislab2\Python\take_home\part1\prelim_if2.py”,第 28 行,在 arcpy.CalculateField_management(Output_Feature_Class, "Francis", "", "PYTHON_9.3", "")
文件“C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\management.py”,第 3128 行,在 CalculateField raise e
ExecuteError:执行失败。参数无效。错误 000735:表达式:需要值 执行失败 (CalculateField)。
这是代码
# Import arcpy module
import arcpy
print "start your engines"
# Script arguments
Shapefile = "C:\\gislab2\\Python\\take_home\\USCancer2000.shp"
Field_Name = Francis
Output_Feature_Class = "C:\\gislab2\\Python\\take_home\\USCancer2000.shp"
# Local variables:
USCancer2000__2_ = Output_Feature_Class
# Process: Add Field
arcpy.AddField_management(Shapefile, "Francis", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
# Process: Calculate Field
arcpy.CalculateField_management(Output_Feature_Class, "Francis", "", "PYTHON_9.3", "")
##
### Process: If-then check for missing values
##
if "Cnt1"==-99:
Field_name=7
elif "Cnt2"==-99:
Field_name=7
elif "Cnt3"==-99:
Field_name=7
elif "Pop1"==-99:
Field_name==7
elif "Pop2"==-99:
Field_name=7
elif "Pop3"==-99:
Field_name=7
else:
Field_name=("Cnt1"+"Cnt2"+"Cnt3")/("Pop1"+"Pop2"+"Pop3")
print "done"
提前谢谢了!大卫