Cogger is a standalone binary and a golang library that reads an internally tiled geotiff

Cogger

Go Reference License

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

Installation

Binaries

We publish the cogger binaries for the major platforms/cpus, which you can grab from our releases

From source

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

Usage

Binary

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 geotif.tif 2 4 8 16 32
cogger -output mycog.tif geotif.tif

Library

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.

Advanced

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

Contributing

Contributions are welcome. Please read the contribution guidelines before submitting fixes or enhancements.

Licensing

Cogger is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Owner
Comments
  • ENH idea: emit header ghost area and tile header and trailer bytes

    ENH idea: emit header ghost area and tile header and trailer bytes

    For really huge COGs (let's say 1 million pixel x 1 million pixel), the size of the TileByteCount and TileOffsets values can be quite big (several tens of MB). If one knows that the tiles are ordered in a top-to-bottom, left-to-right order in the file, then a smart reader can possibly only use TileOffsets, and that's what GDAL does, to save a GET request. To do so, one must write the header ghost area per https://gdal.org/drivers/raster/cog.html#header-ghost-area and add a 4-byte header before each tile data and a 4-byte trailer after it (https://gdal.org/drivers/raster/cog.html#tile-data-leader-and-trailer), whose purpose is to check that a writer hasn't modified tile content since the COG generation, which would make the optimization no longer valid.

  • Overviews: optional or not?

    Overviews: optional or not?

    The read me says both "internally tiled geotiff (optionally with overviews" and "it should contain overviews". The statements are at odds with each other. Which is the more correct meaning?

  • Support of the separated mask *.msk file ?

    Support of the separated mask *.msk file ?

    Hi,

    Thanks a lot for this amazing tool ! I have just converted a 15Go ECW to GeoTiff with GDAL. To be able to use the YCBCR jpeg optimization, I have been "forced" to remove the 4th transparency band of the ECW. I used the -mask 4 to keep the transparency and avoid to have a big black rectangle.

    gdalinfo against the ecw gives: https://paste.sh/DAITkjGJ#P0ui5RBQaEDpDP0vQnHSWyny

    My use of gdal_translate & gdaladdo:

    # convert ecw to tif
    gdal_translate -a_srs EPSG:2154 -r nearest -co COMPRESS=JPEG -co JPEG_QUALITY=60 --config INTERLEAVE PIXEL -co PHOTOMETRIC=YCBCR -b 1 -b 2 -b 3 -mask 4 -co TILED=YES -co BIGTIFF=YES -co BLOCKXSIZE=512 -co BLOCKYSIZE=512 --config GDAL_CACHEMAX 500 --config GDAL_MAX_DATASET_POOL_SIZE 1014 -co NUM_THREADS=2 -of GTiff orthophoto.ecw orthophoto.tif
    
    # pyramids
    gdaladdo -r average -ro --config COMPRESS_OVERVIEW JPEG --config JPEG_QUALITY_OVERVIEW 60--config INTERLEAVE_OVERVIEW PIXEL --config PHOTOMETRIC_OVERVIEW YCBCR --config TILED_OVERVIEW YES --config GDAL_TIFF_OVR_BLOCKSIZE 512 --config BIGTIFF_OVERVIEW YES --config GDAL_CACHEMAX 500 --config GDAL_MAX_DATASET_POOL_SIZE 1014 -co NUM_THREADS=2 orthophoto.tif 2 4 8 16 32 64 128 256
    

    The output Geotiff is exactly what I expected, but with this -b 1 -b 2 -b 3 -mask 4 technique, I have four files: orthophoto.tif, orthophoto.tif.ovr, orthophoto.tif.msk, orthophoto.tif.msk.ovr

    Then I wanted to use cogger with

    ./cogger -output orthophoto.cog.tif orthophoto.tif orthophoto.tif.ovr
    

    I get the expected orthophoto.cog.tif file, but the mask has not been "integrated" into the cog, so I get the black rectangle around the data, for example when viewing this COG file inside QGIS.

    Do I need to create a new COG file from the orthophoto.tif.msk and orthophoto.tif.msk.ovr files, or is there a better way ?

  • Add advanced usage options/functionality (API only)

    Add advanced usage options/functionality (API only)

    • The gdal ghost area optimisations can be disabled, and will not be emitted for PlanarConfiguration=Separate, as it is not supported by gdal. Fixes #8
    • Each IFD may now reference only a single mask
    • The IFD structure is now exported and can be used to hand-craft an expected COG from dynamic data
    • Encoding (little vs. big endian) is now configurable
    • For PlanarConfiguration=Separate files, it is possible to fine tune the layout/interlacing of each plane's tiles and mask tiles, supporting tile orders like r1,g1,b1,r2,g2,b2 (the default), or r1,r2...g1,g2...b1,b2 or even r1,g1,r2,g2,...rn,gn,b1,b2
  • Remove gdal ghost area for planarconfiguration=separate

    Remove gdal ghost area for planarconfiguration=separate

    planarconfiguration=separate is not an officially recognized configuration for COGs, which is an oversight as the same principles as for planarconfiguration=contig also apply in this case. cogger should probably not emit a ghost area for those type of files so as not to confuse a parser using that information. c.f. opengeospatial/CloudOptimizedGeoTIFF#3 and OSGEO/gdal#4931

Related tags
Leftright - A concurrent map that is optimized for scenarios where reads are more frequent than writes

leftright A concurrent map that is optimized for scenarios where reads are more

Jan 30, 2022
This library provides an ASTERIX Frame(binary data) decoding/parsing(json,xml) capabilities for Go.

GoAsterix This library provides an ASTERIX Frame(binary data) decoding/parsing(json,xml) capabilities for Go. ASTERIX ASTERIX (All Purpose Structured

Dec 13, 2022
Elf binary infector written in Golang

Elf binary infector written in Golang. It can be used for infecting executables of type ET_DYN and ET_EXEC with a payload of your creation. Utilizing the classic elf text segment padding algorithm by Silvio Cesar, your payload (parasite) will run before native functionality of the binary effectively backooring the binary.

Dec 30, 2022
A fully Go userland with Linux bootloaders! u-root can create a one-binary root file system (initramfs) containing a busybox-like set of tools written in Go.

u-root Description u-root embodies four different projects. Go versions of many standard Linux tools, such as ls, cp, or shutdown. See cmds/core for m

Dec 29, 2022
Execute a binary from memory, without touching the disk. Linux only.
Execute a binary from memory, without touching the disk. Linux only.

Memit Execute a binary from memory, without touching the disk. Linux only. Available as both a Go module and a binary. Using the Go module The Command

Jan 5, 2023
Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package.
Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package.

Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package. The library allows you to call Go service methods from PHP with a minimal footprint, structures and []byte support.

Dec 28, 2022
A Go (golang) library for parsing and verifying versions and version constraints.

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

Jan 9, 2023
A well tested and comprehensive Golang statistics library package with no dependencies.

Stats - Golang Statistics Package A well tested and comprehensive Golang statistics library / package / module with no dependencies. If you have any s

Dec 30, 2022
GoDynamic can load and run Golang dynamic library compiled by -buildmode=shared -linkshared

GoDynamic can load and run Golang dynamic library compiled by -buildmode=shared -linkshared How does it work? GoDynamic works like a dynamic

Sep 30, 2022
A golang library to validate and format swiss social security numbers

s3n is a golang library to validate and format swiss social security numbers (aka. AVS in french and AHV in german).

Nov 15, 2021
🍕 Enjoy a slice! A utility library for dealing with slices and maps that focuses on type safety and performance.

?? github.com/elliotchance/pie Enjoy a slice! pie is a library of utility functions for common operations on slices and maps. Quick Start FAQ What are

Dec 30, 2022
Govalid is a data validation library that can validate most data types supported by golang

Govalid is a data validation library that can validate most data types supported by golang. Custom validators can be used where the supplied ones are not enough.

Apr 22, 2022
Golang library to act on structure fields at runtime. Similar to Python getattr(), setattr(), hasattr() APIs.

go-attr Golang library to act on structure fields at runtime. Similar to Python getattr(), setattr(), hasattr() APIs. This package provides user frien

Dec 16, 2022
A library for diffing golang structures

Diff A library for diffing golang structures and values. Utilizing field tags and reflection, it is able to compare two structures of the same type an

Dec 29, 2022
go-sundheit:A library built to provide support for defining service health for golang services
go-sundheit:A library built to provide support for defining service health for golang services

A library built to provide support for defining service health for golang services. It allows you to register async health checks for your dependencies and the service itself, and provides a health endpoint that exposes their status.

Dec 27, 2022
GoLang port of Google's libphonenumber library

phonenumbers golang port of Google's libphonenumber, forked from libphonenumber from ttacon which in turn is a port of the original Java library. You

Jan 4, 2023
A concurrent rate limiter library for Golang based on Sliding-Window rate limiter algorithm.

ratelimiter A generic concurrent rate limiter library for Golang based on Sliding-window rate limitng algorithm. The implementation of rate-limiter al

Jan 6, 2023
MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

Nov 29, 2021
Easy to use, light enough, good performance Golang library
 Easy to use, light enough, good performance Golang library

指令使用 特性 简单易用、足够轻量,避免过多的外部依赖,最低兼容 Window 7 等老系统 快速上手 安装 $ go get github.com/sohaha/zlsgo HTTP 服务 // main.go

Dec 29, 2022