If you want to order the tif files by coordinate pair this will do it.
from osgeo import gdal tiffiles=["basefilename-99-100.tif","basefilename-98.7-200.tif","basefilename-101-300.tif","basefilename-100.25-400.tif","basefilename-99.925-500.tif","basefilename-97.552-100.tif"] coordarray=[] tifdict={} for tf in tiffiles: ds = gdal.Open(tf) w = ds.RasterXSize h = ds.RasterYSize gtrans = ds.GetGeoTransform() minx = gtrans[0] miny = gtrans[3] + w*gtrans[4] + h*gtrans[5] # splittifname=tf.split("-") coords=(minx,miny) coordarray.append(coords) tifdict[coords]=tf coordarray=sorted(coordarray,key=lambda k:(k[0],k[1])) for coord in coordarray: ### DO STUFF TO COMBINE THE RASTER TO A STACK print(tifdict[coord])
I don't think I explain myself clearly, this will put your tif in order by coordinate from min x min y of the set, then you can merge or place the file names in order on .txt file and batch process. I change the code to use the coord value in the tif file instead of value in file name but I have not had a chance to test you may need to declare the spatial reference somewhere.