Cogger is a standalone binary and a golang library that reads an internally tiled geotiff (optionally with overviews and masks) and rewrites it as a Cloud Optimized Geotiff (COG). This process being a reshuffling of the original geotiff's bytes, it should run as fast as the underlying disk or network i/o.
Cogger does not do any pixel manipulation on the provided image, it is up to you to provide an input geotiff which can be suitably transformed to a COG, namely:
- it must be internally tiled
- it should be compressed with one of the standard supported tiff compression mechanisms
- it should contain overviews
We publish the cogger
binaries for the major platforms/cpus, which you can grab from our releases
The library version of cogger
can be used in go code with:
import "github.com/airbusgeo/cogger"
The cogger binary can be installed directly to your $GOPATH/bin
with:
go install github.com/airbusgeo/cogger/cmd/cogger@latest
gdal_translate -of GTIFF -co BIGTIFF=YES -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 input.file geotif.tif
gdaladdo --config GDAL_NUM_THREADS 4 --config COMPRESS_OVERVIEW ZSTD geotif.tif 2 4 8 16 32
cogger -output mycog.tif geotif.tif
gdal_translate -of GTIFF -co BIGTIFF=YES -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 input.file geotif.tif
gdaladdo -ro --config GDAL_NUM_THREADS 4 --config COMPRESS_OVERVIEW ZSTD geotif.tif 2 4 8 16 32 #creates geotif.tif.ovr
cogger -output mycog.tif geotif.tif geotif.tif.ovr
The cogger API consists of a single function:
func Rewrite(out io.Writer, readers ...tiff.ReadAtReadSeeker) error
with the reader allowing random read access to the input file, i.e. implementing
Read(buf []byte) (int,error)
ReatAt(buf []byte, offset int64) (int,error)
Seek(off int64, whence int) (int64,error)
The writer is a plain io.Writer
which means that the output cog can be directly
streamed to http/cloud storage without having to be stored in an intermediate file.
For an full example of library usage, see the main.go
file in cmd/cogger
.
Cogger is able to assemble a single COG from a main tif file and overviews that have been computed
in distinct files. This may be useful as gdaladdo
is missing some features to fine tune the options
of each individual overview.
gdal_translate -of GTIFF -co BIGTIFF=YES -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 input.file geotif.tif
# compute first overview
gdal_translate -of GTIFF -outsize 50% 50% -co BLOCKXSIZE=128 -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 geotif.tif ovr.tif.1
# compute second overview
gdal_translate -of GTIFF -outsize 50% 50% -co BLOCKXSIZE=256 -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 ovr.tif.1 ovr.tif.2
# compute third overview
gdal_translate -of GTIFF -outsize 50% 50% -co BLOCKXSIZE=512 -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 ovr.tif.2 ovr.tif.3
# compute COG from geotif.tif and ovr.tif.* overviews
cogger -output mycog.tif geotif.tif ovr.tif.1 ovr.tif.2 ovr.tif.3
Contributions are welcome. Please read the contribution guidelines before submitting fixes or enhancements.
Cogger is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.