mirror of
https://github.com/rasterio/rasterio.git
synced 2026-02-01 14:34:43 +00:00
Added support for NaN in warp.
This commit is contained in:
parent
fa633280a9
commit
61a49ee5ef
@ -54,7 +54,11 @@ cdef bint in_dtype_range(value, dtype):
|
||||
105: np.iinfo,
|
||||
117: np.iinfo
|
||||
}
|
||||
rng = infos[np.dtype(dtype).kind](dtype)
|
||||
key = np.dtype(dtype).kind
|
||||
if np.isnan(value):
|
||||
return key in ('c', 'f', 99, 102)
|
||||
|
||||
rng = infos[key](dtype)
|
||||
return rng.min <= value <= rng.max
|
||||
|
||||
# Single band IO functions.
|
||||
|
||||
@ -276,6 +276,33 @@ def test_reproject_nodata():
|
||||
params.dst_height - 4461)
|
||||
|
||||
|
||||
def test_reproject_nodata_nan():
|
||||
params = default_reproject_params()
|
||||
nodata = 215
|
||||
|
||||
with rasterio.drivers():
|
||||
source = numpy.ones((params.width, params.height), dtype=numpy.float32)
|
||||
out = numpy.zeros((params.dst_width, params.dst_height),
|
||||
dtype=source.dtype)
|
||||
out.fill(120) # Fill with arbitrary value
|
||||
|
||||
reproject(
|
||||
source,
|
||||
out,
|
||||
src_transform=params.src_transform,
|
||||
src_crs=params.src_crs,
|
||||
src_nodata=numpy.nan,
|
||||
dst_transform=params.dst_transform,
|
||||
dst_crs=params.dst_crs,
|
||||
dst_nodata=numpy.nan
|
||||
)
|
||||
|
||||
assert (out == 1).sum() == 4461
|
||||
assert numpy.isnan(out).sum() == (params.dst_width *
|
||||
params.dst_height - 4461)
|
||||
|
||||
|
||||
|
||||
def test_reproject_dst_nodata_default():
|
||||
"""
|
||||
If nodata is not provided, destination will be filled with 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user