Как записать значение в какой-то конкретный столбец в таблице ArcGIS? - PullRequest
0 голосов
/ 21 мая 2019

Я пишу скрипт на 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 , и я хочу изменить другие поля на основе моего другого набора данных, который имеет общий первичный ключ.

1 Ответ

1 голос
/ 21 мая 2019

Для обновления записи вам нужен метод 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)
...