[gdal-dev] Image compositing in VRT files
Jorge Arévalo
jorge.arevalo at deimos-space.com
Fri Feb 11 08:37:10 EST 2011
2011/2/11 Alain Cembro <acembro at yahoo.com>:
> Hello Jorge,
>
>
> --- On Fri, 2/11/11, Jorge Arévalo <jorge.arevalo at deimos-space.com> wrote:
>
>> You probably can use gdal_vrtmerge.py script in this way:
>>
>> gdal_vrtmerge.py -o out.vrt <list of tiff files>
>>
>> You can modify the out.vrt file to include only the bands
>> you're interested in.
>
> Sorry, it doesn't work :
>
> If I put the roads.tif first, there is an exeption :
>
> $ gdal_vrtmerge.py -o test.vrt roads.tif photos.tif
> Traceback (most recent call last):
> File "/usr/share/gdal/samples/gdal_vrtmerge.py", line 320, in <module>
> fi.write_source(t_fh, geotransform, xsize, ysize, band)
> File "/usr/share/gdal/samples/gdal_vrtmerge.py", line 150, in write_source
> data_type_name = gdal.GetDataTypeName(self.band_types[s_band])
> IndexError: list index out of range
>
> If I put the photos.tif first, a VRT file is created, but I can only see the roads on a white background instead of the photos background.
>
> $ gdal_vrtmerge.py -o test.vrt photos.tif roads.tif
>
> More infos :
>
> $ gdalinfo roads.tif
> Band 1 Block=256x256 Type=Byte, ColorInterp=Red
> Mask Flags: PER_DATASET ALPHA
> Band 2 Block=256x256 Type=Byte, ColorInterp=Green
> Mask Flags: PER_DATASET ALPHA
> Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
> Mask Flags: PER_DATASET ALPHA
> Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha
>
> $ gdalinfo photos.tif
> Band 1 Block=256x256 Type=Byte, ColorInterp=Red
> Band 2 Block=256x256 Type=Byte, ColorInterp=Green
> Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
>
> $ gdalinfo test.vrt
> Band 1 Block=128x128 Type=Byte, ColorInterp=Red
> Band 2 Block=128x128 Type=Byte, ColorInterp=Green
> Band 3 Block=128x128 Type=Byte, ColorInterp=Blue
>
>
>
>
>
Hello,
The error is caused because both files have different band number. If
you put road.tif first (4 bands), the script tries to fetch 4 bands
from all files, and fails with the 3-bands tif photos.tif. When you
put photos.tif in first place, then the scripts takes 3 bands for all
files, and you lose the alpha band (that's the reason of white bg
instead a transparent one)
I'm not sure if I'm talking nonsense, but you may use one of the bands
from photos.tif as alpha channel for the resulting vrt file. You can
change the VRT file by hand (http://www.gdal.org/gdal_vrttut.html)
Sorry, I don't know if it really helps... Maybe I'm wrong
--
Jorge Arévalo
Internet & Mobilty Division, DEIMOS
jorge.arevalo at deimos-space.com
http://es.linkedin.com/in/jorgearevalo80
http://mobility.grupodeimos.com/
http://www.twitter.com/jorgeas80
http://gis4free.wordpress.com
http://geohash.org/ezjqgrgzz0g
More information about the gdal-dev
mailing list