Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow morecantile 4.0 #606

Merged
merged 3 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies = [
"httpx",
"numexpr",
"numpy",
"morecantile>=3.1,<4.0",
"morecantile>=3.1,<5.0",
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
"pydantic",
"pystac>=0.5.4",
"rasterio>=1.3.0",
Expand Down
12 changes: 7 additions & 5 deletions rio_tiler/io/rasterio.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ def __exit__(self, exc_type, exc_value, traceback):

def _dst_geom_in_tms_crs(self):
"""Return dataset info in TMS projection."""
if self.crs != self.tms.rasterio_crs:
tms_crs = self.tms.rasterio_crs
if self.crs != tms_crs:
dst_affine, w, h = calculate_default_transform(
self.crs,
self.tms.rasterio_crs,
tms_crs,
self.dataset.width,
self.dataset.height,
*self.dataset.bounds,
Expand All @@ -161,7 +162,7 @@ def get_minzoom(self) -> int:
if self._minzoom is None:
# We assume the TMS tilesize to be constant over all matrices
# ref: https://github.com/OSGeo/gdal/blob/dc38aa64d779ecc45e3cd15b1817b83216cf96b8/gdal/frmts/gtiff/cogdriver.cpp#L274
tilesize = self.tms.tileMatrix[0].tileWidth
tilesize = self.tms.matrix(self.tms.minzoom).tileWidth

try:
dst_affine, w, h = self._dst_geom_in_tms_crs()
Expand Down Expand Up @@ -349,11 +350,12 @@ def tile(
)

tile_bounds = self.tms.xy_bounds(Tile(x=tile_x, y=tile_y, z=tile_z))
dst_crs = self.tms.rasterio_crs

return self.part(
tile_bounds,
dst_crs=self.tms.rasterio_crs,
bounds_crs=None,
dst_crs=dst_crs,
bounds_crs=dst_crs,
height=tilesize,
width=tilesize,
max_size=None,
Expand Down
14 changes: 8 additions & 6 deletions rio_tiler/io/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ def __attrs_post_init__(self):

def _dst_geom_in_tms_crs(self):
"""Return dataset info in TMS projection."""
if self.crs != self.tms.rasterio_crs:
tms_crs = self.tms.rasterio_crs
if self.crs != tms_crs:
dst_affine, w, h = calculate_default_transform(
self.crs,
self.tms.rasterio_crs,
tms_crs,
self.input.rio.width,
self.input.rio.height,
*self.bounds,
Expand All @@ -100,7 +101,7 @@ def get_minzoom(self) -> int:
if self._minzoom is None:
# We assume the TMS tilesize to be constant over all matrices
# ref: https://github.com/OSGeo/gdal/blob/dc38aa64d779ecc45e3cd15b1817b83216cf96b8/gdal/frmts/gtiff/cogdriver.cpp#L274
tilesize = self.tms.tileMatrix[0].tileWidth
tilesize = self.tms.matrix(self.tms.minzoom).tileWidth

try:
dst_affine, w, h = self._dst_geom_in_tms_crs()
Expand Down Expand Up @@ -217,11 +218,12 @@ def tile(
)

tile_bounds = self.tms.xy_bounds(Tile(x=tile_x, y=tile_y, z=tile_z))
dst_crs = self.tms.rasterio_crs

# Create source array by clipping the xarray dataset to extent of the tile.
ds = self.input.rio.clip_box(*tile_bounds, crs=self.tms.rasterio_crs)
ds = self.input.rio.clip_box(*tile_bounds, crs=dst_crs)
ds = ds.rio.reproject(
self.tms.rasterio_crs,
dst_crs,
shape=(tilesize, tilesize),
transform=from_bounds(*tile_bounds, height=tilesize, width=tilesize),
resampling=Resampling[resampling_method],
Expand All @@ -238,7 +240,7 @@ def tile(
return ImageData(
ds.data,
bounds=tile_bounds,
crs=self.tms.rasterio_crs,
crs=dst_crs,
dataset_statistics=stats,
band_names=band_names,
)
Expand Down