I am trying to use the ExtractByMask tool on a multidimension raster dataset by using the ForEach tool,
The raster data is gridded historical climate data of monthly maximum air temperature.
The mask data is a vector data set of vegetation communities,
Here is the code
import arcpy
climate_file_historic_monthly_1950_54 = r"D:\temp\climate_projections\macav2metdata_tasmax_GFDL-ESM2M_r1i1p1_historical_1950_1954_CONUS_monthly.nc"
max_temp_hist_monthly_raster = arcpy.Raster(climate_file_historic_monthly_1950_54,True)
eru_data_file = r"D:\temp\RegionalSeralStateDeparture.gdb\Ecological_Response_Unit"
arcpy.management.MakeFeatureLayer(eru_data_file,'eru_data',"R3ERUCODE = 'MCD'")
arcpy.CheckOutExtension('Spatial')
arcpy.sa.Foreach(max_temp_hist_monthly_raster,'ExtractByMask',{'in_mask_data':'eru_data'})
:
The error returned is
RuntimeError Traceback (most recent call last) In [70]: Line 1: arcpy.sa.Foreach(max_temp_hist_monthly_raster,'ExtractByMask',{'in_mask_data':'eru_data'}) File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\ia\_ia.py, in Foreach: Line 114: return arcgisscripting._ia.Foreach(in_raster=in_raster, RuntimeError: Invalid Raster Function: 'ExtractByMask'
The documentation on using the ForEach tool is a bit scanty. Using the ExtractByMask tool from the analysis tools returns a single band raster. I am looking for the extracted data by each slice.
I am not seeing ExtractByMask in the list of Raster function objects referenced here
Foreach—ArcGIS Pro | Documentation and here
Raster function objects—Common Data Types | ArcGIS Developers
Thanks. The documentation on using the ForEach function is not all that clear. I assumed that any Spatial Analyst raster function could be used.
After consulting the raster functions documentation I changed the code from ExtractByMask to
max_temp_clip_raster = arcpy.sa.Foreach(max_temp_hist_monthly_raster,'Clip',{"ClippingGeometry":eru_data_feature_set, "ClippingType":1})
use the Clip function.
That does not work. This is the error returned:
RuntimeError Traceback (most recent call last) In [17]: Line 4: max_temp_clip_raster = arcpy.sa.Foreach(max_temp_hist_monthly_raster,'Clip',{"ClippingGeometry":eru_data_feature_set, "ClippingType":1}) File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\ia\_ia.py, in Foreach: Line 114: return arcgisscripting._ia.Foreach(in_raster=in_raster, RuntimeError: Failed to apply Raster Function: 'Clip' (The parameter is incorrect. )
I tested out the Clip raster function in Pro UI. From what I determine, the function will not clip a raster to a polygon boundary like the ExtractByMask function does.
@DavidAnderson_1701 You ever figure this out I got the same issue. Mask strips the dimensions and Subset is just a bounding box. been posting here also with a sample.
Thanks