Skip to content

Commit

Permalink
Merge branch 'main' into iterable_mosaic_reader
Browse files Browse the repository at this point in the history
  • Loading branch information
bitner authored Nov 15, 2023
2 parents 090f2f0 + dc7e87d commit 4a61a83
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 6.2.4
current_version = 6.2.6
commit = True
tag = True
tag_name = {new_version}
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

# 6.2.6 (2023-11-10)

* validate `shape` in `ImageData.get_coverage_array` to avoid rasterio error when re-projecting the geometry

# 6.2.5 (2023-11-06)

* avoid `indexes` collision in `MultiBaseReader`

# 6.2.4 (2023-10-19)

* fix issue with `WarpedVRT` when doing re-projection (ref: https://github.com/cogeotiff/rio-tiler/pull/648)
Expand Down
2 changes: 1 addition & 1 deletion rio_tiler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""rio-tiler."""

__version__ = "6.2.4"
__version__ = "6.2.6"

from . import ( # noqa
colormap,
Expand Down
25 changes: 20 additions & 5 deletions rio_tiler/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,11 @@ def tile(

asset_indexes = asset_indexes or {}

# We fall back to `indexes` if provided
indexes = kwargs.pop("indexes", None)

def _reader(asset: str, *args: Any, **kwargs: Any) -> ImageData:
idx = asset_indexes.get(asset) or kwargs.pop("indexes", None) # type: ignore
idx = asset_indexes.get(asset) or indexes # type: ignore

asset_info = self._get_asset_info(asset)
url = asset_info["url"]
Expand Down Expand Up @@ -567,8 +570,11 @@ def part(

asset_indexes = asset_indexes or {}

# We fall back to `indexes` if provided
indexes = kwargs.pop("indexes", None)

def _reader(asset: str, *args: Any, **kwargs: Any) -> ImageData:
idx = asset_indexes.get(asset) or kwargs.pop("indexes", None) # type: ignore
idx = asset_indexes.get(asset) or indexes # type: ignore

asset_info = self._get_asset_info(asset)
url = asset_info["url"]
Expand Down Expand Up @@ -643,8 +649,11 @@ def preview(

asset_indexes = asset_indexes or {}

# We fall back to `indexes` if provided
indexes = kwargs.pop("indexes", None)

def _reader(asset: str, **kwargs: Any) -> ImageData:
idx = asset_indexes.get(asset) or kwargs.pop("indexes", None) # type: ignore
idx = asset_indexes.get(asset) or indexes # type: ignore

asset_info = self._get_asset_info(asset)
url = asset_info["url"]
Expand Down Expand Up @@ -723,8 +732,11 @@ def point(

asset_indexes = asset_indexes or {}

# We fall back to `indexes` if provided
indexes = kwargs.pop("indexes", None)

def _reader(asset: str, *args, **kwargs: Any) -> PointData:
idx = asset_indexes.get(asset) or kwargs.pop("indexes", None) # type: ignore
idx = asset_indexes.get(asset) or indexes # type: ignore

asset_info = self._get_asset_info(asset)
url = asset_info["url"]
Expand Down Expand Up @@ -795,8 +807,11 @@ def feature(

asset_indexes = asset_indexes or {}

# We fall back to `indexes` if provided
indexes = kwargs.pop("indexes", None)

def _reader(asset: str, *args: Any, **kwargs: Any) -> ImageData:
idx = asset_indexes.get(asset) or kwargs.pop("indexes", None) # type: ignore
idx = asset_indexes.get(asset) or indexes # type: ignore

asset_info = self._get_asset_info(asset)
url = asset_info["url"]
Expand Down
4 changes: 3 additions & 1 deletion rio_tiler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
RIOResampling,
)
from rio_tiler.utils import (
_validate_shape_input,
get_array_statistics,
linear_rescale,
non_alpha_indexes,
Expand Down Expand Up @@ -822,10 +823,11 @@ def get_coverage_array(
Note: code adapted from https://github.com/perrygeo/python-rasterstats/pull/136 by @sgoodm
"""
shape = _validate_shape_input(shape)

if self.crs != shape_crs:
shape = transform_geom(shape_crs, self.crs, shape)

shape = shape.get("geometry", shape)
cover_array = rasterize(
[(shape, 1)],
out_shape=(self.height * cover_scale, self.width * cover_scale),
Expand Down
16 changes: 16 additions & 0 deletions tests/test_io_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ def test_tile_valid(rio):
assert img.mask.shape == (256, 256)
assert img.band_names == ["green_b1", "green_b1", "red_b1", "red_b1"]

# check that indexes and asset_indexes are not conflicting
img = stac.tile(
71,
102,
8,
assets=("green", "red"),
indexes=None,
asset_indexes={
"green": (1,),
"red": 1,
},
)
assert img.data.shape == (2, 256, 256)
assert img.mask.shape == (256, 256)
assert img.band_names == ["green_b1", "red_b1"]

img = stac.tile(71, 102, 8, expression="green_b1*2;green_b1;red_b1*2")
assert img.data.shape == (3, 256, 256)
assert img.mask.shape == (256, 256)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,24 @@ def test_imagedata_coverage():

coverage = im.get_coverage_array({"type": "Feature", "geometry": poly})
assert numpy.unique(coverage).tolist() == [0.25]

poly = {
"type": "Polygon",
"coordinates": [
[
(-10018754.171394622, -5621521.486192066),
(10018754.171394622, -5621521.486192066),
(10018754.171394622, 5621521.486192066),
(-10018754.171394622, 5621521.486192066),
(-10018754.171394622, -5621521.486192066),
]
],
}

coverage = im.get_coverage_array(poly, shape_crs="epsg:3857")
assert numpy.unique(coverage).tolist() == [0.25]

coverage = im.get_coverage_array(
{"type": "Feature", "geometry": poly}, shape_crs="epsg:3857"
)
assert numpy.unique(coverage).tolist() == [0.25]

0 comments on commit 4a61a83

Please sign in to comment.