[gdal-dev] creating .VRT files with the python bindings

Ricardo Filipe Soares Garcia da ricardo.garcia.silva at gmail.com
Mon Jan 31 20:27:36 EST 2011


Hello list
I am trying to create a .VRT file to mosaic a bunch of HDF5 files. It
is starting to work, except for the fact that I can't seem to set the
relativeToVRT attribute of the SourceFilename tag to "0".

I've been adapting the online vrt tutorial[1] from C++ to Python. The
tutorial says that relativeToVRT will default to "0", but I'm getting
the exact opposite. It is defaulting to "1", and even if I try to set
it to "0" explicitly when using the SetMetadataItem method, it will
still be saved as a "1". I have included an excerpt of the code at the
end of this message. I'll post the rest of it if it is relevant.

After saving the file, I can open a text editor and replace all the
"1" with "0" and this fixes it, allowing me to get the desired
visualization (on QGIS).

Am I doing something wrong here? Or is this possibly a bug? I'm using
gdal 1.7.3, as available on the ubuntugis-unstable repository.


Another question: is it possible to use derived bands via python
bindings? I guess I'll have to write a pixel function and somehow
register it with gdal...

[1] - http://www.gdal.org/gdal_vrttut.html

[2] - python code follows:


def get_xml_source(fileName, dataSet, xSize, ySize, dType, blockX,
                   blockY, sXOff, sYOff, sXSize, sYSize, dXOff,
                   dYOff, dXSize, dYSize, relToVRT=0, band=1):
    template = """
    <SimpleSource>
    <SourceFilename relativeToVRT='%i'>HDF5:%s://%s</SourceFilename>
    <SourceBand>%i</SourceBand>
    <SourceProperties RasterXSize='%i' RasterYSize='%i' DataType='%s'
BlockXSize='%i' BlockYSize='%i' />
    <SrcRect xOff='%i' yOff='%i' xSize='%i' ySize='%i' />
    <DstRect xOff='%i' yOff='%i' xSize='%i' ySize='%i' />
    </SimpleSource>
    """
    return template % (relToVRT, fileName, dataSet, band, xSize, ySize,
                       dType, blockX, blockY, sXOff, sYOff, sXSize, sYSize,
                       dXOff, dYOff, dXSize, dYSize)

.... somewhere down the code...

xmlSource = get_xml_source(lit, dataSet, xResolution, yResolution,
                                   "Int16", blockXSize, blockYSize, 0, 0,
                                   xResolution, yResolution, xOff, yOff,
                                   xResolution, yResolution)
outBand.SetMetadataItem("teste", xmlSource, "new_vrt_sources")


-- 
___________________________ ___ __
Ricardo Garcia Silva


More information about the gdal-dev mailing list