[GIS] Python Gdal write virtual raster

gdalpythonrasterxml

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.

Best Answer

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. """