2

I want to port a gdal_translate into Python. It is about translating a GeoTIFF into a Cloud Optimized GeoTIFF (COG). I do not know how to insert the option -of and its input.

Here's is the equivalent CLI for that:

gdal_translate input.tif output_cog.tif -of COG -co COMPRESS=LZW

My current Python Code:

from osgeo import gdal

ds = gdal.Open('input.tif') ds = gdal.Translate('output.tif', ds, options=["COMPRESS=LZW"])

How can I insert the input/argument -of COG into the Python code?

I got the code here: https://www.cogeo.org/developers-guide.html

Vince
  • 20,017
  • 15
  • 45
  • 64
Nikko
  • 581
  • 4
  • 16

1 Answers1

6

You can simply add all your parameters as a string (like in the command line version of gdal_translate):

from osgeo import gdal
ds = gdal.Translate('output.tif', 'input.tif', options="-of GTiff -co COMPRESS=LZW")

I used GTiff format because there is no COG driver in my gdal 3.0.4 version. I used the name of the input instead loading into ds and overwriting with the output of gdal.Translate.

Zoltan
  • 7,325
  • 17
  • 27