Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch from rasterio/gdal to pyproj #58

Merged
merged 16 commits into from
Sep 9, 2021
23 changes: 16 additions & 7 deletions morecantile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pydantic import AnyHttpUrl, BaseModel, Field, PrivateAttr, validator
from pyproj import CRS, Transformer
from pyproj.enums import WktVersion
from pyproj.exceptions import ProjError

from .commons import BoundingBox, Coords, Tile
from .errors import (
Expand All @@ -28,7 +29,6 @@
from rasterio.crs import CRS as rasterioCRS
from rasterio.env import GDALVersion
except ModuleNotFoundError:
rasterio = None
rasterioCRS = None
GDALVersion = None

Expand Down Expand Up @@ -149,12 +149,21 @@ def __init__(self, **data):
"""Create PyProj transforms and check if TileMatrixSet supports quadkeys."""
super().__init__(**data)
self._is_quadtree = check_quadkey_support(self.tileMatrix)
self._to_wgs84 = Transformer.from_crs(
self.supportedCRS, WGS84_CRS, always_xy=True
)
self._from_wgs84 = Transformer.from_crs(
WGS84_CRS, self.supportedCRS, always_xy=True
)
try:
self._to_wgs84 = Transformer.from_crs(
self.supportedCRS, WGS84_CRS, always_xy=True
)
self._from_wgs84 = Transformer.from_crs(
WGS84_CRS, self.supportedCRS, always_xy=True
)
except ProjError:
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(
"Could not create coordinate Transformer from input CRS to WGS84"
"tms methods might not be available.",
UserWarning,
)
self._to_wgs84 = None
self._from_wgs84 = None

@validator("tileMatrix")
def sort_tile_matrices(cls, v):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ def test_nztm_quad_is_quad():
def test_nztm_quad_scales():
nztm_tms = morecantile.tms.get("NZTM2000Quad")
google_tms = morecantile.tms.get("WebMercatorQuad")
print(dir(google_tms))

for z in range(2, nztm_tms.maxzoom + 2):
assert (
round(
Expand Down Expand Up @@ -278,7 +276,10 @@ def test_schema():
"+proj=stere +lat_0=90 +lon_0=0 +k=2 +x_0=0 +y_0=0 +R=3396190 +units=m +no_defs"
)
extent = [-13584760.000, -13585240.000, 13585240.000, 13584760.000]
tms = morecantile.TileMatrixSet.custom(extent, crs, identifier="MarsNPolek2MOLA5k")
with pytest.warns(UserWarning):
tms = morecantile.TileMatrixSet.custom(
extent, crs, identifier="MarsNPolek2MOLA5k"
)
assert tms.schema()
assert tms.schema_json()
assert tms.dict(exclude_none=True)
Expand Down