命令行实现:
gdal_translate input.tif cog.tif \
-of COG \
-co TILING_SCHEME=GoogleMapsCompatible \
-co COMPRESS=JPEG \
-co QUALITY=100 \
-co BLOCKSIZE=256 \
-co BIGTIFF=YES \
-co NUM_THREADS=ALL_CPUS
python代码实现:
options = gdal.TranslateOptions(
# 压缩方式为JPEG、切片方式为谷歌地图
format="COG",
creationOptions=[
"COMPRESS=JPEG",
"TILING_SCHEME=GoogleMapsCompatible",
"QUALITY=100",
"BLOCKSIZE=256",
"BIGTIFF=YES",
"NUM_THREADS=ALL_CPUS"
]
)
# 转换为COG格式数据
gdal.Translate(cog_tif, input_tif, options=options)
注意: 压缩方式执行为JPEG时,input.tif
必须为8位图像