I had created a script with help from the community that takes two rasters of the same name and merges them together (here). 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
Traceback (most recent call last):
File "<string>", line 45, in <module>
IndexError: list index out of range
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!
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")