Select to view content in your preferred language

Iterating extract by mask in ArcPy for 73 different masks and 21 different input rasters that don't all interconnect

495
1
04-19-2023 04:38 PM
MaraNutt
New Contributor

Hello,

I am using ArcGIS Pro 10.8.1 on a PC. I am struggling to be able to extract 21 .tif raster files that need to be extracted using 73 different .tif raster masks, making for quite a few output .tif files all with unique names.

I would like the name the output files in the following way: mask_name_input_name. Not all of the input rasters cross all the mask rasters, and so I think a for loop needs to be in the code somewhere, I'm just not sure where. I can email anyone who wants the exact files.
I think part of the issue for me is that I'm not sure how the os.path.join works in conjunction with the ListRaster function. Do I need to specify something in either of those?


 

Not all input rasters cross the mask rasters, which makes it slightly different (I think?) from this example from this community page: https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in... that I tried but kept coming up with this error:

TypeError                                 Traceback (most recent call last)
In  [14]:
Line 12:    in_rasters = [os.path.join(inras_ws, raster) for raster in arcpy.ListRasters()]

TypeError: 'NoneType' object is not iterable
---------------------------------------------------------------------------


Thank-you in advance!
Mara

0 Kudos
1 Reply
DavidPike
MVP Frequent Contributor

Think you have to set your Workspace for ListRasters().  At the moment it's probably returning nothing. 

0 Kudos