1

I am trying to mosaic images with same dates in a folder. As there are images with different dates in the folder folder containing images

I have looped through the images with just SR_clip.tif extension using wildcard that I require but unable to figure out which logical operator to use which specifies if my images have the same dates create a mosaic or else move on to the next images with same dates and create a new mosaic.

Model Builder to iterate through all images with specified wildcard

1 Answer 1

0
import arcpy

# Set the current workspace
arcpy.env.workspace = "D:/datasets/planetscope/2021/2021_09-2021_08_psscene_analytic_sr_udm2/copy raster udm"
location = "D:/datasets/planetscope/2021/2021_09-2021_08_psscene_analytic_sr_udm2/mosaic"

# Get and print a list of GRIDs from the workspace
#rasters = arcpy.ListRasters("*Analytic*", "TIF")
#for raster in rasters:
  #  print(raster)
    
rasters = arcpy.ListRasters("*udm2*", "TIF")
for raster in rasters:
    print(raster)
values = set(map(lambda x:x.split('_')[-7], rasters)) #Find unique groups
values
newlist = [[y for y in rasters if y.split('_')[-7]==x] for x in values] #From the rasterlist, create a new list of 
#lists of grouped rasters
    
for group in newlist:
    if len(group)>0: #Dont mosaic single rasters
        outname='udm2_Mosaic_{0}.tif'.format(group[0].split('_')[-7])
        arcpy.MosaicToNewRaster_management(input_rasters=group, 
                                           output_location = location,raster_dataset_name_with_extension=outname, 
                                           pixel_type="8_BIT_UNSIGNED",cellsize="", number_of_bands="8", 
                                           mosaic_method="BLEND",mosaic_colormap_mode="MATCH")  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.