Skip to content

Commit

Permalink
Merge pull request #206 from richpsharp/bugfix/stitch-rasters-bad-off…
Browse files Browse the repository at this point in the history
…set-205

Bugfix/stitch rasters bad offset 205
  • Loading branch information
richpsharp authored Jul 2, 2021
2 parents 09b5847 + 9331a1c commit 444515e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 4 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Release History
===============

Unreleased Changes
2.3.0 (2021-06-21)
------------------
* Added a ``single_outlet_tuple`` parameter to ``routing.fill_pits`` that
forces a DEM to only have one outlet at any point on the raster. The
Expand All @@ -22,8 +22,10 @@ Unreleased Changes
* Expanded the error message raised by ``transform_bounding_box`` when the
bounding box cannot be transformed to provide more helpful details.
* Add support and testing for GDAL 3.3.0.
* Fixed exception occuring in ``stitch_rasters`` when base rasters were
larger than the target raster on the ``y`` axis.

2.2.0 (2020-05-14)
2.2.0 (2021-05-14)
------------------
* Adding explicit support for Python 3.9 and testing on Python 3.9.
* Fixed an issue in ``create_raster_from_vector_extents`` that would cause a
Expand Down
17 changes: 9 additions & 8 deletions src/pygeoprocessing/geoprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3863,32 +3863,34 @@ def _mult_op(base_array, base_nodata, scale, datatype):
_offset_vars = {}
overlap = True
for (target_to_base_off, off_val,
target_off_id, off_clip_id, win_size_id) in [
target_off_id, off_clip_id, win_size_id, raster_size) in [
(target_to_base_xoff, offset_dict['xoff'],
'target_xoff', 'xoff_clip', 'win_xsize'),
'target_xoff', 'xoff_clip', 'win_xsize',
target_raster_x_size),
(target_to_base_yoff, offset_dict['yoff'],
'target_yoff', 'yoff_clip', 'win_ysize')]:
'target_yoff', 'yoff_clip', 'win_ysize',
target_raster_y_size)]:
_offset_vars[target_off_id] = (target_to_base_off+off_val)
if _offset_vars[target_off_id] > target_raster_x_size:
if _offset_vars[target_off_id] >= raster_size:
overlap = False
break
# how far to move right to get in the target raster
_offset_vars[off_clip_id] = 0
if _offset_vars[target_off_id] < 0:
_offset_vars[off_clip_id] = -_offset_vars[target_off_id]
_offset_vars[win_size_id] = offset_dict[win_size_id]
if _offset_vars[off_clip_id] > _offset_vars[win_size_id]:
if _offset_vars[off_clip_id] >= _offset_vars[win_size_id]:
# its too far left for the whole window
overlap = False
break
# make the _offset_vars[win_size_id] smaller if it shifts
# off the target window
if (_offset_vars[off_clip_id] + _offset_vars[target_off_id] +
_offset_vars[win_size_id] > target_raster_x_size):
_offset_vars[win_size_id] >= raster_size):
_offset_vars[win_size_id] -= (
_offset_vars[off_clip_id] +
_offset_vars[target_off_id] +
_offset_vars[win_size_id] - target_raster_x_size)
_offset_vars[win_size_id] - raster_size)

if not overlap:
continue
Expand All @@ -3899,7 +3901,6 @@ def _mult_op(base_array, base_nodata, scale, datatype):
win_xsize=_offset_vars['win_xsize'],
win_ysize=_offset_vars['win_ysize'])
target_nodata_mask = numpy.isclose(target_array, target_nodata)

base_array = base_band.ReadAsArray(
xoff=offset_dict['xoff']+_offset_vars['xoff_clip'],
yoff=offset_dict['yoff']+_offset_vars['yoff_clip'],
Expand Down

0 comments on commit 444515e

Please sign in to comment.