[gdal-dev] building a vrt to stack overlapping COGs with a mask/alpha band

Landry Breuil breuil at craig.fr
Fri Jul 10 01:41:54 PDT 2020


On 09/07/2020 10:09, Landry Breuil wrote:
> On 08/07/2020 13:23, Even Rouault wrote:
>> On mercredi 8 juillet 2020 10:12:31 CEST Landry Breuil wrote:
>>

<snip>

> 
>> Your best option with VRT would be to use a NoData value instead if 
>> you can.
> 
> You mean setting a nodata value when building the COGs (ie 
> gdal_translate -a_nodata 0 -of COG dataset.vrt dataset.tif) instead of 
> the alpha/mask band, and then using this nodata value as -srcnodata 0 
> parameter to gdalbuildvrt ?

So i tried this nodata method, it sort of works, ie i can stack the COGs 
on top of each other via the VRT, and they're blended together at 
display time.. unless (and i already hit that in the past) on the 
borders of the COG one can see ugly artifacts of the JPEG compression 
going 'outside' the original area:

https://imgur.com/t0hwdvx.png

https://imgur.com/RqJXbmx.png

to workaround this in the past, i had built a contraption/script that 
'worked' but wasnt fully satisfying:
- creating a geojson with a cutline from the tileindex (ogr2ogr -dialect 
SQLITE -f GeoJSON -sql "SELECT buffer(GUnion(GEOMETRY), -12, 1) from 
tileindex)
- warping the vrt with the cutline via gdalwarp
- compressing the result via gdal_translate (not COG yet, but TIFF with 
JPEG/YCBCR)
- and then adding overviews separately via gdaladdo

i'm unsure this method is still the way to go to eradicate artifacts on 
the borders of image, as i had sometimes artifacts *in the overviews* 
which were also JPEG-compressed.

Landry


More information about the gdal-dev mailing list