Skip to content

Commit

Permalink
Return a 1x1 image when bbox is smaller than a single pixel (#637)
Browse files Browse the repository at this point in the history
* Return a 1x1 image when bbox is smaller than a single pixel

* update changelog

---------

Co-authored-by: vincentsarago <[email protected]>
  • Loading branch information
JackDunnNZ and vincentsarago authored Sep 13, 2023
1 parent 0668787 commit a272374
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

# 6.0.3 (2023-09-13)

* return a 1x1 image when bbox is smaller than a single pixel (author @JackDunnNZ, https://github.com/cogeotiff/rio-tiler/pull/637)

# 6.0.2 (2023-08-21)

* Update `data_as_image` to return masked values (author @JackDunnNZ, https://github.com/cogeotiff/rio-tiler/pull/635)
Expand Down
4 changes: 2 additions & 2 deletions rio_tiler/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ def part(
max_size, round(window.height), round(window.width)
)

height = height or round(window.height)
width = width or round(window.width)
height = height or max(1, round(window.height))
width = width or max(1, round(window.width))

if buffer:
bounds, height, width = _apply_buffer(buffer, bounds, height, width)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy
import pytest
import rasterio
from numpy.testing import assert_array_almost_equal
from rasterio.warp import transform_bounds

from rio_tiler import constants, reader
Expand Down Expand Up @@ -632,3 +633,11 @@ def test_part_no_VRT():
assert img_pad.bounds == bounds_dst_crs
# Padding should not have any influence when not doing any rescaling/reprojection
numpy.array_equal(img_pad.data, img.data)

# Read bbox smaller than one pixel
bounds_small = [bounds[0], bounds[1], bounds[0] + 1e-6, bounds[1] + 1e-6]
bounds_small_dst_crs = transform_bounds("epsg:4326", src_dst.crs, *bounds_small)
img_small = reader.part(src_dst, bounds_small, bounds_crs="epsg:4326")
assert img_small.height == 1
assert img_small.width == 1
assert_array_almost_equal(img_small.bounds, bounds_small_dst_crs)

0 comments on commit a272374

Please sign in to comment.