1

I'm new using python and I'm trying to create a Virtual Raster mosaicing 3 raster images of Landsat in a time series. So I'm trying with gdal.BuildVRT but it doesn't work? I'll show the code:

    from osgeo import gdal
    import os
    import glob

    #SET PATH 
    path = 'D:\Imagery\L8 OLI TIRS'
    x = len(files))/3 #IN THE FILE I HAVE 3 TILES FOR EACH DATE
    """
    example with only one date
    NDVI
    """
    #subset route:
    in_subRoute = files[0]+'-'+files[0+x]+'-'+files[0+x*2] #string, every 'files' equals to a directory of a tile.
    subRoute = in_subRoute.split('-') #to list
    Dirmosaic = "D:\Results\mosaic.vrt" 
    gdal.BuildVRT(Dirmosaic, subRoute)

but doesn't happen anything

What am I doing wrong?

2

The following code solved my problem to mosaic a lot of MODIS images in a folder. The code get the day of year of the file name and mosaic the images with the same day in common. Copy this code to a python script (example: mosaic.py), put in the images folder and run. It will create the mosaic as *.vrt files which you can convert to *.tif later. Adapt the "MOD11_L2.A2014" and "_LST.vrt" names to your project data.

 #!/usr/bin/env python
    #coding: utf-8
    from osgeo import gdal
    import glob
    for day in range(0, 32):
    day = str('%0.3d' % day)
    gdal.BuildVRT("MOD11_L2.A2014"+day+"_LST.vrt", glob.glob("MOD11_L2.A2014"+day+"*.tif"))
0

Does this need to be in Python? Just use the command-line utility (assuming it was installed, e.g. with osgeo4w) with something like this:

gdalbuildvrt "D:\Results\mosaic.vrt" "D:\Imagery\L8 OLI TIRS\*"

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.