Skip to content

Commit

Permalink
Merge c2eb5b2 into 226ab3b
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillies committed Sep 18, 2018
2 parents 226ab3b + c2eb5b2 commit 4b13d5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions rasterio/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,10 @@ def geometry_window(dataset, shapes, pad_x=0, pad_y=0, north_up=True,
right, bottom = (right, bottom) * dataset.transform

window = dataset.window(left, bottom, right, top)
window = window.round_offsets(op='floor', pixel_precision=pixel_precision)
window = window.round_shape(op='ceil', pixel_precision=pixel_precision)
window_floored = window.round_offsets(op='floor', pixel_precision=pixel_precision)
w = math.ceil(window.width + window.col_off - window_floored.col_off)
h = math.ceil(window.height + window.row_off - window_floored.row_off)
window = Window(window_floored.col_off, window_floored.row_off, w, h)

# Make sure that window overlaps raster
raster_window = Window(0, 0, dataset.width, dataset.height)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_geometry_window_pixel_precision(basic_image_file):
with rasterio.open(basic_image_file) as src:
window = geometry_window(src, [geom2], north_up=False,
pixel_precision=6)
assert window.flatten() == (1, 2, 3, 3)
assert window.flatten() == (1, 2, 4, 3)


def test_geometry_window_north_up(path_rgb_byte_tif):
Expand All @@ -190,7 +190,7 @@ def test_geometry_window_north_up(path_rgb_byte_tif):
with rasterio.open(path_rgb_byte_tif) as src:
window = geometry_window(src, [geometry], north_up=True)

assert window.flatten() == (326, 256, 167, 167)
assert window.flatten() == (326, 256, 168, 167)


def test_geometry_window_pad(basic_image_file, basic_geometry):
Expand Down

0 comments on commit 4b13d5d

Please sign in to comment.