I am writing a script (to be used in ArcGIS 10.7.1) that uses a Zonal Statistics tool to create an average of a raster that is beneath a grid. I then use the Summary Statistics tool to take the summation of all the grid values and display them in a table. The resulting table has only one row with three columns, as shown below:
I'm trying to use a cursor to assign the value of the "SUM_Value" to a variable, because that value will be used later to compute some fertilizer amounts.
How can I do this?
The methods that I've tried aren't working out. I get this error when I do so:
Traceback (most recent call last): File "<pyshell#132>", line 1, in <module> totalNitrogen = row.getValue(field) NameError: name 'row' is not defined
Here is what I've tried:
#Define workspace env.workspace = "C:\\someWorkspace" #Defining variable 'Grid' Grid = #Previously created grid #Zonal statistics tool recommendationMap = ZonalStatistics(Grid, "grid_field", outputRaster, "MEAN") #Compute raster to Int recommendationMapInt = Int(recommendationMap) #Save raster recommendationMapInt.save(env.workspace + "\\nitrogenRecommendationMap") #Generate statistics with Summary Statistics tool nitrogenStats = arcpy.Statistics_analysis(recommendationMapInt,"outputRaster",[["Field_to_summarize", "SUM"]]) #Resulting output field defined for cursor nitrogenField = "SUM_Value" #Cursor defined nitrogenCursor = arcpy.SearchCursor(nitrogenStats) #Error occurs here totalNitrogen = row.getValue(field)
As previously stated, I need that
totalNitrogen variable to equal the "SUM_Value" field from the