[GIS] Finding the average value from polygon areas in a fishnet cell

arcgis-desktoparcpypolygonvector-grid

I am looking to assign depth values to each fishnet grid cell that I have by taking the area-weighted average of values from a contour/isopach map.

The map was interpolating using the depths of individual wells using the Geostatistical Analysis tool Inverse Distance Weighting.

Attached see a picture of my example along with the attribute table.

Example

At first I thought that Zonal Statistics as Table tool would be perfect but it would require me to convert to raster first (or even change the output of the IDW tool) but I have read that the conversion to raster is a poor choice (Does IDW interpolation in ArcGIS Geostatistical analyst work as exact interpolation method?). Is there a better method?

Best Answer

Unless i missunderstand you this should work:

  1. Intersect Fishnet and contours
  2. Calculate a column of area-weighted values (value*shapearea)
  3. Dissolve by fishnet ID and sum the area-weighted values
  4. Calculate total averages by Dividing with shape areas

You can do this manually, with ModelBuilder or using the Python window and code below (change the four lines as indicated):

import arcpy
arcpy.env.overwriteOutput=1

fishnet = r'C:\Default.gdb\fishnet_4km' #Change to match your data
contours = r'C:\Default.gdb\contour' #Change to match your data
valuecolumn = 'AvgValue' #Change to match your data
outfc = r'C:\Default.gdb\fishnet_with_averages' #Change to match your data

#Intersect fishnet and contours
tempfc=r'in_memory\intersect'
arcpy.Intersect_analysis(in_features=[fishnet,contours], out_feature_class=tempfc)

#Calculate areaweighted values per intersection
arcpy.AddField_management(in_table=tempfc, field_name='AvgArea', field_type='DOUBLE')
with arcpy.da.UpdateCursor(tempfc,['AvgArea',valuecolumn,'SHAPE@AREA']) as cursor:
    for row in cursor:
        row[0]=row[1]*row[2]
        cursor.updateRow(row)

#Dissolve by fishnet ID and calculate sum of areasums
fishnetID = '{0}{1}'.format('FID_',arcpy.Describe(fishnet).name)
arcpy.Dissolve_management(in_features=tempfc, out_feature_class=outfc, 
                         dissolve_field=fishnetID, 
                         statistics_fields=[['AvgArea','SUM']])
arcpy.AddField_management(in_table=outfc, field_name='Areaweighted_average', field_type='DOUBLE')

#Calculate areaweighted average
with arcpy.da.UpdateCursor(outfc,['Areaweighted_average','SUM_AvgArea','SHAPE@AREA']) as cursor:
    for row in cursor:
        row[0]=row[1]/row[2]
        cursor.updateRow(row)

Inputs: enter image description here Output: enter image description here

Related Question