I'm using Jupyter Notebook and gdalbuildvrt to write a program that loads hundreds of rasters. I want to set an area of interest, and only keep rasters (or portions of rasters) that fall in this area.

Here's an example pulled from the internet, using the 'te' flag from the command line to set a bounding box:

gdalbuildvrt -te 5.8887,50.3332,9.4702,52.5212 output.vrt -input_file_list 

However, in the Python/Jupyter API, using BuildVRT, it isn't clear how to set the georeferenced extents:

outds = gd.BuildVRT(output.vrt, filelist, separate=True)

Simply adding 'te' causes a syntax error


After doing some digging, the answer is within the documentation, but not on the main BuildVRT page:


The answer to my above question is therefore to use the outputBounds argument, like so:

options = gd.BuildVRTOptions(outputBounds=(xmin, ymin, xmax, ymax), separate=True)

outds = gd.BuildVRT(outvrt, getfiles, options=options)

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.