Is there a python module to create Virtual Raster (.vrt) xml files? Rather than writing text strings to a file, I'd like to know if there is an automated way to do this.

  • 1
    subprocess.Popen(['gdalbuildvrt','c:\\full\\path\\vrt_file.vrt','d:\\path\\to\\image.tif']) - works for me! no need to reinvent the wheel. Read up on gdal.org/gdalbuildvrt.html to see if there's additional parameters you need to suit your purposes. Jun 16, 2016 at 22:36
  • The GeoTiff's aren't geolocated, and need to be referenced via the .vrt files to a separate data set of lat/lon values which aren't uniformly spaced.
    – rakbar
    Jun 16, 2016 at 22:40
  • I believe this is a possible solution:stackoverflow.com/questions/3605680/…
    – rakbar
    Jun 16, 2016 at 22:50
  • If they're not geolocated then they're not GeoTiff, just TIF. You should be able to write a world file for each given you know the parameters (Xmin, Ymax, cellX, cellY) kralidis.ca/gis/worldfile.htm to geolocate them and then call GDALbuildVRT. Why muck around with XML enclosures if there's already a tool that will do it for you... trust me there's too much chance of misspelling a key or putting it in the wrong order which is frustrating and complicated. Jun 16, 2016 at 23:21
  • Thanks! The word files assumed uniform spacing between lat/long values? is this correct?
    – rakbar
    Jun 17, 2016 at 16:24

1 Answer 1


This was implemented in RFC59.1 in GDAL release 2.1.0.

def BuildVRTOptions(options = [],
                resolution = None,
                outputBounds = None,
                xRes = None, yRes = None,
                targetAlignedPixels = None,
                separate = None,
                bandList = None,
                addAlpha = None,
                resampleAlg = None,
                outputSRS = None,
                allowProjectionDifference = None,
                srcNodata = None,
                VRTNodata = None,
                hideNodata = None,
                callback = None, callback_data = None):
""" Create a BuildVRTOptions() object that can be passed to gdal.BuildVRT()
    Keyword arguments are :
      options --- can be be an array of strings, a string or let empty and filled from other keywords..
      resolution --- 'highest', 'lowest', 'average', 'user'.
      outputBounds --- output bounds as (minX, minY, maxX, maxY) in target SRS.
      xRes, yRes --- output resolution in target SRS.
      targetAlignedPixels --- whether to force output bounds to be multiple of output resolution.
      separate --- whether each source file goes into a separate stacked band in the VRT band.
      bandList --- array of band numbers (index start at 1).
      addAlpha --- whether to add an alpha mask band to the VRT when the source raster have none.
      resampleAlg --- resampling mode.
      outputSRS --- assigned output SRS.
      allowProjectionDifference --- whether to accept input datasets have not the same projection. Note: they will *not* be reprojected.
      srcNodata --- source nodata value(s).
      VRTNodata --- nodata values at the VRT band level.
      hideNodata --- whether to make the VRT band not report the NoData value.
      callback --- callback method.
      callback_data --- user data for callback.

def BuildVRT(destName, srcDSOrSrcDSTab, **kwargs):
    """ Build a VRT from a list of datasets.
        Arguments are :
          destName --- Output dataset name
          srcDSOrSrcDSTab --- an array of Dataset objects or filenames, or a Dataset object or a filename
        Keyword arguments are :
          options --- return of gdal.InfoOptions(), string or array of strings
          other keywords arguments of gdal.BuildVRTOptions()
        If options is provided as a gdal.BuildVRTOptions() object, other keywords are ignored. """

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.