[Git][debian-gis-team/rasterio][upstream] New upstream version 1.2.8
Bas Couwenberg (@sebastic)
gitlab at salsa.debian.org
Fri Sep 10 06:08:21 BST 2021
Bas Couwenberg pushed to branch upstream at Debian GIS Project / rasterio
Commits:
9a26cf3a by Bas Couwenberg at 2021-09-10T06:55:23+02:00
New upstream version 1.2.8
- - - - -
6 changed files:
- CHANGES.txt
- rasterio/__init__.py
- rasterio/_base.pyx
- rasterio/transform.py
- tests/test_transform.py
- tests/test_warp_transform.py
Changes:
=====================================
CHANGES.txt
=====================================
@@ -1,6 +1,13 @@
Changes
=======
+1.2.8 (2021-09-09)
+------------------
+
+- Correct for the sense of OCTTransform's return value (#2287).
+- Fix a regression in the rasterio.transform module's xy and rowcol functions
+ (#2283).
+
1.2.7 (2021-09-07)
------------------
=====================================
rasterio/__init__.py
=====================================
@@ -40,7 +40,7 @@ import rasterio.enums
import rasterio.path
__all__ = ['band', 'open', 'pad', 'Env']
-__version__ = "1.2.7"
+__version__ = "1.2.8"
__gdal_version__ = gdal_version()
# Rasterio attaches NullHandler to the 'rasterio' logger and its
=====================================
rasterio/_base.pyx
=====================================
@@ -1413,7 +1413,8 @@ def _transform(src_crs, dst_crs, xs, ys, zs):
try:
transform = OCTNewCoordinateTransformation(src, dst)
transform = exc_wrap_pointer(transform)
- exc_wrap_int(OCTTransform(transform, n, x, y, z))
+ # OCTTransform() returns TRUE/FALSE contrary to most GDAL API functions
+ exc_wrap_int(OCTTransform(transform, n, x, y, z) == 0)
res_xs = [0]*n
res_ys = [0]*n
=====================================
rasterio/transform.py
=====================================
@@ -168,12 +168,15 @@ def xy(transform, rows, cols, offset='center'):
adjusted_transform = transform * Affine.translation(coff, roff)
- if isinstance(rows, (int, float)) and isinstance(cols, (int, float)):
- return adjusted_transform * (cols, rows)
- elif isinstance(rows, Iterable) and isinstance(cols, Iterable):
- xs, ys = zip(*(adjusted_transform * (col, row) for col, row in zip(cols, rows)))
- return list(xs), list(ys)
- else:
+ try:
+ if hasattr(rows, "__iter__") and hasattr(cols, "__iter__"):
+ xs, ys = zip(
+ *(adjusted_transform * (col, row) for col, row in zip(cols, rows))
+ )
+ return list(xs), list(ys)
+ else:
+ return adjusted_transform * (cols, rows)
+ except TypeError:
raise TransformError("Invalid inputs")
@@ -220,13 +223,16 @@ def rowcol(transform, xs, ys, op=math.floor, precision=None):
invtransform = ~transform
- if isinstance(xs, (int, float)) and isinstance(ys, (int, float)):
- fcol, frow = invtransform * (xs + eps, ys + eps)
- return op(frow), op(fcol)
- elif isinstance(xs, Iterable) and isinstance(ys, Iterable):
- fcols, frows = zip(*(invtransform * (x + eps, y + eps) for x, y in zip(xs, ys)))
- return [op(row) for row in frows], [op(col) for col in fcols]
- else:
+ try:
+ if hasattr(xs, "__iter__") and hasattr(ys, "__iter__"):
+ fcols, frows = zip(
+ *(invtransform * (x + eps, y + eps) for x, y in zip(xs, ys))
+ )
+ return [op(row) for row in frows], [op(col) for col in fcols]
+ else:
+ fcol, frow = invtransform * (xs + eps, ys + eps)
+ return op(frow), op(fcol)
+ except TypeError:
raise TransformError("Invalid inputs")
=====================================
tests/test_transform.py
=====================================
@@ -1,5 +1,12 @@
+"""Tests of the transform module."""
+
+from array import array
+
from affine import Affine
import pytest
+
+import numpy
+
import rasterio
from rasterio import transform
from rasterio.env import GDALVersion
@@ -132,33 +139,55 @@ def test_from_bounds_two():
assert [round(v, 7) for v in tr] == [round(v, 7) for v in expected]
-def test_xy():
- # TODO: use pytest's parametrize to make separate tests.
- aff = Affine(300.0379266750948, 0.0, 101985.0,
- 0.0, -300.041782729805, 2826915.0)
- ul_x, ul_y = aff * (0, 0)
- xoff = aff.a
- yoff = aff.e
- assert xy(aff, 0, 0, offset='ur') == (ul_x + xoff, ul_y)
- assert xy(aff, 0, 0, offset='ll') == (ul_x, ul_y + yoff)
- expected = (ul_x + xoff, ul_y + yoff)
- assert xy(aff, 0, 0, offset='lr') == expected
- expected = (ul_x + xoff / 2, ul_y + yoff / 2)
- assert xy(aff, 0, 0, offset='center') == expected
- assert xy(aff, 0, 0, offset='lr') == \
- xy(aff, 0, 1, offset='ll') == \
- xy(aff, 1, 1, offset='ul') == \
- xy(aff, 1, 0, offset='ur')
-
- # Check list inputs.
- assert xy(aff, [0], [0], offset='ul') == ([ul_x], [ul_y])
+ at pytest.mark.parametrize("aff", [Affine.identity()])
+ at pytest.mark.parametrize(
+ "offset, exp_xy",
+ [
+ ("ur", (1.0, 0.0)),
+ ("lr", (1.0, 1.0)),
+ ("ll", (0.0, 1.0)),
+ ("ul", (0.0, 0.0)),
+ ("center", (0.5, 0.5)),
+ ],
+)
+def test_xy_offset(offset, exp_xy, aff):
+ """Check offset keyword arg."""
+ assert xy(aff, 0, 0, offset=offset) == exp_xy
def test_bogus_offset():
+ """Raise on invalid offset."""
with pytest.raises(TransformError):
xy(None, 1, 0, offset='bogus')
+ at pytest.mark.parametrize("aff", [Affine.identity()])
+ at pytest.mark.parametrize(
+ "rows, cols, exp_xy",
+ [
+ (0, 0, (0.5, 0.5)),
+ (0.0, 0.0, (0.5, 0.5)),
+ (numpy.int32(0), numpy.int32(0), (0.5, 0.5)),
+ (numpy.float32(0), numpy.float32(0), (0.5, 0.5)),
+ ([0], [0], ([0.5], [0.5])),
+ (array("d", [0.0]), array("d", [0.0]), ([0.5], [0.5])),
+ ([numpy.int32(0)], [numpy.int32(0)], ([0.5], [0.5])),
+ (numpy.array([0.0]), numpy.array([0.0]), ([0.5], [0.5])),
+ ],
+)
+def test_xy_input(rows, cols, exp_xy, aff):
+ """Handle single and iterable inputs of different numerical types."""
+ assert xy(aff, rows, cols) == exp_xy
+
+
+ at pytest.mark.parametrize("aff", [Affine.identity()])
+ at pytest.mark.parametrize("rows, cols", [(0, [0]), ("0", "0")])
+def test_invalid_xy_input(rows, cols, aff):
+ """Raise on invalid input."""
+ with pytest.raises(TransformError):
+ xy(aff, rows, cols)
+
+
def test_guard_transform_gdal_TypeError(path_rgb_byte_tif):
"""As part of the 1.0 migration, guard_transform() should raise a TypeError
if a GDAL geotransform is encountered"""
@@ -186,8 +215,21 @@ def test_rowcol():
assert rowcol(aff, left, bottom) == (src.height, 0)
assert rowcol(aff, 101985.0, 2826915.0) == (0, 0)
- # Check list inputs.
- assert rowcol(aff, [101985.0 + 400.0], [2826915.0]) == ([0], [1])
+
+ at pytest.mark.parametrize(
+ "xs, ys, exp_rowcol",
+ [
+ ([101985.0 + 400.0], [2826915.0], ([0], [1])),
+ (array("d", [101985.0 + 400.0]), array("d", [2826915.0]), ([0], [1])),
+ (numpy.array([101985.0 + 400.0]), numpy.array([2826915.0]), ([0], [1])),
+ ],
+)
+def test_rowcol_input(xs, ys, exp_rowcol):
+ """Handle single and iterable inputs of different numerical types."""
+ with rasterio.open("tests/data/RGB.byte.tif", "r") as src:
+ aff = src.transform
+
+ assert rowcol(aff, xs, ys) == exp_rowcol
def test_xy_rowcol_inverse():
@@ -199,6 +241,14 @@ def test_xy_rowcol_inverse():
assert rows_cols == rowcol(aff, *xy(aff, *rows_cols))
+ at pytest.mark.parametrize("aff", [Affine.identity()])
+ at pytest.mark.parametrize("xs, ys", [(0, [0]), ("0", "0")])
+def test_invalid_rowcol_input(xs, ys, aff):
+ """Raise on invalid input."""
+ with pytest.raises(TransformError):
+ rowcol(aff, xs, ys)
+
+
def test_from_gcps():
with rasterio.open("tests/data/white-gemini-iv.vrt", 'r') as src:
aff = transform.from_gcps(src.gcps[0])
=====================================
tests/test_warp_transform.py
=====================================
@@ -1,9 +1,12 @@
+"""Tests of the warp module's coordinate transformation features."""
+
import os
import logging
import pytest
import rasterio
+from rasterio._err import CPLE_BaseError
from rasterio._warp import _calculate_default_transform
from rasterio.control import GroundControlPoint
from rasterio.crs import CRS
@@ -13,6 +16,7 @@ from rasterio.warp import calculate_default_transform, transform_bounds
log = logging.getLogger(__name__)
+
def test_gcps_bounds_exclusivity():
"""gcps and bounds parameters are mutually exclusive"""
with pytest.raises(ValueError):
@@ -179,31 +183,61 @@ def test_transform_bounds_identity():
assert transform_bounds("+init=epsg:3857", "+init=epsg:3857", *bounds) == bounds
+def test_transform_bounds_densify_out_of_bounds():
+ with pytest.raises(ValueError):
+ transform_bounds(
+ "EPSG:4326",
+ "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 "
+ "+a=6370997 +b=6370997 +units=m +no_defs",
+ -120,
+ 40,
+ -80,
+ 64,
+ densify_pts=-1,
+ )
+
+
+def test_transform_bounds_densify_out_of_bounds__geographic_output():
+ with pytest.raises(ValueError):
+ transform_bounds(
+ "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 "
+ "+a=6370997 +b=6370997 +units=m +no_defs",
+ "EPSG:4326",
+ -120,
+ 40,
+ -80,
+ 64,
+ densify_pts=-1,
+ )
+
+
def test_issue1131():
"""Confirm that we don't run out of memory"""
transform, w, h = calculate_default_transform(CRS.from_epsg(4326), CRS.from_epsg(3857), 455880, 454450, 13.0460235139, 42.6925552354, 13.2511695428, 42.8970561511)
assert (w, h) == (381595, 518398)
+
def test_rpcs_calculate_transform():
with rasterio.open('tests/data/RGB.byte.rpc.vrt') as src:
_, width, height = calculate_default_transform('EPSG:4326', 'EPSG:32610', width=7449, height=11522, rpcs=src.rpcs)
-
assert width == 10889
assert height == 11579
+
def test_rpcs_calculate_transform_pass_kwargs_to_transformer(caplog):
with rasterio.open('tests/data/RGB.byte.rpc.vrt') as src:
caplog.set_level(logging.DEBUG)
_, width, height = calculate_default_transform('EPSG:4326', 'EPSG:32610', width=7449, height=11522, rpcs=src.rpcs, RPC_HEIGHT=1000)
-
assert "RPC_HEIGHT" in caplog.text
assert width == 10880
assert height == 11587
+
def test_gcps_rpcs_exclusivity():
with pytest.raises(ValueError):
calculate_default_transform('EPSG:4326', 'EPSG:32610', width=7449, height=11522, gcps=[0], rpcs={'a':'123'})
-
+
+
def test_rpcs_bounds_exclusivity():
with pytest.raises(ValueError):
- calculate_default_transform('EPSG:4326', 'EPSG:32610', width=7449, height=11522, left=1, rpcs={'a':'123'})
\ No newline at end of file
+ calculate_default_transform('EPSG:4326', 'EPSG:32610', width=7449, height=11522, left=1, rpcs={'a':'123'})
View it on GitLab: https://salsa.debian.org/debian-gis-team/rasterio/-/commit/9a26cf3aebcdbb0526442cd7c2e5986244320f24
--
View it on GitLab: https://salsa.debian.org/debian-gis-team/rasterio/-/commit/9a26cf3aebcdbb0526442cd7c2e5986244320f24
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20210910/16be7bcc/attachment-0001.htm>
More information about the Pkg-grass-devel
mailing list