Generating Cloud Optimized GeoTIFFs and Raster Tiles with GDAL
TL;DR gdalbuildvrt, gdal_translate, gdal_warp and gdaladdo
What is the Cloud-Optimized GeoTIFF Format
A Cloud Optimized GeoTIFF (COG) is a cloud-native geospatial raster data format designed for efficient storage and retrieval in cloud environments. COG files are structured to allow for selective access to specific portions of the raster data without the need to download the entire file. This is achieved by organizing the data into smaller blocks and using HTTP range requests to retrieve only the required portions. COGs are well-suited for cloud storage platforms, enabling faster and more cost-effective data access, particularly in applications involving large-scale geospatial datasets and distributed computing resources.
See the COG website for more in-depth information, and the COG-Explorer for a sample COG viewer.
How to Create a COG
The following outlines the basic steps for generating Cloud Optimized GeoTIFFs and raster tiles from one or more raw TIFF files.
Create the Mosaic
Separate the bands and add an alpha band that gdal can use.
|
Update 3/22/2022 - If you run into the error “gdalbuildvrt does not support heterogeneous projection” you can warp all the source TIFF files into the desired projection, then run the command above, using the warped vrt files as the source files. See this Stack Exchange post
|
|
Create the Desktop Cloud Optimized GeoTIFF
Force the NAD83 projection using either EPSG:6551 (NAD83 2011) or 3735.
Update 2/10/2022 - For Desktop GIS usage, higher clarity may be found by using the NEAREST resampling method at the expense of pixelation. When using this method, set the resampling to bilinear
or cubic
in the GIS software when adding the COG.
|
Create a Mosaic in WebMercator from the Original Mosaic
Use the ITRF00 transformation suitable for both 6551 and 3735.
|
Create the COG in WebMercator for use in a COG Server
If you want to use the COG in ArcGIS Server then use JPEG compression.
Using the default resampling works fine as does AVERAGE, BILINEAR and CUBIC (default).
Update 2/10/2022 - Using AVERAGE may provide more clarity for the overviews.
Update 11/27/2023 - In the creation options in gdal_translate, using SPARSE_OK=TRUE
can lead to errors when rendering the COG with certain software. To avoid these errors use SPARSE_OK=FALSE
. See this GitHub issue for more details.
|
Check your COG with the coggeotiff
cli tool
|
Generate Tiles with gdal_translate and gdaladdo
Use this method to output mbtiles instead of a COG for serving raster tiles.
|
|
Other Methods
These methods create satisfactory outputs and can be faster, but can cause projection shifts. These may still be satisfactory for imagery where precise accuracy is not as important. In addition, the QGIS tool exports the rendered map, not just the raster, allowing for the creation of tiled custom basemaps.
- gdal2tiles
- QGIS Generate XYZ Tiles (directory & mbtiles)
|
Resources
https://alastaira.wordpress.com/2011/07/11/maptiler-gdal2tiles-and-raster-resampling/
https://gitlab.com/GitLabRGI/geopackage-python/blob/master/Packaging/tiles2gpkg_parallel.py
https://gitlab.com/GitLabRGI/geopackage-python/blob/master/Tiling/gdal2tiles_parallel.py