Skip to content

Commit

Permalink
adding method to convert a CRS to a urn
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAnnex committed Oct 4, 2024
1 parent 1829fe1 commit 05b4b22
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion morecantile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def to_json(self, *args: Any, **kwargs: Any) -> str:
CRSType = CRS


def CRS_to_uri(crs: pyproj.CRS) -> str:
def CRS_to_info(crs: pyproj.CRS) -> tuple[str, str, str | None]:
"""Convert CRS to URI."""
authority = "EPSG"
code = None
Expand All @@ -157,10 +157,23 @@ def CRS_to_uri(crs: pyproj.CRS) -> str:
# if we have a version number in the authority, split it out
if "_" in authority:
authority, version = authority.split("_")
return authority, version, code


def CRS_to_uri(crs: pyproj.CRS) -> str:
"""Convert CRS to URI."""
authority, version, code = CRS_to_info(crs)
return f"http://www.opengis.net/def/crs/{authority}/{version}/{code}"


def CRS_to_urn(crs: pyproj.CRS) -> str:
"""Convert CRS to URN."""
authority, version, code = CRS_to_info(crs)
if version == "0":
version = ""
return f"urn:ogc:def:crs:{authority}:{version}:{code}"


def crs_axis_inverted(crs: pyproj.CRS) -> bool:
"""Check if CRS has inverted AXIS (lat,lon) instead of (lon,lat)."""
return crs.axis_info[0].abbrev.upper() in ["Y", "LAT", "N"]
Expand Down

0 comments on commit 05b4b22

Please sign in to comment.