Convert GeoTIFF to COG

This post will cover converting a GeoTIFF to Cloud Optimized GeoTIFF (COG)

For our example, let’s use the GeoTIFF file FAA_UTM18N_NAD83.tif from the U.S. Geological Survey.

You can download the file from: https://www.sciencebase.gov/catalog/item/53f5a87ae4b09d12e0e8547b

We can convert our GeoTIFF to COG using GDAL.

Place the file on your server and issue below:

gdal_translate FAA_UTM18N_NAD83.tif FAA_COG.tif -of COG -co BLOCKSIZE=256 -co BIGTIFF=IF_SAFER -co COMPRESS=LZW -co PREDICTOR=YES

Our output should look something like below:

Input file size is 1491, 1387
0...10...20...30...40...50...60...70...80...90...100 - done.

Let’s take a look at the GDAL command we used. You can adjust these, of course, for your own files.

  • FAA_UTM18N_NAD83.tif is our input file
  • FAA_COG.tif is our output file
  • ‘-of COG’ our output file type is COG
  • Our Creation Options, ‘-co’ are:
    • BLOCKSIZE=256 – default is 512.
    • BIGTIFF=IF_SAFER – this will create a BIGTIFF is the output file exceeds 4 GB
    • COMPRESS=LZW – this is our compression type (default)
    • PREDICTOR=YES – set to use to create BIGTIFF if required

If we wish to, we can now validate the COG we have created using COG Validator (https://github.com/rouault/cog_validator)

It’s a good idea to validate your COG as GeoServer can be very picky about COGs.

wget https://raw.githubusercontent.com/rouault/cog_validator/refs/heads/master/validate_cloud_optimized_geotiff.py

Our output should look like below:

FAA_COG.tif is a valid cloud optimized GeoTIFF

The size of all IFD headers is 1532 bytes

You can find the full GDAL COG reference at: https://gdal.org/en/latest/drivers/raster/cog.html