From 3c3ffc40a04a10c1711b77e0676cd878c94bb428 Mon Sep 17 00:00:00 2001 From: Alexis Manin Date: Thu, 25 Jan 2024 09:55:31 +0100 Subject: [PATCH] refactor(Cli): reduce impact of "web_optimized" parameter As the Python API deprecates it, it now only activates a default TMS. --- rio_cogeo/scripts/cli.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/rio_cogeo/scripts/cli.py b/rio_cogeo/scripts/cli.py index 2f91487..42819f6 100644 --- a/rio_cogeo/scripts/cli.py +++ b/rio_cogeo/scripts/cli.py @@ -5,6 +5,7 @@ import typing import click +import morecantile import numpy from morecantile import TileMatrixSet from rasterio.rio import options @@ -135,7 +136,10 @@ def cogeo(): show_default=True, ) @click.option( - "--web-optimized", "-w", is_flag=True, help="Create COGEO optimized for Web." + "--web-optimized", + "-w", + is_flag=True, + help="Create COGEO optimized for Web. Deprecated: use directly --tms", ) @click.option( "--zoom-level-strategy", @@ -258,24 +262,33 @@ def create( output_profile["blockxsize"] = blocksize output_profile["blockysize"] = blocksize - if web_optimized: - overview_blocksize = blocksize or 512 - config.update( { "GDAL_NUM_THREADS": threads, "GDAL_TIFF_INTERNAL_MASK": os.environ.get("GDAL_TIFF_INTERNAL_MASK", True), - "GDAL_TIFF_OVR_BLOCKSIZE": str(overview_blocksize), } ) + tilematrixset: TileMatrixSet | None if tms: with open(tms, "r") as f: tilematrixset = TileMatrixSet(**json.load(f)) - + elif web_optimized: + tilematrixset = morecantile.tms.get("WebMercatorQuad") else: tilematrixset = None + gdal_tif_ovr_blocksize: int | None + if overview_blocksize: + gdal_tif_ovr_blocksize = overview_blocksize + elif blocksize: + gdal_tif_ovr_blocksize = blocksize + elif output_profile.get("blockxsize", -1) == output_profile.get("blockysize", -2): + gdal_tif_ovr_blocksize = blocksize + + if gdal_tif_ovr_blocksize: + config.update({"GDAL_TIFF_OVR_BLOCKSIZE": gdal_tif_ovr_blocksize}) + cog_translate( input, output, @@ -286,7 +299,6 @@ def create( add_mask=add_mask, overview_level=overview_level, overview_resampling=overview_resampling, - web_optimized=web_optimized, zoom_level_strategy=zoom_level_strategy, zoom_level=zoom_level, aligned_levels=aligned_levels,