I have 8,760 (24*365) GRID rasters in a directory. I'd like to use use FocalStatistics analysis to reassign cells to the maximum of a 5x5 window/kernel and extract the resultant values at points specified in a points feature class.
from arcpy import CheckOutExtension
from arcpy.sa import FocalStatistics, NbrRectangle
if CheckOutExtension("spatial") != 'CheckedOut':
raise Exception('Failed to check out spatial analyst extension.)
# Testing subset of raster data. For simplicity.
HRRR_rasters = [r'E:\HRRR_Data\2014\GRID\1 - JAN_2014\g01010000',
r'E:\HRRR_Data\2014\GRID\1 - JAN_2014\g01010100',
r'E:\HRRR_Data\2014\GRID\1 - JAN_2014\g01010200',
r'E:\HRRR_Data\2014\GRID\1 - JAN_2014\g01010300',
r'E:\HRRR_Data\2014\GRID\1 - JAN_2014\g01010400']
neighborhood = NbrRectangle(width=5, height=5, units="CELL")
extract_points = r'C:\Users\jking\Documents\ArcGIS\Default.gdb\sample_points'
for raster in HRRR_rasters:
raster_obj = FocalStatistics(raster, neighborhood, 'MAXIMUM', "DATA")
# ------------------------Psudocode ------------------------------------
# ExtractValuesToPoints(in_point_features, in_raster, out_point_features)
# arcpy.da.InsertCursor to append to master table.
# Allow raster object to be garbage collected or deleted.
The main problem that I'm having is that ExtractValuesToPoints takes a raster_layer as input rather than a raster object. I have looked into saving the raster to the 'in_memory' workspace without any luck. I've also looked into the properties of the raster object finding that raster_obj.catalogPath & raster_obj.path are None. MakeRasterLayer takes the path and name of the raster dataset which also doesn't work. I can, albeit reluctantly, save the raster to disc, use it for processing and delete it manually. I would like to avoid this write heavy approach though.