This is an automated email from the git hooks/post-receive script. sebastic pushed a commit to branch master in repository rasterio.
commit 5901f230e1fc3aaab6f8454f7d194239c77c06dd Author: Bas Couwenberg <[email protected]> Date: Fri Dec 25 14:54:45 2015 +0100 Imported Upstream version 0.31.0 --- .travis.yml | 1 - CHANGES.txt | 12 ++++++++++++ rasterio/__init__.py | 2 +- rasterio/_base.pyx | 12 ++++++++---- rasterio/_err.pyx | 10 ++++++++++ rasterio/_io.pyx | 14 +++++++++++--- requirements-dev.txt | 2 +- tests/test_read_boundless.py | 17 ++++++++++++++++ tests/test_transform.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 106 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7301728..4d96006 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ env: - PIP_FIND_LINKS=file://$HOME/.cache/pip/wheels - GDALINST=$HOME/gdalinstall - GDALBUILD=$HOME/gdalbuild - - CYTHON_COVERAGE=1 matrix: - GDALVERSION = "1.9.2" - GDALVERSION = "1.11.2" diff --git a/CHANGES.txt b/CHANGES.txt index 1b691b5..19f4033 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,18 @@ Changes ======= +0.31.0 (2015-12-18) +------------------- +- Warn when rasters have no georeferencing and when the default identity + transform will be applied by GDAL (#524, #527). +- Build OS X wheels using numpy>=1.10.2 (#529). +- When reading image windows in previous versions, given a window with + ((row_start, row_stop), (col_start, col_stop)) if the stop index is greater + than the width/height the start index effectively shifts as well. This can + manifest itself in pixel misalignment if, e.g. you read block windows with + a bit of padding to avoid edge effects. Now the window offsets are determined + solely by row_start and col_start.(#532, #533). + 0.30.0 (2015-11-16) ------------------- - Added window utilities: get_data_window(), window_union(), diff --git a/rasterio/__init__.py b/rasterio/__init__.py index 76ff733..142ce75 100644 --- a/rasterio/__init__.py +++ b/rasterio/__init__.py @@ -23,7 +23,7 @@ from rasterio import _err, coords, enums __all__ = [ 'band', 'open', 'drivers', 'copy', 'pad'] -__version__ = "0.30.0" +__version__ = "0.31.0" log = logging.getLogger('rasterio') class NullHandler(logging.Handler): diff --git a/rasterio/_base.pyx b/rasterio/_base.pyx index b4e2fb9..ea59ac0 100644 --- a/rasterio/_base.pyx +++ b/rasterio/_base.pyx @@ -14,7 +14,7 @@ from libc.stdlib cimport malloc, free from rasterio cimport _gdal, _ogr from rasterio._drivers import driver_count, GDALEnv -from rasterio._err import cpl_errs +from rasterio._err import cpl_errs, GDALError from rasterio import dtypes from rasterio.coords import BoundingBox from rasterio.transform import Affine @@ -204,9 +204,13 @@ cdef class DatasetReader(object): raise ValueError("Null dataset") cdef double gt[6] err = _gdal.GDALGetGeoTransform(self._hds, gt) - if err: - warnings.warn("GDALGetGeoTransform failed, default invalid " - "transform will be returned.") + + if err == GDALError.failure: + warnings.warn( + "Dataset has no geotransform set. Default transform " + "will be applied (Affine.identity())", + UserWarning + ) transform = [0]*6 for i in range(6): diff --git a/rasterio/_err.pyx b/rasterio/_err.pyx index b59ce44..bae5c16 100644 --- a/rasterio/_err.pyx +++ b/rasterio/_err.pyx @@ -29,6 +29,9 @@ manager raises a more useful and informative error: ValueError: The PNG driver does not support update access to existing datasets. """ +from enums import IntEnum + + # CPL function declarations. cdef extern from "cpl_error.h": int CPLGetLastErrorNo() @@ -68,3 +71,10 @@ cdef class GDALErrCtxManager: cpl_errs = GDALErrCtxManager() + +class GDALError(IntEnum): + none = 0, # CE_None + debug = 1, # CE_Debug + warning= 2, # CE_Warning + failure = 3, # CE_Failure + fatal = 4 # CE_Fatal diff --git a/rasterio/_io.pyx b/rasterio/_io.pyx index 070d0fd..9b003d6 100644 --- a/rasterio/_io.pyx +++ b/rasterio/_io.pyx @@ -17,7 +17,7 @@ from rasterio cimport _base, _gdal, _ogr, _io from rasterio._base import ( crop_window, eval_window, window_shape, window_index, tastes_like_gdal) from rasterio._drivers import driver_count, GDALEnv -from rasterio._err import cpl_errs +from rasterio._err import cpl_errs, GDALError from rasterio import dtypes from rasterio.coords import BoundingBox from rasterio.five import text_type, string_types @@ -865,9 +865,9 @@ cdef class RasterReader(_base.DatasetReader): roff = 0 coff = 0 if window[0][0] < 0: - roff = int(round(window_h*scaling_h)) - data_h + roff = -window[0][0] * scaling_h if window[1][0] < 0: - coff = int(round(window_w*scaling_w)) - data_w + coff = -window[1][0] * scaling_w for dst, src in zip( out if len(out.shape) == 3 else [out], @@ -1450,6 +1450,14 @@ cdef class RasterUpdater(RasterReader): def write_transform(self, transform): if self._hds == NULL: raise ValueError("Can't read closed raster file") + + if [abs(v) for v in transform] == [0, 1, 0, 0, 0, 1]: + warnings.warn( + "Dataset uses default geotransform (Affine.identity). " + "No tranform will be written to the output by GDAL.", + UserWarning + ) + cdef double gt[6] for i in range(6): gt[i] = transform[i] diff --git a/requirements-dev.txt b/requirements-dev.txt index 16048fe..925b579 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ cligj cython>=0.23.4 delocate enum34 -numpy>=1.8 +numpy>=1.10 snuggs>=1.2 pytest>=2.8.2 pytest-cov>=2.2.0 diff --git a/tests/test_read_boundless.py b/tests/test_read_boundless.py index 117479f..26e2ed0 100644 --- a/tests/test_read_boundless.py +++ b/tests/test_read_boundless.py @@ -84,3 +84,20 @@ def test_read_boundless_masks_zero_stop(): data = src.read_masks(window=((-200, 0), (-200, 0)), boundless=True) assert data.shape == (3, 200, 200) assert data.min() == data.max() == src.nodata + +def test_read_boundless_noshift(): + with rasterio.open('tests/data/rgb4.tif') as src: + # the read offsets should be determined by start col/row alone + # when col stop exceeds image width + c1 = src.read(boundless=True, + window=((100, 101), (-1, src.shape[1])))[0, 0, 0:9] + c2 = src.read(boundless=True, + window=((100, 101), (-1, src.shape[1] + 1)))[0, 0, 0:9] + assert numpy.array_equal(c1, c2) + + # when row stop exceeds image height + r1 = src.read(boundless=True, + window=((-1, src.shape[0]), (100, 101)))[0, 0, 0:9] + r2 = src.read(boundless=True, + window=((-1, src.shape[0] + 1), (100, 101)))[0, 0, 0:9] + assert numpy.array_equal(r1, r2) diff --git a/tests/test_transform.py b/tests/test_transform.py index cf0607e..23a8efe 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -1,3 +1,5 @@ +from affine import Affine +import pytest import rasterio from rasterio import transform @@ -74,3 +76,47 @@ def test_window_bounds(): for e, a in zip(expected, actual): assert round(e, 7) == round(a, 7) + + +def test_affine_roundtrip(tmpdir): + output = str(tmpdir.join('test.tif')) + out_affine = Affine(2, 0, 0, 0, -2, 0) + + with rasterio.open( + output, 'w', + driver='GTiff', + count=1, + dtype=rasterio.uint8, + width=1, + height=1, + transform=out_affine + ) as out: + assert out.affine == out_affine + + with rasterio.open(output) as out: + assert out.affine == out_affine + + +def test_affine_identity(tmpdir): + """ + Setting a transform with absolute values equivalent to Affine.identity() + should result in a warning (not captured here) and read with + affine that matches Affine.identity(). + """ + + output = str(tmpdir.join('test.tif')) + out_affine = Affine(1, 0, 0, 0, -1, 0) + + with rasterio.open( + output, 'w', + driver='GTiff', + count=1, + dtype=rasterio.uint8, + width=1, + height=1, + transform=out_affine + ) as out: + assert out.affine == out_affine + + with rasterio.open(output) as out: + assert out.affine == Affine.identity() -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/rasterio.git _______________________________________________ Pkg-grass-devel mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

