forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcog.py
40 lines (29 loc) · 866 Bytes
/
cog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# SPDX-License-Identifier: MIT
# Copyright 2020 Even Rouault
import time
from osgeo import gdal
srcfilename = "/vsimem/test.tif"
ds = gdal.GetDriverByName("GTiff").Create(
srcfilename, 20000, 20000, 3, options=["COMPRESS=" + "ZSTD", "TILED=YES"]
)
ds.GetRasterBand(1).Fill(50)
ds.GetRasterBand(3).Fill(100)
ds.GetRasterBand(3).Fill(200)
ds = None
def doit(compress, threads):
gdal.SetConfigOption("GDAL_NUM_THREADS", str(threads))
start = time.time()
gdal.Translate(
"/vsimem/out.tif", srcfilename, options="-of COG -co COMPRESS=" + compress
)
end = time.time()
print("COMPRESS=%s, NUM_THREADS=%d: %.2f" % (compress, threads, end - start))
gdal.SetConfigOption("GDAL_NUM_THREADS", None)
doit("ZSTD", 0)
doit("ZSTD", 2)
doit("ZSTD", 4)
doit("ZSTD", 8)
doit("WEBP", 0)
doit("WEBP", 2)
doit("WEBP", 4)
doit("WEBP", 8)