简体   繁体   English

如何在Arcgis中的python中添加字段名称?

[英]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.

相关问题 如何为没有 Anaconda 变体的 Python 安装 ArcGIS API - How to install ArcGIS API for Python without Anaconda variants Python3-如何在输入中添加名称以进行编辑? - Python3 - How to add a name for editing in input? 您如何在Python 3.4中将变量名添加到文件名? - How would you add the name of a variable to a file name in Python 3.4? 如何在excel中使用python在某些条件下获取名称字段? - How to get the name field given some conditions in excel using python? Python 3 arcgis.gis.user for lastLogin 访问 ArcGIS Portal - Python 3 arcgis.gis.user for lastLogin accessing ArcGIS Portal Protobuf 和 Python:如何将消息添加到“可重复的任何”字段? - Protobuf and Python: How to add messages to "repeatable Any" field? 如何在python中添加一个字段,根据其他列返回值? - How to add a field in python to return value based on other columns? 是否可以在ArcGis Pro外部使用Python安装的Python? - Is it possible to use the Python installed by ArcGis Pro outside of it? 如果字段名称与 python 中的字典值匹配,则求和 - sum if the field name matches the dictionary values in python 如何在 Python 中创建一个网格字段,其中包含全球每个像素的国家名称,分辨率为 0.1°x0.1°? - How to create a gridded field in Python that contains the country name of each pixel globally with a resolution of 0.1°x0.1°?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM