QGIS icon indicating copy to clipboard operation
QGIS copied to clipboard

Add "COG" ( Cloud Optimized GeoTIFF generator) as possible output format in GDAL based tools

Open ramotswa opened this issue 4 years ago • 10 comments

Feature description. I would like to be able to export a raster layer as a COG - be it via a checkbox option in the dialog or just as a format option.

Additional context I know that via the 'Export Raster' dialog I can get close (or possibly all the way) to COG by specifying TILED and a BLOCK{X,Y}SIZE as 512, but I still get an error when trying to validate the output tiff. I guess there are other create options I can use to fix those errors but it still seems a bit overkill considering a small change to the output format drop down to include 'COG' might be possible?

Errors:

The offset of the main IFD should be 8. It is 6291930 instead
The offset of the first block of the image should be after its IFD

Thanks

ramotswa avatar Mar 01 '21 17:03 ramotswa

@ramotswa COG = https://gdal.org/drivers/raster/cog.html ?

gioman avatar Mar 01 '21 17:03 gioman

Yes indeed.

ramotswa avatar Mar 01 '21 17:03 ramotswa

@ramotswa look at the GDAL "translate" tool in the QGIS Processing toolbox, you have the option to add yourself new GDAL "creation options". For this format it seems you need to add the

COPY_SRC_OVERVIEWS=YES

one. You'll probably will find more infos in the GDAL man page.

gioman avatar Mar 01 '21 17:03 gioman

That will only work if the file already has overviews which would make this a manual, two-or-more-step process. It would be great if the COG driver was directly selectable so GDAL could do all the magic.

kannes avatar Mar 01 '21 18:03 kannes

Thanks @kannes . @gioman - even with that command it doesn't work as expected. Using input image s3://planet-disaster-data/hurricane-harvey/SkySat_Freeport_s03_20170831T162740Z3.tif Adding as a raster layer via S3. Then using the toolbox GDAL translate with that -co flag gives this command:

gdal_translate -of GTiff -co COPY_SRC_OVERVIEWS=YES /vsis3/planet-disaster-data/hurricane-harvey/SkySat_Freeport_s03_20170831T162740Z3.tif /Users/me/Downloads/skysat_test.tif

But clearly (surely?) that won't work as the -of is still GTiff right?

ramotswa avatar Mar 01 '21 18:03 ramotswa

You can try to build overviews/pyramids for the file first, then try the export as suggested by gioman. That might work.

COG is just a special structure of GeoTIFF which you should get by doing these steps.

kannes avatar Mar 01 '21 19:03 kannes

@ramotswa @kannes so, as far as I understand we should add "COG" option (to be used as " -of COG") among the list of the possible output formats (in GDAL based tools) but still maintain the .tiff extension for the same output, correct?

gioman avatar Mar 02 '21 11:03 gioman

Hi @gioman - yes that sounds good.

ramotswa avatar Mar 02 '21 11:03 ramotswa

any news on this? I've been manually running GDAL command line to get COGs since 2.x. Exporting them from QGIS would be handy

arkanoid87 avatar May 07 '23 19:05 arkanoid87

On our side, we're using a mixture of gdal -of COG and rio-cogeo CLI. Would love to have the COG export option (in addition to standard GTiff option) for non tech-savvy users!

If there are some pointers as to where to implement this feature, would love to give it a try (although I've never built qgis on my own yet)

jo-chemla avatar Jun 29 '23 15:06 jo-chemla

I also would love this. Seems like it could be done with either gdalwarp or gdal_translate. It would save me lots of re-writing files... These are my typical commands, optimized over several years for speed and file size, thanks to many folks posting in many places (I know some or all of these could be exposed options for the cog driver in the QGIS GUI, which would be great):

gdalwarp method gdalwarp -of cog -overwrite -multi --config GDAL_CACHEMAX 9000 -wm 9000 -co BLOCKSIZE=256 -co BIGTIFF=YES -co COMPRESS=DEFLATE -co PREDICTOR=YES -co NUM_THREADS=ALL_CPUS

gdal_translate method gdal_translate -of COG -co BLOCKSIZE=256 -co COMPRESS=DEFLATE -co PREDICTOR=YES -co NUM_THREADS=ALL_CPUS -co BIGTIFF=YES --config GDAL_CACHEMAX 9000

-edit- I just went into the preferences to see if I could make a "create" profile for COG and saw that in QGIS v3.32.0 /settings/options/raster drivers the gdal cog driver is listed with flags rwv and not rw+v - what does it take to get the + in there?

aritchie-usgs avatar Jul 14 '23 03:07 aritchie-usgs

Any news on this? As a end user i would like this feature too.

GO1984 avatar Mar 24 '24 09:03 GO1984

following.

This seems like a great option to add. I believe GDAL should be creating all tifs as cog by default, but I fear the way the output specs are handled in the processing tools forces standard GTIFF.

tomkom avatar Jun 03 '24 06:06 tomkom