AnsweredAssumed Answered

How to run geoprocessing on row selected by cursor?

Question asked by rhowell2 on Feb 4, 2020
Latest reply on Feb 4, 2020 by rhowell2

I have a point feature class that has a unique ID field and a julian date field.

 

I also have a pile of rasters in a geodatabase that have daily values that I want to extract to the corresponding date in the point file. I have already written a script that goes through and renamed them so that the julian date is tagged on to the end of the name of the raster.

 

To do this, I have the following code:

input = point feature class


#Iterate through to extract values to points based on date
arcpy.env.workspace = #geodatabase with the rasters
fl = arcpy.ListRasters()
dict = {}
for feature in fl:
    j = feature[-5:-1] + feature[-1]#returns the julian date
   
    with arcpy.da.SearchCursor(input, ["julian"]) as cursor:
        for row in cursor:
            if row[0] == int(j):
                temp = #temporary output string
                table = arcpy.sa.ExtractValuesToPoints(input, r'string for geodatabase' + feature, r"ouput geodatabase" + feature + "_testtable")
             
                with arcpy.da.SearchCursor(table, ['ID', 'RASTERVALU']) as cursor2:
                    for row2 in cursor2:
                        ID = row2[0]
                        value = row2[1]
                        dict.update({ID : value})
                arcpy.Delete_management(table)
               
            else:
                print('not equal' + str(row[0]))

with arcpy.da.UpdateCursor(input, ['ID', "Value column"]) as cursor:
    for row in cursor:
        row[1] = dict[row[0]]
        cursor.updateRow(row)

I think the problem is line 15; the input for the Extract Values to Points tool is being overwritten by the last raster that it iterates over. So, the values for November 6th are writing over all of the previous dates in the dictionary and subsequently the point feature class. 

 

How do I code this so that it only runs the Extract Values to Points tool on the selected row in the search cursor?

Outcomes