From 27d919202a324436b7aed261e26b87b3402b545b Mon Sep 17 00:00:00 2001 From: "Dr. Andrew Annex" Date: Mon, 26 Aug 2024 14:35:41 -0700 Subject: [PATCH 1/3] update to ensure self._geographic_crs will be a pyproj CRS object. Likely a lot more could be done here to error catch but this could be reasonably robust as is --- morecantile/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/morecantile/models.py b/morecantile/models.py index 90550b0..36412f0 100644 --- a/morecantile/models.py +++ b/morecantile/models.py @@ -499,7 +499,7 @@ def __init__(self, **data): """Set private attributes.""" super().__init__(**data) - self._geographic_crs = data.get("_geographic_crs", WGS84_CRS) + self._geographic_crs = pyproj.CRS.from_user_input(data.get("_geographic_crs", WGS84_CRS)) try: self._to_geographic = pyproj.Transformer.from_crs( From 035cf47893156aeccac6d5355e94508de254ec2d Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Tue, 27 Aug 2024 16:47:58 +0200 Subject: [PATCH 2/3] update changelog and add tests --- CHANGES.md | 4 ++++ morecantile/models.py | 11 ++++------- tests/test_models.py | 13 +++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d785954..e81d327 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,8 @@ +## 5.4.1 (2024-08-27) + +* ensure `TileMatrixSet._geographic_crs` is a pyproj CRS object (author @AndrewAnnex, https://github.com/developmentseed/morecantile/pull/152) + ## 5.4.0 (2024-08-20) * adds --tms optional argument to the shapes and tiles cli tools (author @AndrewAnnex, https://github.com/developmentseed/morecantile/pull/151) diff --git a/morecantile/models.py b/morecantile/models.py index 36412f0..9659f22 100644 --- a/morecantile/models.py +++ b/morecantile/models.py @@ -1,7 +1,6 @@ """Pydantic modules for OGC TileMatrixSets (https://www.ogc.org/standards/tms)""" import math -import sys import warnings from functools import cached_property from typing import Any, Dict, Iterator, List, Literal, Optional, Sequence, Tuple, Union @@ -18,6 +17,7 @@ model_validator, ) from pyproj.exceptions import CRSError, ProjError +from typing_extensions import Annotated from morecantile.commons import BoundingBox, Coords, Tile from morecantile.errors import ( @@ -37,11 +37,6 @@ to_rasterio_crs, ) -if sys.version_info >= (3, 9): - from typing import Annotated # pylint: disable=no-name-in-module -else: - from typing_extensions import Annotated - NumType = Union[float, int] BoundsType = Tuple[NumType, NumType] LL_EPSILON = 1e-11 @@ -499,7 +494,9 @@ def __init__(self, **data): """Set private attributes.""" super().__init__(**data) - self._geographic_crs = pyproj.CRS.from_user_input(data.get("_geographic_crs", WGS84_CRS)) + self._geographic_crs = pyproj.CRS.from_user_input( + data.get("_geographic_crs", WGS84_CRS) + ) try: self._to_geographic = pyproj.Transformer.from_crs( diff --git a/tests/test_models.py b/tests/test_models.py index 28fc34b..95e4c33 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -162,6 +162,19 @@ def test_Custom(): assert round(wmMat.scaleDenominator, 6) == round(cusMat.scaleDenominator, 6) assert round(wmMat.pointOfOrigin[0], 6) == round(cusMat.pointOfOrigin[0], 6) + extent = (-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892) + custom_tms = TileMatrixSet.custom( + extent, pyproj.CRS.from_epsg(3857), geographic_crs="epsg:4326" + ) + assert isinstance(custom_tms._geographic_crs, pyproj.CRS) + assert custom_tms._geographic_crs == pyproj.CRS.from_epsg(4326) + + extent = (-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892) + custom_tms = TileMatrixSet.custom( + extent, pyproj.CRS.from_epsg(3857), geographic_crs=pyproj.CRS.from_epsg(4326) + ) + assert isinstance(custom_tms._geographic_crs, pyproj.CRS) + def test_custom_tms_bounds_epsg4326(): """Check bounds with epsg4326.""" From 64e2cf0e1a6b198e14f241dedeadf6adff7910da Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Tue, 27 Aug 2024 16:50:05 +0200 Subject: [PATCH 3/3] add python 3.12 --- .github/workflows/ci.yml | 3 ++- CHANGES.md | 1 + pyproject.toml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f67ba2..ce69c82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: - '*' pull_request: env: - LATEST_PY_VERSION: '3.10' + LATEST_PY_VERSION: '3.12' jobs: tests: @@ -20,6 +20,7 @@ jobs: - '3.9' - '3.10' - '3.11' + - '3.12' steps: - uses: actions/checkout@v3 diff --git a/CHANGES.md b/CHANGES.md index e81d327..e73ca6c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## 5.4.1 (2024-08-27) * ensure `TileMatrixSet._geographic_crs` is a pyproj CRS object (author @AndrewAnnex, https://github.com/developmentseed/morecantile/pull/152) +* add `python 3.12` support ## 5.4.0 (2024-08-20) diff --git a/pyproject.toml b/pyproject.toml index 7808b51..62c9ae3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering :: GIS", ] dynamic = ["version"]