[Git][debian-gis-team/rasterio][master] 4 commits: New upstream version 1.2.9

Bas Couwenberg (@sebastic) gitlab at salsa.debian.org
Sat Oct 2 06:31:22 BST 2021



Bas Couwenberg pushed to branch master at Debian GIS Project / rasterio


Commits:
d81ce3b7 by Bas Couwenberg at 2021-10-02T07:08:21+02:00
New upstream version 1.2.9
- - - - -
f69eba92 by Bas Couwenberg at 2021-10-02T07:08:58+02:00
Update upstream source from tag 'upstream/1.2.9'

Update to upstream version '1.2.9'
with Debian dir 8c93b169ffa3ca6bab7ffb12684c8a22784ab5e2
- - - - -
532a6b2f by Bas Couwenberg at 2021-10-02T07:15:38+02:00
New upstream release.

- - - - -
beb33445 by Bas Couwenberg at 2021-10-02T07:16:25+02:00
Set distribution to unstable.

- - - - -


10 changed files:

- CHANGES.txt
- debian/changelog
- rasterio/__init__.py
- rasterio/_crs.pyx
- rasterio/features.py
- rasterio/rio/clip.py
- rasterio/rio/convert.py
- rasterio/rio/mask.py
- tests/test__crs.py
- tests/test_crs.py


Changes:

=====================================
CHANGES.txt
=====================================
@@ -1,6 +1,17 @@
 Changes
 =======
 
