I'm using ArcGIS Pro 2.9.3, and I want to use the Mosaic to New Raster tool to merge groups of rasters. I have many days that each have multiple rasters within them. For example, I have
July3a.tif
July3b.tif
July3c.tif
July10a.tif
July10b.tif
July10c.tif
July11a.tif
July11b.tif
July11c.tif
So in this case, I'd want to merge July3a.tif-July3c.tif into one raster, July3.tif, then July10a.tif-July10c.tif into July10.tif, and so on.
I've scratched out a basic while loop, but it only works for one day at a time, and it would be awfully time consuming to adjust the arguments for each and every day.
i = July3a.tif
while i = July3*.tif
arcpy.management.MosaicToNewRaster(i, output_location, July3.tif, {coordinate_system_for_the_raster}, {pixel_type}, {cellsize}, number_of_bands, {mosaic_method}, {mosaic_colormap_mode})
i += 1
Is it possible to make a loop that merges multiple days at once?
Best Answer
Here is the code you can use, obviously I don't have your data so I spoofed it up with text files, so you need to edit the code and replace the
txt
withtif
.Here is my sample data:
This code is developed for ArcMap so if you want to run it in ArcGIS Pro you need to change this line:
to