COG overview and how to create and validate a Cloud Optimised Geotiff

Sanket Saxena
3 min readJul 13, 2020

--

Cloud optimized GeoTIFF is a regular GeoTIFF file with an internal organization like tiling and overviews which can be leveraged by HTTP range request. This allows us to access only a portion of data in the raster file which we are interested in, rather than downloading the entire file itself.

COGs enable efficient streaming of data, opening up possibilities of fully cloud-based geospatial workflows that address the potential issue of data duplication. Since COG offers on-the-fly processing of raster data, cloud workflows can access single files online instead of needing to copy and cache the data locally.

COG being the same data format as GeoTiff, has legacy support which means all kinds of legacy GIS software which can read Geotiff, can also read the COG. So data providers need only produce one format.

For more information on the COG data format, please refer to cogeo.org.

Convert Geotiff into COG

GDAL is a go-to library for reading raster files. Using GDAL CLI we can convert GeoTIFF into COG.

It’s a two-step process:

1. Create Overviews

GDAL has a CLI command to create overviews called gdaladdo. The command must be run before the gdal_translate or the resulting GeoTIFF won’t be COG compliant.

$ gdaladdo -r average in.tif 2 4 8 16
  • Here ‘average’ is the resampling algorithm.

This results in creating 4 different overviews at zoom level 2, 4, 8, 16

2. Create tiles and compress GeoTiff

$ gdal_translate in.tiff out.tiff -co COMPRESS=LZW -co TILED=YES -co COPY_SRC_OVERVIEWS=YES
  • Creates tiles, copies existing overviews of GeoTiff, and compresses the GeoTiff.
  • Compression can be LZW or DEFLATE but the latter one is less compatible with some libraries.
  • If we want to download one band at once then INTERLEAVE=BAND option can be used.

This will result in images with tiles of dimension 256x256 pixel for main resolution, and 128x128 tiles for overviews.

Now, we have created an internal organization that a COG should have, we need to validate if the generated COG is valid or not.

Checking if a Geotiff is a valid COG

Generated COG can be verified using an opensource script as below

$ python validate_cloud_optimized_geotiff.py out.tif

Link for validate_cloud_optimized_geotiff.py.

Sample Valid COG result:

Sample Invalid COG result:

Once we get a valid COG result, we can put it up on a server for allowing its online access.

Rio-Cogeo CLI is also a wonderful tool to create and validate COGs.

Thanks for reading :)

--

--

Sanket Saxena

I love writing about software engineering and all the cool things I learn along the way.