<?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 Match three rasters in a if/else loop? in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1022088#M25127</link>
    <description>&lt;P&gt;I had created a script with help from the community that takes two rasters of the same name and merges them together (&lt;A href="https://community.esri.com/t5/geoprocessing-questions/loop-through-rasters-and-extract-by-masks-of-polygon-fcs-with/m-p/1020562#M25124" target="_self"&gt;here&lt;/A&gt;). I now need to bring in a third raster and mosaic them together as well. However, when I go about matching them, I get this error&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 45, in &amp;lt;module&amp;gt;&lt;BR /&gt;IndexError: list index out of range&lt;/P&gt;&lt;P&gt;&amp;nbsp;I wanted to see if I'm going about this the wrong way or if this is even possible to match in this way? TIA!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
from arcpy import env

#not a fan of stating the obvious, but change the paths below to your fgdbs
#also keep the r then surround the path in quotes

#fgdb of rasters being merged
pluv_fgdb = r'E:\FATHOM\2020FATHOM\Analysis\Pluvial_1in100\Pluvial_1in100_Processed.gdb'

fluv_fgdb = r'E:\FATHOM\2020FATHOM\Analysis\Fluvial_1in100\Fluvial_1in100_Processed.gdb'

nhd_fgdb = r'E:\FATHOM\2020FATHOM\Analysis\NHDplusMedium_flowlines_Rast_Expand_HUC02.gdb'


#preferably empy fgdb to put outputs
output_fgdb = r'E:\FATHOM\2020FATHOM\Analysis\Final_Floodplain_Bounds_No_NHD.gdb'


#list all the rasters

arcpy.env.workspace = pluv_fgdb

pluv_rasters = arcpy.ListRasters("*", "GRID")
print (pluv_rasters)

arcpy.env.workspace = fluv_fgdb

fluv_rasters = arcpy.ListRasters()
print (fluv_rasters)

arcpy.env.workspace = nhd_fgdb

nhd_rasters = arcpy.ListRasters()
print (nhd_rasters)

#make a dictionary of source raster path
#to clipping fc and source name
#NB relies on names after the '_' being equal
input_floodplain_pieces_dict = {}

for pluv_raster in pluv_rasters:
    for fluv_raster in fluv_rasters:
        for nhd_raster in nhd_rasters:
            if pluv_raster.split("_Mask")[1] == fluv_raster.split("_Mask")[1] == nhd_raster.split("_")[-1]:
                pluv_raster_path = os.path.join(pluv_fgdb, pluv_raster)
                fluv_raster_path = os.path.join(fluv_fgdb, fluv_raster)
                nhd_raster_path = os.path.join(nhd_gdb, nhd_raster)
                out_raster_name = nhd_raster + "_Floodplain"
                out_raster_path = os.path.join(output_fgdb, out_raster_name)
                OutMedResFloodplain = arcpy.management.MosaicToNewRaster(pluv_raster_path, fluv_raster_path, nhd_raster_path, output_fgdb, out_raster_name, "NAD_1983_Albers", "8_BIT_UNSIGNED", "30", "1", "Last", "First") 
                &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Feb 2021 14:16:39 GMT</pubDate>
    <dc:creator>KathleenHoenke</dc:creator>
    <dc:date>2021-02-01T14:16:39Z</dc:date>
    <item>
      <title>Match three rasters in a if/else loop?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1022088#M25127</link>
      <description>&lt;P&gt;I had created a script with help from the community that takes two rasters of the same name and merges them together (&lt;A href="https://community.esri.com/t5/geoprocessing-questions/loop-through-rasters-and-extract-by-masks-of-polygon-fcs-with/m-p/1020562#M25124" target="_self"&gt;here&lt;/A&gt;). I now need to bring in a third raster and mosaic them together as well. However, when I go about matching them, I get this error&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 45, in &amp;lt;module&amp;gt;&lt;BR /&gt;IndexError: list index out of range&lt;/P&gt;&lt;P&gt;&amp;nbsp;I wanted to see if I'm going about this the wrong way or if this is even possible to match in this way? TIA!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
from arcpy import env

#not a fan of stating the obvious, but change the paths below to your fgdbs
#also keep the r then surround the path in quotes

#fgdb of rasters being merged
pluv_fgdb = r'E:\FATHOM\2020FATHOM\Analysis\Pluvial_1in100\Pluvial_1in100_Processed.gdb'

