<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Possible to iterate both input raster and mask in &amp;quot;extract by mask&amp;quot; tool in model builder or ArcPy? in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070247#M42219</link>
    <description>&lt;P&gt;I'd probably just do algebra on the Raster objects.&amp;nbsp; outExtractByMask should already be a raster object, however mask raster will need to be cast as one with arcpy.raster(...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;outRC = outExtractByMask ** arcpy.Raster(mask_raster)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 20 Jun 2021 22:12:49 GMT</pubDate>
    <dc:creator>DavidPike</dc:creator>
    <dc:date>2021-06-20T22:12:49Z</dc:date>
    <item>
      <title>Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070164#M42207</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Basically, I have a folder of raster grids converted from polygons (N=x)&lt;/P&gt;&lt;P&gt;I have another folder of NDVI rasters (N=y)&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Any insights are greatly appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 00:01:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070164#M42207</guid>
      <dc:creator>LiYi1</dc:creator>
      <dc:date>2021-06-20T00:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070193#M42211</link>
      <description>&lt;P&gt;Why did you convert the polygons to rasters?&lt;/P&gt;&lt;P&gt;It seems like it can be done very easily using arcpy/python.&amp;nbsp; If you give some examples of your folder structures and naming conventions (both sample names and extensions of what you have already, and how you would like the output files named).&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 12:58:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070193#M42211</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-20T12:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070203#M42213</link>
      <description>&lt;P&gt;Hi David, appreciate your reply. I am converting mask poly to raster since I need to have the output raster at the same grid size of the kernel density grid that I later will multiply with raster calculator.&lt;/P&gt;&lt;P&gt;Thanks so much for helping with arcpy, so I have three geodatabases setup called MASK.gdb, INRASTER.gdb, OUTRASTER.gdb within a folder called Expo&lt;/P&gt;&lt;P&gt;and then within MASK.gdb I have MASK1, MASK2 ... stored as raster format&lt;/P&gt;&lt;P&gt;INRASTER i have NDVI1, NDVI2, ... stored as raster form&lt;/P&gt;&lt;P&gt;output OUTRASTER should have name of both MASK1_NDVI1 ... MASK1_NDVI2 ... MASK2_NDVI1...&lt;/P&gt;&lt;P&gt;Looking forward to your reply!&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 15:54:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070203#M42213</guid>
      <dc:creator>LiYi1</dc:creator>
      <dc:date>2021-06-20T15:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070217#M42215</link>
      <description>&lt;P&gt;This should do it&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# specify paths of your GDBs
inras_ws = r'C:\.......\INRASTER.gdb'
mask_ws = r'C:\.......\MASK.gdb'
outras_ws = r'C:\.......\OUTRASTER.gdb'

# Set the current workspace
arcpy.env.workspace = inras_ws
# create a list of in_raster paths
in_rasters = [os.path.join(inras_ws, raster) for raster in arcpy.ListRasters()]

# Set the current workspace
arcpy.env.workspace = mask_ws
# create a list of mask_raster paths
mask_rasters = [os.path.join(mask_ws, raster) for raster in arcpy.ListRasters()]

#iterate and save outputs
for raster in in_rasters:
    raster_name = os.path.basename(raster)
    for mask_raster in mask_rasters:
        mask_raster_name = os.path.basename(mask_raster)
        out_raster_name = raster_name + "_" + mask_raster_name
        out_path = os.path.join(outras_ws, out_raster_name)
        outExtractByMask = arcpy.sa.ExtractByMask(raster, mask_raster)
        outExtractByMask.save(out_path)&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 20 Jun 2021 18:54:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070217#M42215</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-20T18:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070240#M42216</link>
      <description>&lt;P&gt;David, thanks very much. I modified the folder path and tried use IDLE (ArcGIS Pro) and then F5 run module. The Shell does not give me any error, but neither it does seem running. Do I run this code incorrectly? How should it be run usually? Excuse my rudimentary knowledge with ArcPy. Thanks, Li&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 21:34:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070240#M42216</guid>
      <dc:creator>LiYi1</dc:creator>
      <dc:date>2021-06-20T21:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070241#M42217</link>
      <description>&lt;P&gt;I can't really say.&amp;nbsp; I've added some print statements which should help.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# specify paths of your GDBs
inras_ws = r'C:\.......\INRASTER.gdb'
mask_ws = r'C:\.......\MASK.gdb'
outras_ws = r'C:\.......\OUTRASTER.gdb'

# Set the current workspace
arcpy.env.workspace = inras_ws
# create a list of in_raster paths
in_rasters = [os.path.join(inras_ws, raster) for raster in arcpy.ListRasters()]
print(in_rasters)
# Set the current workspace
arcpy.env.workspace = mask_ws
# create a list of mask_raster paths
mask_rasters = [os.path.join(mask_ws, raster) for raster in arcpy.ListRasters()]
print(mask_rasters)
#iterate and save outputs
for raster in in_rasters:
    raster_name = os.path.basename(raster)
    for mask_raster in mask_rasters:
        mask_raster_name = os.path.basename(mask_raster)
        out_raster_name = raster_name + "_" + mask_raster_name
        out_path = os.path.join(outras_ws, out_raster_name)
        print("running extract by mask - " + out_raster_name)
        outExtractByMask = arcpy.sa.ExtractByMask(raster, mask_raster)
        outExtractByMask.save(out_path)
        print("completed extract by mask - " + out_raster_name)
