Skip to content

Commit

Permalink
Add CRS_to_urn (#752)
Browse files Browse the repository at this point in the history
* adds CRS_to_urn function

* fix CRS expected type

* switch to using typing's version of Tuple

* format

* make the crs info function private

* update changelog

---------

Co-authored-by: vincentsarago <[email protected]>
  • Loading branch information
AndrewAnnex and vincentsarago authored Oct 22, 2024
1 parent 0900af9 commit 06c62d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 7.0.1 (2024-10-22)

* Add `CRS_to_urn` method and update internals for `CRS_to_uri` (author @AndrewAnnex, https://github.com/cogeotiff/rio-tiler/pull/752)

# 7.0.0 (2024-10-21)

Expand Down
24 changes: 23 additions & 1 deletion rio_tiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def cast_to_sequence(val: Optional[Any] = None) -> Sequence:
return val


def CRS_to_uri(crs: CRS) -> Optional[str]:
def _CRS_authority_info(crs: CRS) -> Optional[Tuple[str, str, str]]:
"""Convert CRS to URI.
Code adapted from https://github.com/developmentseed/morecantile/blob/1829fe12408e4a1feee7493308f3f02257ef4caf/morecantile/models.py#L148-L161
Expand All @@ -804,6 +804,28 @@ def CRS_to_uri(crs: CRS) -> Optional[str]:
if "_" in authority:
authority, version = authority.split("_")

return authority, version, code

return None


def CRS_to_uri(crs: CRS) -> Optional[str]:
"""Convert CRS to URI."""
if info := _CRS_authority_info(crs):
authority, version, code = info

return f"http://www.opengis.net/def/crs/{authority}/{version}/{code}"

return None


def CRS_to_urn(crs: CRS) -> Optional[str]:
"""Convert CRS to URN."""
if info := _CRS_authority_info(crs):
authority, version, code = info
if version == "0":
version = ""

return f"urn:ogc:def:crs:{authority}:{version}:{code}"

return None

0 comments on commit 06c62d8

Please sign in to comment.