fluv_fgdb = r'E:\FATHOM\2020FATHOM\Analysis\Fluvial_1in100\Fluvial_1in100_Processed.gdb'

nhd_fgdb = r'E:\FATHOM\2020FATHOM\Analysis\NHDplusMedium_flowlines_Rast_Expand_HUC02.gdb'


#preferably empy fgdb to put outputs
output_fgdb = r'E:\FATHOM\2020FATHOM\Analysis\Final_Floodplain_Bounds_No_NHD.gdb'


#list all the rasters

arcpy.env.workspace = pluv_fgdb

pluv_rasters = arcpy.ListRasters("*", "GRID")
print (pluv_rasters)

arcpy.env.workspace = fluv_fgdb

fluv_rasters = arcpy.ListRasters()
print (fluv_rasters)

arcpy.env.workspace = nhd_fgdb

nhd_rasters = arcpy.ListRasters()
print (nhd_rasters)

#make a dictionary of source raster path
#to clipping fc and source name
#NB relies on names after the '_' being equal
input_floodplain_pieces_dict = {}

for pluv_raster in pluv_rasters:
    for fluv_raster in fluv_rasters:
        for nhd_raster in nhd_rasters:
            if pluv_raster.split("_Mask")[1] == fluv_raster.split("_Mask")[1] == nhd_raster.split("_")[-1]:
                pluv_raster_path = os.path.join(pluv_fgdb, pluv_raster)
                fluv_raster_path = os.path.join(fluv_fgdb, fluv_raster)
                nhd_raster_path = os.path.join(nhd_gdb, nhd_raster)
                out_raster_name = nhd_raster + "_Floodplain"
                out_raster_path = os.path.join(output_fgdb, out_raster_name)
                OutMedResFloodplain = arcpy.management.MosaicToNewRaster(pluv_raster_path, fluv_raster_path, nhd_raster_path, output_fgdb, out_raster_name, "NAD_1983_Albers", "8_BIT_UNSIGNED", "30", "1", "Last", "First") 
                &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 14:16:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1022088#M25127</guid>
      <dc:creator>KathleenHoenke</dc:creator>
      <dc:date>2021-02-01T14:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Match three rasters in a if/else loop?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1022114#M25128</link>
      <description>&lt;P&gt;I'd get rid of any references to the dictionary, it just confuses things.&lt;/P&gt;&lt;P&gt;It's likely when you call the index [1] on the .split list.&amp;nbsp; You should really add print statements to see what's going on - such as:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print(pluv_raster.split("_Mask")[1])&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 01 Feb 2021 14:57:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1022114#M25128</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-02-01T14:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Match three rasters in a if/else loop?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1022428#M25131</link>
      <description>&lt;P&gt;Thank you - that did work and help me to make sure I got the 0 and 1s correct.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I'm receiving this error:&lt;/P&gt;&lt;P&gt;arcgisscripting.ExecuteError: ERROR 000622: Failed to execute (Mosaic To New Raster). Parameters are not valid.&lt;BR /&gt;ERROR 000628: Cannot set input into parameter coordinate_system_for_the_raster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 04:01:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1022428#M25131</guid>
      <dc:creator>KathleenHoenke</dc:creator>
      <dc:date>2021-02-02T04:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: Match three rasters in a if/else loop?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1022600#M25134</link>
      <description>&lt;P&gt;I've not gone though the whole code, only the error you have, but:&lt;/P&gt;&lt;P&gt;The mosaic to new raster tool&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/mosaic-to-new-raster.htm" target="_blank"&gt;Mosaic To New Raster (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;expects the input rasters argument to be a list.&amp;nbsp; The tool is misinterpreting each raster as an incorrect argument to the tool.&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;OutMedResFloodplain = arcpy.management.MosaicToNewRaster([pluv_raster_path, fluv_raster_path, nhd_raster_path], output_fgdb, out_raster_name, "NAD_1983_Albers", "8_BIT_UNSIGNED", "30", "1", "Last", "First") &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 16:28:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1022600#M25134</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-02-02T16:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: Match three rasters in a if/else loop?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1023237#M25140</link>
      <description>&lt;P&gt;Perfect, thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 23:25:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/match-three-rasters-in-a-if-else-loop/m-p/1023237#M25140</guid>
      <dc:creator>KathleenHoenke</dc:creator>
      <dc:date>2021-02-03T23:25:53Z</dc:date>
    </item>
  </channel>
</rss>

