如何在ArcGIS表格中的特定列中写入值?

2024-06-23 03:32:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个python脚本来添加字段并将数据写入ArcGIS表。我可以成功地编辑和删除表中的列或字段。但我一直在把数据写进字段。我有一个代码,我们可以通过它来获得类型和其他有关字段的信息。但我无法在这个领域写点东西。你知道吗

这是我从他们论坛得到的剧本-

import arcpy

feature_class = "c:/data/counties.shp"

# Create a list of fields using the ListFields function
fields = arcpy.ListFields(feature_class)

# Iterate through the list of fields
for field in fields:
    # Print field properties
    print("Field:       {0}".format(field.name))
    print("Alias:       {0}".format(field.aliasName))
    print("Type:        {0}".format(field.type))
    print("Is Editable: {0}".format(field.editable))
    print("Required:    {0}".format(field.required))
    print("Scale:       {0}".format(field.scale))
    print("Precision:   {0}".format(field.precision))  

已更新 下图是我的桌子 enter image description here

我的主键是COPROPCD,我想根据另一个具有公共主键的数据集更改其他字段。你知道吗


Tags: ofthe数据脚本formatfieldfieldsfeature
1条回答
网友
1楼 · 发布于 2024-06-23 03:32:32

要更新记录,需要使用UpdateCursor方法。假设你的datasource是一个字典,你可以这样做

import arcpy
feature_class = "c:/data/counties.shp"

with arcpy.da.UpdateCursor(feature_class, ["COPROPCD","field2"]) as cursor:
    for row in cursor:
        #Check if "COPROPCD" exist as a key in the dict     
        if row[0] in dataset.keys():
            #logic for updating the dable
            #This will update the field2 column to the value of the key
            row[1] = dataset["value"]
            cursor.updateRow(row)

相关问题 更多 >

    热门问题