Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crs to urn #163

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion morecantile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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 @@ -156,10 +156,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
Loading