&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 20 Jun 2021 21:35:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070241#M42217</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-20T21:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070246#M42218</link>
      <description>&lt;P&gt;Hi David, thanks. I was able to make it work, now I need to take one step forward to use rastercalculator to multiply in_mask with the outextractbymask object. I took a stab here but it does not seem to work. Would you be so kind to look at it and let me know what I did wrong here? Much appreciated.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

# specify paths of your GDBs
inras_ws = r'P:\MADRES_GPS\Processed\Exposure\DayGPSExposure\in_raster.gdb'
mask_ws = r'P:\MADRES_GPS\Processed\Exposure\DayGPSExposure\in_mask.gdb'
outras_ws = r'P:\MADRES_GPS\Processed\Exposure\DayGPSExposure\out_raster.gdb'

# Set the current workspace
arcpy.env.workspace = inras_ws
# create a list of in_raster paths
in_rasters = [os.path.join(inras_ws, raster) for raster in arcpy.ListRasters()]

# Set the current workspace
arcpy.env.workspace = mask_ws
# create a list of mask_raster paths
mask_rasters = [os.path.join(mask_ws, raster) for raster in arcpy.ListRasters()]

#iterate and save outputs
for raster in in_rasters:
    raster_name = os.path.basename(raster)
    for mask_raster in mask_rasters:
        mask_raster_name = os.path.basename(mask_raster)
        out_raster_name =  mask_raster_name + "_" + raster_name 
        out_path = os.path.join(outras_ws, out_raster_name)
        print("running extract by mask - " + out_raster_name)
        outExtractByMask = arcpy.sa.ExtractByMask(raster, mask_raster)
        print("completed extract by mask - " + out_raster_name)
        outRC=RasterCalculator([outExtractByMask, mask_raster], ["x", "y"],
                               "x*y")
        outRC.save(out_path)
        print("completed raster calculator - " + out_raster_name)&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 20 Jun 2021 22:05:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070246#M42218</guid>
      <dc:creator>LiYi1</dc:creator>
      <dc:date>2021-06-20T22:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070247#M42219</link>
      <description>&lt;P&gt;I'd probably just do algebra on the Raster objects.&amp;nbsp; outExtractByMask should already be a raster object, however mask raster will need to be cast as one with arcpy.raster(...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;outRC = outExtractByMask ** arcpy.Raster(mask_raster)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 22:12:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070247#M42219</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-20T22:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070249#M42220</link>
      <description>&lt;P&gt;I see, so in this way, if I wish to scale it to 0.0001 I just do the below right?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;outRC = outExtractByMask ** arcpy.Raster(mask_raster) ** 0.0001&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 22:24:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070249#M42220</guid>
      <dc:creator>LiYi1</dc:creator>
      <dc:date>2021-06-20T22:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070250#M42221</link>
      <description>&lt;P&gt;That's the badger.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 22:33:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070250#M42221</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-20T22:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070251#M42222</link>
      <description>&lt;P&gt;Cancel that, I used power notation &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; just use the one * for everything&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 22:36:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070251#M42222</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-20T22:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070252#M42223</link>
      <description>&lt;LI-CODE lang="python"&gt;outRC = outExtractByMask * arcpy.Raster(mask_raster) * 0.0001&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 20 Jun 2021 22:36:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1070252#M42223</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-20T22:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1071735#M42382</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/251775"&gt;@LiYi1&lt;/a&gt;&amp;nbsp; Just to confirm you know the ** (to the power of) is incorrect and should be * (multiply)&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 22:15:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1071735#M42382</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-23T22:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1071780#M42387</link>
      <description>Yes, I did see this message. Thanks again David.&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Jun 2021 23:31:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1071780#M42387</guid>
      <dc:creator>LiYi1</dc:creator>
      <dc:date>2021-06-23T23:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1073909#M42692</link>
      <description>&lt;P&gt;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,&lt;/P&gt;&lt;P&gt;I have NDVI images named: A2016273, A2017001, A2017037 ... (julian dates)&lt;/P&gt;&lt;P&gt;KDE grids named: G_106_03Jan17 G_108_29Dec16 G109_17Nov16 ..&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 21:22:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1073909#M42692</guid>
      <dc:creator>LiYi1</dc:creator>
      <dc:date>2021-06-29T21:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Possible to iterate both input raster and mask in "extract by mask" tool in model builder or ArcPy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1073912#M42693</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;I would iterate through the dictionaries to construct a new dictionary with the NVDI filepath -&amp;gt; KDE Grid filepath with the closest date (look for some existing code on this, or just find the rasters with the smallest datetime difference).&lt;/P&gt;&lt;P&gt;Using this dictionary it would be easy to then match them in the GP tool.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 21:35:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/possible-to-iterate-both-input-raster-and-mask-in/m-p/1073912#M42693</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-29T21:35:57Z</dc:date>
    </item>
  </channel>
</rss>

