[英]How to add field name in python in arcgis?
I am making one tool, and for this I want to save result of this tool in field that I've added. 我正在制作一个工具,为此,我想将此工具的结果保存在我添加的字段中。 I want give name to that field on the basis of amenity selection (Here I've given data type of amenity as string. and added a list of values in amenity parameter like Education, Medical, Transportation, etc.).
我想根据便利设施的选择为该字段命名(在此,我将便利设施的数据类型指定为字符串。并在诸如教育,医疗,交通等便利设施参数中添加了值列表)。 If I select "education" from amenities then my field name is like "Edu_IC".
如果我从便利设施中选择“教育”,那么我的字段名称就像“ Edu_IC”。 How can I do this?
我怎样才能做到这一点? I've added my code snippet below
我在下面添加了我的代码段
def setupVulnerability():
GP = ARC.create(9.3)
print(SYS.version)
InputFC = GP.GetParameterAsText(0) # Input Feature Class
print "InputFC:-'%s'" % (InputFC)
Fields = GP.GetParameterAsText(1)
print "Fields:-'%s'" % (Fields)
fieldList = Fields.split(";")
print "fieldList:-'%s'" % (fieldList)
amenity = GP.GetParameterAsText(2)
print "amen:-'%s'" % (amenity)
all_field_names = [f.name for f in arcpy.ListFields(InputFC)]
field_Name = None
try:
for field in fieldList:
field_Name = field[0:3]+ "_" + "IC"
if field_Name in all_field_names:
continue
else :
GP.AddField(InputFC , field_Name , "FLOAT")
field_Name = None
except:
raise ERROR.ScriptError()
if __name__ == '__main__':
setupVulnerability()
I believe the problem is that your "amenity" variable, which receives input from the user, is not referenced when the field is being added. 我认为问题在于添加字段时未引用您的“舒适性”变量(该变量从用户接收输入)。
Something like this should work: 这样的事情应该起作用:
amenity = GP.GetParameterAsText(2) if amenity == "Education": field_name = amenity[:3] + "_IC" GP.AddField(InputFC, field_Name, "FLOAT")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.