Skip to content

Commit

Permalink
Merge pull request #289 from lagamura/fix-issue-288
Browse files Browse the repository at this point in the history
fix #288 overviews should be NONE when overview_level=0
  • Loading branch information
vincentsarago authored Aug 28, 2024
2 parents 426615e + 1473f28 commit 54e2da9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 14 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- '*'
pull_request:
env:
LATEST_PY_VERSION: '3.10'
LATEST_PY_VERSION: '3.12'

jobs:
tests:
Expand All @@ -21,11 +21,12 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -59,9 +60,9 @@ jobs:
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.LATEST_PY_VERSION }}

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Documentation = "https://cogeotiff.github.io/rio-cogeo/"
cogeo = "rio_cogeo.scripts.cli:cogeo"

[build-system]
requires = ["flit>=3.2,<4"]
requires = ["flit_core>=3.2,<4"]
build-backend = "flit_core.buildapi"

[tool.flit.module]
Expand Down
15 changes: 8 additions & 7 deletions rio_cogeo/cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ def cog_translate( # noqa: C901
tags.update(
{
"TILING_SCHEME_NAME": tms.id or "CUSTOM",
"TILING_SCHEME_ZOOM_LEVEL": zoom_level
if zoom_level is not None
else default_zoom,
"TILING_SCHEME_ZOOM_LEVEL": (
zoom_level if zoom_level is not None else default_zoom
),
}
)
if aligned_levels:
Expand Down Expand Up @@ -445,7 +445,8 @@ def cog_translate( # noqa: C901
warnings.warn(
"With GDAL COG driver, mask band will be translated to an alpha band."
)

if overview_level == 0:
dst_kwargs["overviews"] = "NONE"
dst_kwargs["overview_resampling"] = overview_resampling
dst_kwargs["warp_resampling"] = resampling
dst_kwargs["blocksize"] = tilesize
Expand Down Expand Up @@ -772,9 +773,9 @@ def cog_info(
Height=src_dst.height,
Tiled=(src_dst.block_shapes[0][1] != src_dst.width),
Dtype=src_dst.dtypes[0],
Interleave=src_dst.interleaving.value
if src_dst.interleaving
else "UNKNOWN",
Interleave=(
src_dst.interleaving.value if src_dst.interleaving else "UNKNOWN"
),
AlphaBand=utils.has_alpha_band(src_dst),
InternalMask=utils.has_mask_band(src_dst),
Nodata=src_dst.nodata,
Expand Down
18 changes: 17 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""``pytest`` configuration."""

import os

import pytest
import rasterio
Expand All @@ -11,8 +12,23 @@
# Define helpers to skip tests based on GDAL version
gdal_version = GDALVersion.runtime()

webp_tiff_path_rgb = os.path.join(
os.path.dirname(__file__), "fixtures", "image_webp.tif"
)

has_webp = False
try:
with rasterio.open(webp_tiff_path_rgb) as src:
pass

has_webp = True

except rasterio.RasterioIOError:
has_webp = False


requires_webp = pytest.mark.skipif(
"WEBP" not in drivers.keys(), reason="Only relevant if WEBP drivers is supported"
has_webp is False, reason="Only relevant if WEBP drivers is supported"
)

requires_gdal31 = pytest.mark.skipif(
Expand Down
Binary file modified tests/fixtures/image_colormap.tif
Binary file not shown.
Binary file modified tests/fixtures/image_nocolormap.tif
Binary file not shown.
Binary file added tests/fixtures/image_webp.tif
Binary file not shown.
31 changes: 31 additions & 0 deletions tests/test_cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,37 @@ def test_gdal_cog_web_mask(runner):
assert cog_validate("cogeo.tif")


@requires_gdal31
def test_gdal_cog_overview(runner):
"""Test GDAL COG."""
with runner.isolated_filesystem():
profile = cog_profiles.get("jpeg")
profile["blockxsize"] = 256
profile["blockysize"] = 256

cog_translate(
raster_path_rgba,
"gdalcogeo.tif",
profile.copy(),
quiet=True,
use_cog_driver=True,
overview_level=0,
)
with rasterio.open("gdalcogeo.tif") as src:
assert src.overviews(1) == []

cog_translate(
raster_path_rgba,
"gdalcogeo.tif",
profile.copy(),
quiet=True,
use_cog_driver=True,
overview_level=None,
)
with rasterio.open("gdalcogeo.tif") as src:
assert src.overviews(1) == [2]


def test_info_with_metadata():
"""Make sure info returns band metadata."""
info = cog_info(raster_band_tags)
Expand Down

0 comments on commit 54e2da9

Please sign in to comment.