mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
Incorporating @brendan-ward's suggestions.
This commit is contained in:
parent
2b4f7284ba
commit
12261402fb
@ -377,9 +377,6 @@ cdef class DatasetReader(object):
|
||||
"""Returns the window corresponding to the world bounding box."""
|
||||
ul = self.index(left, top)
|
||||
lr = self.index(right, bottom)
|
||||
#if ul[0] < 0 or ul[1] < 0 or lr[0] > self.height or lr[1] > self.width:
|
||||
# raise ValueError("Bounding box overflows the dataset extents")
|
||||
#else:
|
||||
return tuple(zip(ul, lr))
|
||||
|
||||
@property
|
||||
|
||||
@ -87,12 +87,14 @@ def merge(ctx, files, driver, bounds, res):
|
||||
kwargs['height'] = output_height
|
||||
|
||||
dst = rasterio.open(output, 'w', **kwargs)
|
||||
dest = np.zeros((first.count,) + (output_height, output_width),
|
||||
dest = np.zeros((first.count, output_height, output_width),
|
||||
dtype=first.dtypes[0])
|
||||
nodataval = first.nodatavals[0]
|
||||
|
||||
if nodataval is not None:
|
||||
dest.fill(nodataval)
|
||||
else:
|
||||
notdataval = 0
|
||||
|
||||
for fname in reversed(files):
|
||||
with rasterio.open(fname) as src:
|
||||
@ -108,13 +110,13 @@ def merge(ctx, files, driver, bounds, res):
|
||||
masked=True)
|
||||
np.copyto(dest, data,
|
||||
where=np.logical_and(
|
||||
dest==(nodataval or 0), data.mask==False))
|
||||
dest==nodataval, data.mask==False))
|
||||
|
||||
if dst.mode == 'r+':
|
||||
data = dst.read(masked=True)
|
||||
np.copyto(dest, data,
|
||||
where=np.logical_and(
|
||||
dest==(nodataval or 0), data.mask==False))
|
||||
dest==nodataval, data.mask==False))
|
||||
|
||||
dst.write(dest)
|
||||
dst.close()
|
||||
|
||||
@ -17,8 +17,5 @@ def test_window_no_exception():
|
||||
with rasterio.open('tests/data/RGB.byte.tif') as src:
|
||||
left, bottom, right, top = src.bounds
|
||||
left -= 1000.0
|
||||
try:
|
||||
_ = src.window(left, bottom, right, top)
|
||||
assert True
|
||||
except ValueError:
|
||||
assert False
|
||||
assert src.window(left, bottom, right, top) == (
|
||||
(0, src.height), (-3, src.width))
|
||||
|
||||
@ -13,7 +13,7 @@ def test_read_boundless_natural_extent():
|
||||
with rasterio.open('tests/data/RGB.byte.tif') as src:
|
||||
data = src.read(boundless=True)
|
||||
assert data.shape == (3, src.height, src.width)
|
||||
assert data[0].mean() == src.read(1).mean()
|
||||
assert abs(data[0].mean() - src.read(1).mean()) < 0.0001
|
||||
assert data.any()
|
||||
|
||||
def test_read_boundless_beyond():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user