Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?

1951
15
Jump to solution
06-19-2021 04:56 PM
LiYi1
by
New Contributor

Hi, I think what I am trying to do is very straigitforward but I was stuck in two days and have exhausted all previous solutions here and stakcoverflow. So, I am posting here with the hope of getting some help from someone who is good at model builder or arcpy.

Basically, I have a folder of raster grids converted from polygons (N=x)

I have another folder of NDVI rasters (N=y)

I am trying to build a loop extract by mask tool so that the tool will take x*y combinations of raster grids ad the mask and NDVI as raster inputs so that each NDVI will be clipped by the raster grids.

Model builder does not allow two iterators, and the sub-model within the model cannot be used to bypass this since it only takes the last value of the sub-model in the main model. I see someone mention arcpy method but I have zero skill in python so no idea how this can be achieved. I am hoping for any comments on whether this is indeed available.

Any insights are greatly appreciated.

Thanks a lot.

0Kudos
15 Replies
DavidPike
MVP频繁来讲ibutor

Cancel that, I used power notation:disappointed_face:just use the one * for everything

0Kudos
DavidPike
MVP频繁来讲ibutor
outRC = outExtractByMask * arcpy.Raster(mask_raster) * 0.0001
0Kudos
DavidPike
MVP频繁来讲ibutor

@LiYi1Just to confirm you know the ** (to the power of) is incorrect and should be * (multiply)

0Kudos
LiYi1
by
New Contributor
Yes, I did see this message. Thanks again David.
0Kudos
LiYi1
by
New Contributor

Hi David, sorry to trouble you again. But I wonder if it is possible for me to match mask and raster before executing extract by mask tool based on dates indicated in file name. For instance,

I have NDVI images named: A2016273, A2017001, A2017037 ... (julian dates)

KDE grids named: G_106_03Jan17 G_108_29Dec16 G109_17Nov16 ..

I want each NDVI to find the KDE grids file with dates closest to it and then perform raster extraction, how should I modify the loop code then? Any insights are greatly appreciated.

0Kudos
DavidPike
MVP频繁来讲ibutor

I would look how to convert your file strings into a datetime object, then create a dictionary for both NDVI and KDE, keys being the filepath, values being the datetime objects.

I would iterate through the dictionaries to construct a new dictionary with the NVDI filepath -> KDE Grid filepath with the closest date (look for some existing code on this, or just find the rasters with the smallest datetime difference).

Using this dictionary it would be easy to then match them in the GP tool.

0Kudos