From e11b3758702921e1cfac187e89460ff28eb40ce8 Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Thu, 2 Jun 2016 16:17:31 -0400 Subject: [PATCH] pass on invert proj 'errors' and xfail tests for bug #614 --- rasterio/_warp.pyx | 3 +-- tests/test_rio_warp.py | 1 - tests/test_warp.py | 51 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/rasterio/_warp.pyx b/rasterio/_warp.pyx index 937677f2..7dd3eea0 100644 --- a/rasterio/_warp.pyx +++ b/rasterio/_warp.pyx @@ -566,8 +566,7 @@ def _calculate_default_transform( raise CRSError(err.errmsg) except CPLE_AppDefined as err: log.debug("Encountered points outside of valid dst crs region") - raise - #pass + pass finally: if wkt != NULL: _gdal.CPLFree(wkt) diff --git a/tests/test_rio_warp.py b/tests/test_rio_warp.py index af3c6eba..50f89aa3 100644 --- a/tests/test_rio_warp.py +++ b/tests/test_rio_warp.py @@ -395,7 +395,6 @@ def test_warp_badcrs_src_bounds(runner, tmpdir): assert "Invalid value for dst_crs" in result.output -@pytest.mark.xfail def test_warp_reproject_check_invert(runner, tmpdir): srcname = 'tests/data/world.rgb.tif' outputname = str(tmpdir.join('test.tif')) diff --git a/tests/test_warp.py b/tests/test_warp.py index 05708af9..8a8a35ac 100644 --- a/tests/test_warp.py +++ b/tests/test_warp.py @@ -596,3 +596,54 @@ def test_reproject_unsupported_resampling_guass(): dst_transform=DST_TRANSFORM, dst_crs=dst_crs, resampling=Resampling.gauss) + + +@pytest.mark.xfail() +@pytest.mark.parametrize("method", Resampling) +def test_resample_no_invert_proj(method): + """Nearest and bilinear should produce valid results with + CHECK_WITH_INVERT_PROJ = False + """ + from rasterio.warp import calculate_default_transform + from rasterio._err import CPLE_AppDefined + + with Env(CHECK_WITH_INVERT_PROJ=False): + with rasterio.open('tests/data/world.rgb.tif') as src: + source = src.read(1) + profile = src.profile.copy() + + dst_crs = {'init': 'EPSG:32619'} + + # Calculate the ideal dimensions and transformation in the new crs + dst_affine, dst_width, dst_height = calculate_default_transform( + src.crs, dst_crs, src.width, src.height, *src.bounds) + + profile['height'] = dst_height + profile['width'] = dst_width + + out = np.empty(shape=(dst_height, dst_width), dtype=np.uint8) + + # nearest works fine + reproject( + source, + out, + src_transform=src.transform, + src_crs=src.crs, + dst_transform=dst_affine, + dst_crs=dst_crs, + resampling=Resampling.nearest) + + assert out.mean() > 0 + + # some other methods succeed but produce blank images + out = np.empty(src.shape, dtype=np.uint8) + reproject( + source, + out, + src_transform=src.transform, + src_crs=src.crs, + dst_transform=dst_affine, + dst_crs=dst_crs, + resampling=method) + + assert out.mean() > 0