From 0956495767f2396a9364bf4e9229710c9316faf8 Mon Sep 17 00:00:00 2001 From: Amit Aronovitch Date: Mon, 18 Nov 2024 00:43:50 +0200 Subject: [PATCH] failed tests: use as_crs() to avoid CRS(crs) != crs in new rasterio --- telluric/collections.py | 3 ++- telluric/georaster.py | 3 ++- telluric/util/general.py | 5 +++++ telluric/vectors.py | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/telluric/collections.py b/telluric/collections.py index e7ee0586..bfe1d77c 100644 --- a/telluric/collections.py +++ b/telluric/collections.py @@ -16,6 +16,7 @@ from shapely.prepared import prep from telluric.constants import WEB_MERCATOR_CRS, WGS84_CRS +from telluric.util.general import as_crs from telluric.vectors import GeoVector from telluric.features import GeoFeature from telluric.plotting import NotebookPlottingMixin @@ -532,7 +533,7 @@ def open(cls, filename, crs=None): """ with fiona.Env(): with fiona.open(filename, 'r') as source: - original_crs = CRS(source.crs) + original_crs = as_crs(source.crs) schema = source.schema length = len(source) crs = crs or original_crs diff --git a/telluric/georaster.py b/telluric/georaster.py index 1137d5c6..c2fcb8c6 100644 --- a/telluric/georaster.py +++ b/telluric/georaster.py @@ -47,6 +47,7 @@ from PIL import Image from telluric.constants import WEB_MERCATOR_CRS, MERCATOR_RESOLUTION_MAPPING, RASTER_TYPE, WGS84_CRS +from telluric.util.general import as_crs from telluric.vectors import GeoVector from telluric.util.projections import transform from telluric.util.raster_utils import ( @@ -620,7 +621,7 @@ def __init__(self, image=None, affine=None, crs=None, """ super().__init__(image=image, band_names=band_names, shape=shape, nodata=nodata) self._affine = deepcopy(affine) - self._crs = None if crs is None else CRS(crs) # type: Union[None, CRS] + self._crs = None if crs is None else as_crs(crs) # type: Union[None, CRS] self._filename = filename self._temporary = temporary self._footprint = copy(footprint) diff --git a/telluric/util/general.py b/telluric/util/general.py index d1dff597..d26e6f43 100644 --- a/telluric/util/general.py +++ b/telluric/util/general.py @@ -1,4 +1,5 @@ import numpy as np +from rasterio.crs import CRS def convert_meter_to_latlon_deg(lat_deg): @@ -14,3 +15,7 @@ def convert_resolution_from_meters_to_deg(position_lat, gsd_metric): gsd_deg_lat = gsd_metric * m_to_deg_lat gsd_deg_lon = gsd_metric * m_to_deg_lon return gsd_deg_lon, gsd_deg_lat + + +def as_crs(crs) -> CRS: + return crs if isinstance(crs, CRS) else CRS(crs) diff --git a/telluric/vectors.py b/telluric/vectors.py index 571dc1d7..c2938f9c 100644 --- a/telluric/vectors.py +++ b/telluric/vectors.py @@ -17,6 +17,7 @@ from typing import Tuple, Iterator from telluric.constants import DEFAULT_CRS, EQUAL_AREA_CRS, WGS84_CRS, WEB_MERCATOR_CRS +from telluric.util.general import as_crs from telluric.util.projections import transform from telluric.plotting import NotebookPlottingMixin @@ -289,7 +290,7 @@ def __init__(self, shape, crs=DEFAULT_CRS, safe=True): """ self._shape = shape # type: shapely.geometry.base.BaseGeometry - self._crs = CRS(crs) + self._crs = as_crs(crs) @classmethod def from_geojson(cls, filename):