Skip to content

Commit

Permalink
Transform shape (#146)
Browse files Browse the repository at this point in the history
* use rasterio function to determine Affine & properly set width and height of target window

* updated changelog
  • Loading branch information
ungarj committed Dec 12, 2018
1 parent 05bc90b commit 388d7c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changelog
* fixed antimeridian shift check
* added retry decorator to read functions & added get_gdal_options() and read_raster_no_crs() functions
* pass on ``antimeridian_cutting`` from ``reproject_geometry()`` to underlying Fiona function
* fix transform shape on non-square tiles (#145)

----
0.26
Expand Down
16 changes: 8 additions & 8 deletions mapchete/io/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from rasterio.enums import Resampling
from rasterio.errors import RasterioIOError
from rasterio.io import MemoryFile
from rasterio.transform import from_bounds as affine_from_bounds
from rasterio.vrt import WarpedVRT
from rasterio.warp import reproject
from rasterio.windows import from_bounds
Expand Down Expand Up @@ -251,23 +252,22 @@ def _rasterio_read(
dst_nodata=None,
):
with rasterio.open(input_file, "r") as src:
height, width = dst_shape[-2:]
if indexes is None:
dst_shape = (len(src.indexes), dst_shape[-2], dst_shape[-1], )
dst_shape = (len(src.indexes), height, width)
indexes = list(src.indexes)
src_nodata = src.nodata if src_nodata is None else src_nodata
dst_nodata = src.nodata if dst_nodata is None else dst_nodata
dst_left, dst_bottom, dst_right, dst_top = dst_bounds
with WarpedVRT(
src,
crs=dst_crs,
src_nodata=src_nodata,
nodata=dst_nodata,
width=dst_shape[-2],
height=dst_shape[-1],
transform=Affine(
(dst_bounds[2] - dst_bounds[0]) / dst_shape[-2],
0, dst_bounds[0], 0,
(dst_bounds[1] - dst_bounds[3]) / dst_shape[-1],
dst_bounds[3]
width=width,
height=height,
transform=affine_from_bounds(
dst_left, dst_bottom, dst_right, dst_top, width, height
),
resampling=Resampling[resampling]
) as vrt:
Expand Down

0 comments on commit 388d7c2

Please sign in to comment.