[Gdal-dev] VRTWarpedDataset w/ -dstalpha

Dardo D Kleiner - CONTRACTOR dkleiner at cmf.nrl.navy.mil
Fri May 20 14:17:37 EDT 2005


>> [src1.tif] [src2.tif] [src3.tif] . . . [srcN.tif] (say, 10k x 10k images)
>>      |          |          |                |
>> [src1.vrt] [src2.vrt] [src3.vrt] . . . [srcN.vrt] (add georeferencing)
>>      \          \          /                /
>>       \          \        /                /
>>        \          \      /                /
>>         \---------[src.vrt]--------------/ (i.e. a vrt mosaic)
>>                       |
>>                       | gdalwarp -of vrt -s_srs EPSG:xxxx -t_srs EPSG:4326 \
>>                       |       -co ALPHA=YES -dstalpha src.vrt dest.vrt
>>                       |
>>         /---------[dest.vrt]-------------\
>>        /           /     \                \
>>       /           /       \                \
>>      /           /         \                \
>> [dest1.vrt] [dest2.vrt] [dest3.vrt] . . . [destM.vrt] (512 x 512 tile grid)
>>      |           |           |                 |
>> [dest1r.vrt] [dest2r.vrt] [dest3r.vrt] . . . [destMr.vrt] (VRTRawRasterBand)
>>      |           |           |                 |
>> [dest1.8888] [dest2.8888] [dest3.8888] . . . [destM.8888] (raw tiles)

> I'm not sure I follow your whole tree of .vrt's concept properly.  Is dest.vrt
> using a bunch of <SimpleSource>'s to refer to individual tiles?  You should
> be able to read from such a thing, but you cannot write to it. 

dest.vrt is created by the gdalwarp command in the middle of the tree.  So it
is a VRTWarpedDataset that references the src.vrt mosaic and specifies the warp
options from the source projection to WGS84.  Then each dest?.vrt uses a
<SimpleSource> and <SrcRect> to read small tile-sized regions from the "main"
dest.vrt file.  

So all the way down the tree to the "512 x 512 tile grid" row, each vrt is
reading from the row above it, either via <SimpleSource>, or, in the case of
dest.vrt, via <SourceDataset> within <GDALWarpOptions>.

At the bottom, each dest?r.vrt is supposed to specify the raw output format, i.e.

<VRTDataset rasterXSize="512" rasterYSize="512">
        <VRTRasterBand dataType="Byte" band="1" subClass="VRTRawRasterBand">
                <ColorInterp>Red</ColorInterp>
                <SourceFilename relativetoVRT="1">dest?.8889</SourceFilename>
                <ImageOffset>0</ImageOffset>
                <PixelOffset>4</PixelOffset>
                <LineOffset>2048</LineOffset>
        </VRTRasterBand>
        <VRTRasterBand dataType="Byte" band="2" subClass="VRTRawRasterBand">
                <ColorInterp>Green</ColorInterp>
                <SourceFilename relativetoVRT="1">dest?.8888</SourceFilename>
                <ImageOffset>1</ImageOffset>
                <PixelOffset>4</PixelOffset>
                <LineOffset>2048</LineOffset>
        </VRTRasterBand>
        <VRTRasterBand dataType="Byte" band="3" subClass="VRTRawRasterBand">
                <ColorInterp>Blue</ColorInterp>
                <SourceFilename relativetoVRT="1">dest?.8888</SourceFilename>
                <ImageOffset>2</ImageOffset>
                <PixelOffset>4</PixelOffset>
                <LineOffset>2048</LineOffset>
        </VRTRasterBand>
        <VRTRasterBand dataType="Byte" band="4" subClass="VRTRawRasterBand">
                <ColorInterp>Alpha</ColorInterp>
                <SourceFilename relativetoVRT="1">dest?.8888</SourceFilename>
                <ImageOffset>3</ImageOffset>
                <PixelOffset>4</PixelOffset>
                <LineOffset>2048</LineOffset>
        </VRTRasterBand>
</VRTDataset>

> Try not including the "-of vrt"  part.  When gdalwarp sees you have 
> "-of VRT" it does alot of special stuff to write out a new VRT describing
> the warp instead of actually performing the warp.  But you should be able
> to warp into a preexisting raw file described with a .vrt file.  

I've found that if I 'touch' the dest?.8888 file before warping (without
specifying "-of vrt"), I get the following error:

"ERROR 5: Destination band 1 appears to be read-only."

If I don't specify "-of vrt", even though the output already exists it gets
overwritten as a GeoTIFF file.

>>  On a more philosophical level, is it insane?

> Umm, you should be aware that you are stressing things a bit beyond what
> I had in mind.  In particular, be aware that having .vrt files using
> <SimpleSource>
> to describe mosaics of many tiles may have performance problems.  The 
> implementation of the <SimpleSource> mechanism does *not* scale gracefully
> up to hundreds of thousands of files.  Though it should work fine for dozens
> of files.

At most I'd have a 3-5 thousand source images.  Up to now, I've been warping
each individual source file, then mosaicing the bunch, then chopping up the
mosaic into my desired 512 x 512 tiles.  This method is very time consuming as
well as space consuming, and for mosaics that approach 2^20 pixels in
width/height it's just impossible.  When I realized the potential of VRT to
give me a single-phase operation, I thought I'd give it a shot.

Thanks again!
- Dardo




More information about the Gdal-dev mailing list