+1.2.9 (2021-10-01)
+------------------
+
+- Compute geometry_window more accurately and tightly for rotated rasters,
+  fixing a regression introduced in 1.2.1 (#2303).
+- Copy mask to destination in rio-clip and rio-convert (#2232).
+- Use a default 70% confidence threshold when matching CRS to definitions in
+  authority files (#2293). The confidence threshold can be defined when calling
+  to_epsg and to_authority, which partially addressed the issue reported in
+  #2290.
+
 1.2.8 (2021-09-09)
 ------------------
 


=====================================
debian/changelog
=====================================
@@ -1,10 +1,11 @@
-rasterio (1.2.8-2) UNRELEASED; urgency=medium
+rasterio (1.2.9-1) unstable; urgency=medium
 
   * Team upload.
+  * New upstream release.
   * Bump debhelper compat to 12, changes:
     - Drop --list-missing from dh_install
 
- -- Bas Couwenberg <sebastic at debian.org>  Tue, 14 Sep 2021 12:15:10 +0200
+ -- Bas Couwenberg <sebastic at debian.org>  Sat, 02 Oct 2021 07:16:13 +0200
 
 rasterio (1.2.8-1) unstable; urgency=medium
 


=====================================
rasterio/__init__.py
=====================================
@@ -40,7 +40,7 @@ import rasterio.enums
 import rasterio.path
 
 __all__ = ['band', 'open', 'pad', 'Env']
-__version__ = "1.2.8"
+__version__ = "1.2.9"
 __gdal_version__ = gdal_version()
 
 # Rasterio attaches NullHandler to the 'rasterio' logger and its


=====================================
rasterio/_crs.pyx
=====================================
@@ -206,7 +206,7 @@ cdef class _CRS(object):
             CPLFree(conv_wkt)
 
 
-    def to_epsg(self):
+    def to_epsg(self, confidence_threshold=70):
         """The epsg code of the CRS
 
         Returns
@@ -217,14 +217,14 @@ cdef class _CRS(object):
         if self._epsg is not None:
             return self._epsg
         else:
-            matches = self._matches()
+            matches = self._matches(confidence_threshold=confidence_threshold)
             if "EPSG" in matches:
                 self._epsg = int(matches["EPSG"][0])
                 return self._epsg
             else:
                 return None
 
-    def to_authority(self):
+    def to_authority(self, confidence_threshold=70):
         """The authority name and code of the CRS
 
         Returns
@@ -232,7 +232,7 @@ cdef class _CRS(object):
         (str, str) or None
 
         """
-        matches = self._matches()
+        matches = self._matches(confidence_threshold=confidence_threshold)
         # Note: before version 1.2.7 this function only paid attention
         # to EPSG as an authority, which is why it takes priority over
         # others even if they were a better match.
@@ -245,7 +245,7 @@ cdef class _CRS(object):
         else:
             return None
 
-    def _matches(self):
+    def _matches(self, confidence_threshold=70):
         """Find matches in authority files.
 
         Returns
@@ -258,6 +258,7 @@ cdef class _CRS(object):
         """
         cdef OGRSpatialReferenceH osr = NULL
         cdef OGRSpatialReferenceH *matches = NULL
+        cdef int *confidences = NULL
         cdef int num_matches = 0
         cdef int i = 0
 
@@ -267,12 +268,18 @@ cdef class _CRS(object):
             osr = exc_wrap_pointer(OSRClone(self._osr))
 
             if gdal_version().startswith("3"):
-                matches = OSRFindMatches(osr, NULL, &num_matches, NULL)
+                matches = OSRFindMatches(osr, NULL, &num_matches, &confidences)
 
                 for i in range(num_matches):
+                    confidence = confidences[i]
                     c_code = OSRGetAuthorityCode(matches[i], NULL)
                     c_name = OSRGetAuthorityName(matches[i], NULL)
-                    if c_code != NULL and c_name != NULL:
+
+                    log.debug(
+                        "Matched. confidence=%r, c_code=%r, c_name=%r",
+                        confidence, c_code, c_name)
+
+                    if c_code != NULL and c_name != NULL and confidence >= confidence_threshold:
                         code = c_code.decode('utf-8')
                         name = c_name.decode('utf-8')
                         results[name].append(code)
@@ -292,6 +299,7 @@ cdef class _CRS(object):
         finally:
             _safe_osr_release(osr)
             OSRFreeSRSArray(matches)
+            CPLFree(confidences)
 
     @staticmethod
     def from_epsg(code):


=====================================
rasterio/features.py
=====================================
@@ -438,48 +438,21 @@ def geometry_window(
 
     """
 
-    if pad_x:
-        pad_x = abs(pad_x * dataset.res[0])
+    all_bounds = [bounds(shape, transform=~dataset.transform) for shape in shapes]
 
-    if pad_y:
-        pad_y = abs(pad_y * dataset.res[1])
-
-    all_bounds = [bounds(shape) for shape in shapes]
-
-    xs = [
+    cols = [
         x
         for (left, bottom, right, top) in all_bounds
         for x in (left - pad_x, right + pad_x, right + pad_x, left - pad_x)
     ]
-    ys = [
+    rows = [
         y
         for (left, bottom, right, top) in all_bounds
-        for y in (top + pad_y, top + pad_y, bottom - pad_y, bottom - pad_y)
+        for y in (top - pad_y, top - pad_y, bottom + pad_y, bottom + pad_y)
     ]
 
-    rows1, cols1 = rowcol(
-        dataset.transform, xs, ys, op=math.floor, precision=pixel_precision
-    )
-
-    if isinstance(rows1, (int, float)):
-        rows1 = [rows1]
-    if isinstance(cols1, (int, float)):
-        cols1 = [cols1]
-
-    rows2, cols2 = rowcol(
-        dataset.transform, xs, ys, op=math.ceil, precision=pixel_precision
-    )
-
-    if isinstance(rows2, (int, float)):
-        rows2 = [rows2]
-    if isinstance(cols2, (int, float)):
-        cols2 = [cols2]
-
-    rows = rows1 + rows2
-    cols = cols1 + cols2
-
-    row_start, row_stop = min(rows), max(rows)
-    col_start, col_stop = min(cols), max(cols)
+    row_start, row_stop = int(math.floor(min(rows))), int(math.ceil(max(rows)))
+    col_start, col_stop = int(math.floor(min(cols))), int(math.ceil(max(cols)))
 
     window = Window(
         col_off=col_start,


=====================================
rasterio/rio/clip.py
=====================================
@@ -9,6 +9,7 @@ from . import options
 import rasterio
 from rasterio.coords import disjoint_bounds
 from rasterio.crs import CRS
+from rasterio.enums import MaskFlags
 from rasterio.windows import Window
 
 logger = logging.getLogger(__name__)
@@ -176,3 +177,15 @@ def clip(
                         masked=True,
                     )
                 )
+
+                if MaskFlags.per_dataset in src.mask_flag_enums[0]:
+                    out.write_mask(
+                        src.read_masks(
+                            window=out_window,
+                            out_shape=(src.count, height, width),
+                            boundless=True,
+                        )[0]
+                    )
+
+                # TODO: copy other properties (GCPs etc). Several other
+                # programs need the same utility.


=====================================
rasterio/rio/convert.py
=====================================
@@ -1,10 +1,10 @@
 """File translation command"""
 
-
 import click
 import numpy as np
 
 import rasterio
+from rasterio.enums import MaskFlags
 from rasterio.rio import options
 from rasterio.rio.helpers import resolve_inout
 
@@ -73,7 +73,6 @@ def convert(
 
             profile.update(**creation_options)
 
-            # "tiled" is special
             with rasterio.open(outputfile, 'w', **profile) as dst:
 
                 data = src.read()
@@ -94,3 +93,9 @@ def convert(
                 # Cast to the output dtype and write.
                 result = data.astype(dst_dtype, casting='unsafe', copy=False)
                 dst.write(result)
+
+                if MaskFlags.per_dataset in src.mask_flag_enums[0]:
+                    dst.write_mask(src.read_masks()[0])
+
+                # TODO: copy other properties (GCPs etc). Several other
+                # programs need the same utility.


=====================================
rasterio/rio/mask.py
=====================================
@@ -93,6 +93,8 @@ def mask(
             geometries = [f['geometry'] for f in geojson['features']]
         elif 'geometry' in geojson:
             geometries = (geojson['geometry'], )
+        elif 'coordinates' in geojson:
+            geometries = (geojson, )
         else:
             raise click.BadParameter('Invalid GeoJSON', param=input,
                                      param_hint='input')


=====================================
tests/test__crs.py
=====================================
@@ -89,7 +89,7 @@ def test_to_wkt():
 @pytest.mark.parametrize('proj_string', ['+init=epsg:4326', '+proj=longlat +datum=WGS84 +no_defs'])
 def test_to_epsg(proj_string):
     """CRS has EPSG code"""
-    assert _CRS.from_proj4(proj_string).to_epsg() == 4326
+    assert _CRS.from_proj4(proj_string).to_epsg(confidence_threshold=20) == 4326
 
 
 @pytest.mark.parametrize('proj_string', [ESRI_PROJECTION_STRING])


=====================================
tests/test_crs.py
=====================================
@@ -673,3 +673,11 @@ def test_latlong_northingeasting_gdal3():
     """Check CRS created from epsg with GDAL 3."""
     assert epsg_treats_as_latlong(CRS.from_epsg(4326))
     assert epsg_treats_as_northingeasting(CRS.from_epsg(2193))
+
+
+ at requires_gdal3
+def test_tmerc_no_match():
+    """Should not match an authority, see issue #2293."""
+    s = "+proj=tmerc +lat_0=0 +lon_0=10.7584 +k=0.9996 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
+    crs = CRS.from_string(s)
+    assert crs.to_epsg() is None



View it on GitLab: https://salsa.debian.org/debian-gis-team/rasterio/-/compare/cdb1f1932c0f02e262e38e03dc61d380019b6f35...beb33445bfa1bcc0ce3e7b0104ecc3dd7a833418

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/rasterio/-/compare/cdb1f1932c0f02e262e38e03dc61d380019b6f35...beb33445bfa1bcc0ce3e7b0104ecc3dd7a833418
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/20211002/027aefb4/attachment-0001.htm>


More information about the Pkg-grass-devel mailing list