From 2d4962c19de655e852960c63a5446b789416969b Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Fri, 10 Aug 2018 09:54:50 -0600 Subject: [PATCH] use the rasterio dataset's .transform property; require Rasterio 1.0 --- docs/manual.rst | 2 +- requirements.txt | 2 +- tests/test_io.py | 12 ++++++------ tests/test_point.py | 7 ++++++- tests/test_zonal.py | 9 ++++----- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index fd26cc0..15225a4 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -105,7 +105,7 @@ to a coordinate reference system:: >>> import rasterio >>> with rasterio.open('tests/data/slope.tif') as src: - ... affine = src.affine + ... affine = src.transform ... array = src.read(1) >>> zs = zonal_stats('tests/data/polygons.shp', array, affine=affine) diff --git a/requirements.txt b/requirements.txt index ad82f14..ce7f132 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ shapely numpy>=1.9 -rasterio>=0.27 +rasterio>=1.0 cligj>=0.4 fiona simplejson diff --git a/tests/test_io.py b/tests/test_io.py index b624133..8d1ec78 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -224,15 +224,15 @@ def test_boundless_masked(): def test_window_bounds(): with rasterio.open(raster) as src: win = ((0, src.shape[0]), (0, src.shape[1])) - assert src.bounds == window_bounds(win, src.affine) + assert src.bounds == window_bounds(win, src.transform) win = ((5, 10), (5, 10)) - assert src.window_bounds(win) == window_bounds(win, src.affine) + assert src.window_bounds(win) == window_bounds(win, src.transform) def test_bounds_window(): with rasterio.open(raster) as src: - assert bounds_window(src.bounds, src.affine) == \ + assert bounds_window(src.bounds, src.transform) == \ ((0, src.shape[0]), (0, src.shape[1])) @@ -242,8 +242,8 @@ def test_rowcol(): x, _, _, y = src.bounds x += 1.0 y -= 1.0 - assert rowcol(x, y, src.affine, op=math.floor) == (0, 0) - assert rowcol(x, y, src.affine, op=math.ceil) == (1, 1) + assert rowcol(x, y, src.transform, op=math.floor) == (0, 0) + assert rowcol(x, y, src.transform, op=math.ceil) == (1, 1) def test_Raster_index(): x, y = 245114, 1000968 @@ -263,7 +263,7 @@ def test_Raster(): with rasterio.open(raster) as src: arr = src.read(1) - affine = src.affine + affine = src.transform nodata = src.nodata r2 = Raster(arr, affine, nodata, band=1).read(bounds) diff --git a/tests/test_point.py b/tests/test_point.py index de75fbb..0ea48ab 100644 --- a/tests/test_point.py +++ b/tests/test_point.py @@ -7,7 +7,8 @@ raster_nodata = os.path.join(os.path.dirname(__file__), 'data/slope_nodata.tif') with rasterio.open(raster) as src: - affine = src.affine + affine = src.transform + def test_unitxy_ul(): win, unitxy = point_window_unitxy(245300, 1000073, affine) @@ -17,6 +18,7 @@ def test_unitxy_ul(): assert x > 0.5 assert y < 0.5 + def test_unitxy_ur(): win, unitxy = point_window_unitxy(245318, 1000073, affine) assert win == ((30, 32), (39, 41)) @@ -32,6 +34,7 @@ def test_unitxy_ur(): assert x < 0.5 assert y < 0.5 + def test_unitxy_lr(): win, unitxy = point_window_unitxy(245318, 1000056, affine) assert win == ((31, 33), (39, 41)) @@ -40,6 +43,7 @@ def test_unitxy_lr(): assert x < 0.5 assert y > 0.5 + def test_unitxy_ll(): win, unitxy = point_window_unitxy(245300, 1000056, affine) assert win == ((31, 33), (38, 40)) @@ -48,6 +52,7 @@ def test_unitxy_ll(): assert x > 0.5 assert y > 0.5 + def test_bilinear(): import numpy as np arr = np.array([[1.0, 2.0], diff --git a/tests/test_zonal.py b/tests/test_zonal.py index 48babc9..b5c3014 100644 --- a/tests/test_zonal.py +++ b/tests/test_zonal.py @@ -250,7 +250,7 @@ def _assert_dict_eq(a, b): def test_ndarray(): with rasterio.open(raster) as src: arr = src.read(1) - affine = src.affine + affine = src.transform polygons = os.path.join(DATA, 'polygons.shp') stats = zonal_stats(polygons, arr, affine=affine) @@ -412,7 +412,7 @@ def test_some_nodata_ndarray(): raster = os.path.join(DATA, 'slope_nodata.tif') with rasterio.open(raster) as src: arr = src.read(1) - affine = src.affine + affine = src.transform # without nodata stats = zonal_stats(polygons, arr, affine=affine, stats=['nodata', 'count', 'min']) @@ -431,7 +431,7 @@ def test_some_nodata_ndarray(): def test_transform(): with rasterio.open(raster) as src: arr = src.read(1) - affine = src.affine + affine = src.transform polygons = os.path.join(DATA, 'polygons.shp') stats = zonal_stats(polygons, arr, affine=affine) @@ -458,7 +458,6 @@ def test_geojson_out(): assert 'count' in feature['properties'] # from zonal stats - # do not think this is actually testing the line i wanted it to # since the read_features func for this data type is generating # the properties field @@ -488,7 +487,7 @@ def test_copy_properties_warn(): with pytest.deprecated_call(): stats_b = zonal_stats(polygons, raster, copy_properties=True) assert stats_a == stats_b - + def test_nan_counts(): from affine import Affine