Skip to content

Commit

Permalink
failed tests: use as_crs() to avoid CRS(crs) != crs in new rasterio
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitAronovitch committed Nov 17, 2024
1 parent 13091d4 commit 0956495
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion telluric/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion telluric/georaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions telluric/util/general.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from rasterio.crs import CRS


def convert_meter_to_latlon_deg(lat_deg):
Expand All @@ -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)
3 changes: 2 additions & 1 deletion telluric/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0956495

Please sign in to comment.