1

When you download a large image from Google Earth Engine, it is in multiple small images. Each sub-image name contains the x_min and y_min coordinates of that image. enter image description here

It is described here - https://developers.google.com/earth-engine/image_upload#tfrecord

How to join all these .tif files into one .tif file in right order by using a Python script.

3

Merging tiles can be accomplished using:

  1. GDAL's gdal_merge. An example is given in calling gdal_merge into python script
  2. Rasterio's rasterio.merge. An example is given in Rasterio: tool for creating mosaic?

It is not necessary to order the tiles in a specific way... they are non-overlapping.

  • Are these tiles connected automatically in the right order? I mean if the correct order of tiles in 1-2-3-4 horizontally, I hope they will not be connected in some random fashion. All tiles are non-overlapping but adjoining (cab be vertical or horizontal) – Hariom Ahlawat Nov 6 at 17:08
0

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.

  • I want to combine tiff files to make one big tif file. They should be combined at their right places as per coordinates, not just random place. – Hariom Ahlawat Nov 5 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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