Geographic Information Systems Asked by Nikko on January 19, 2021
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
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.
Answered by Zoltan on January 19, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP