[gdal-dev] VRT creation from Python, adding existing geotiff as bands

Even Rouault even.rouault at spatialys.com
Mon Feb 16 08:32:52 PST 2015


Le lundi 16 février 2015 17:23:49, Rémi Cura a écrit :
> Thank for the fast answers !
> 
> @EvenRouault  : thanks for the snippet, I wasn't aware of this mechanism to
> transmit option trough python dictionary.
> It should most likely be sufficient for my needs, even if I don't
> understand it fully yet.
> I had read the tutorial but failed to translate it from C++ to python.

The Python API is generally close to the C++ one. 
A not-so-pretty doc is available at http://gdal.org/python/

> I'm still _very_ reticent to create XML for VRT in python, I don't see how
> it could be safe and age well.

The XML schema of VRT files is really stable. I can't think of a backward 
incompatible change. The C++ API of the VRT driver allows to build most (but 
not necessarily all) VRT, and it is not exposed to the SWIG bindings.

> 
> @Anton :
> thanks for the lib, I'll look into vrt.py
> <https://github.com/nansencenter/nansat/blob/master/nansat/vrt.py> to try
> to understand how to add an existing tiff file as a band to vrt.
> I don't think I need "SourceTransferType", because the type of the vrt band
> will be the same as the type of the existing geotiff file.
> 
> Cheers,
> Rémi-C
> 
> 2015-02-16 15:11 GMT+01:00 Anton Korosov <anton.korosov at nersc.no>:
> > Dear Rémi,
> > 
> > you may want to look at our Python package NANSAT (https://github.com/
> > nansencenter/nansat) which we build around the GDAL and especially VRT.
> > We even have a separate class VRT() for creating, changing and using VRT
> > files.
> > More specific regarding your question, you can try to use the
> > SourceTransferType parameter of the VRT. Search for this keyword at
> > http://gdal.org/gdal_vrttut.html
> > 
> > Regards!
> > Anton
> > 
> > On 16/02/15 14:13, Rémi Cura wrote:
> >> Hey dear list,
> >> this is my first post here,
> >> so sorry if I'm asking something obvious.
> >> 
> >> (I noticed the 2 previous mail thread regarding python and VRT).
> >> 
> >> I wrote python functions to convert a numpy structured array to several
> >> gdal rasters.
> >> 
> >> A numpy structured array is a 2D pixel array, but each pixel has in fact
> >> several values of possibly different type (like band).
> >> For instance a pixel dtype can be [float32,uint16,Float64].
> >> 
> >> I want to convert this array to raster(s).
> >> First I tried to create one raster with several bands,
> >> but GeoTiff cannot handle bands with different pixel type (or I didn't
> >> find how).
> >> 
> >> I concluded that I must create several rasters, and put them all as
> >> bands in a VRT.
> >> 
> >> So far I have been able to create several geoTiff raster of various type
> >> corresponding to the numpy structured array.
> >> 
> >> Now, I don't know how to create from python the VRT that unites all this
> >> rasters.
> >> 
> >> When I try to write in a VRT raster band I get errors.
> >> 
> >> I am well aware that I could create the XML directly from python, but it
> >> feels like a pretty bad architecture idea.
> >> 
> >> Anybody knows how to do this /and/or has comments about this task?
> >> 
> >> Many Thanks,
> >> Rémi-C
> >> 
> >> 
> >> 
> >> 
> >> _______________________________________________
> >> gdal-dev mailing list
> >> gdal-dev at lists.osgeo.org
> >> http://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list