Update feature class from values in csv file

المشرف العام

Administrator
طاقم الإدارة
I'm trying to update a feature class with new data from a csv file. My workflow is as follows:

  1. Make a csv reader from csv file
  2. Identify my data columns using their index position
  3. Use an update cursor to update the values in the shapefile with data from the csv
Here is my code so far:

import csvimport arcpycsvfile = "C:\\Data\\data.csv"shpfile = "C:\\Data\\TEST.gdb\\azcounties"file = open(csvfile,"r")csvReader = csv.reader(file)header = csvReader.next()nameIndex = header.index("NAME")dateIndex = header.index("DATE")valueIndex = header.index("VALUE")dateField = "DATE"nameField = "NAME_2"valueField = "VALUE"with arcpy.da.UpdateCursor(shpfile,(nameField,dateField,valueField)) as cursor: for row in cursor: for rw in csvReader: row[0] = rw[nameIndex] row[1] = rw[dateIndex] row[2] = rw[valueIndex] cursor.updateRow(row)It seems to almost work. I don't get any errors, but only the first row in the shapefile gets updated.



أكثر...
 
أعلى