From 05b4b223a5b8f587b950a5b90b21e07b1f23f9b5 Mon Sep 17 00:00:00 2001 From: "Dr. Andrew Annex" Date: Fri, 4 Oct 2024 09:26:06 -0700 Subject: [PATCH] adding method to convert a CRS to a urn --- morecantile/models.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/morecantile/models.py b/morecantile/models.py index 863a5b6..5ef1715 100644 --- a/morecantile/models.py +++ b/morecantile/models.py @@ -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 @@ -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"]