Skip to content

Commit

Permalink
Merge pull request #152 from AndrewAnnex/fix_geographic_crs_must_be_p…
Browse files Browse the repository at this point in the history
…yproj_crs_obj

update to ensure self._geographic_crs will be a pyproj CRS object.
  • Loading branch information
vincentsarago authored Aug 27, 2024
2 parents cb36d63 + 64e2cf0 commit 6e0bfd3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '*'
pull_request:
env:
LATEST_PY_VERSION: '3.10'
LATEST_PY_VERSION: '3.12'

jobs:
tests:
Expand All @@ -20,6 +20,7 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12'

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

## 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)

* adds --tms optional argument to the shapes and tiles cli tools (author @AndrewAnnex, https://github.com/developmentseed/morecantile/pull/151)
Expand Down
11 changes: 4 additions & 7 deletions morecantile/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -499,7 +494,9 @@ 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(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 13 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 6e0bfd3

Please sign in to comment.