Skip to content

Commit

Permalink
fix CRS for non-int code by URL (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault authored Nov 1, 2023
1 parent 5fad88b commit 5d8e193
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
26 changes: 14 additions & 12 deletions owslib/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1750,12 +1750,15 @@ def __init__(self, crs, axisorder=None):
self.encoding = "uri"
vals = self.id.split('/')
self.authority = vals[5].upper()
self.code = int(vals[-1])
self.code = vals[-1]
self.version = vals[-2]
if self.version == '0':
self.version = None
elif self.id.find('#') != -1: # URI Style 2
self.encoding = "uri"
vals = self.id.split('#')
self.authority = vals[0].split('/')[-1].split('.')[0].upper()
self.code = int(vals[-1])
self.code = vals[-1]
elif len(values) > 2: # it's a URN style
self.naming_authority = values[1]
self.encoding = "urn"
Expand All @@ -1772,21 +1775,20 @@ def __init__(self, crs, axisorder=None):
if len(values) == 7: # version, even if empty, is included
if values[5]:
self.version = values[5]

# code is always the last value
try:
self.code = int(values[-1])
except Exception:
self.code = values[-1]
self.code = values[-1]

elif len(values) == 2: # it's an authority:code code
self.encoding = "code"
self.authority = values[0].upper()
self.code = values[1]

try:
self.code = int(values[1])
except Exception:
self.code = values[1]
# convert code if possible for int mapping with axisorder
# if not an int, it can be another code such as CRS84
# from http://www.opengis.net/def/crs/OGC/1.3/CRS84
try:
self.code = int(self.code)
except (TypeError, ValueError):
pass

# if the user has not forced the axisorder,
# scan the list of codes that have an axis ordering of
Expand Down
7 changes: 7 additions & 0 deletions tests/doctests/crs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@
'PROJ4'
>>> c.code
'+proj=lcc +lat_1=46.8 +lat_0=46.8 +lon_0=0 +k_0=0.99987742 +x_0=600000 +y_0=2200000'
>>> c=crs.Crs('http://www.opengis.net/def/crs/OGC/1.3/CRS84')
>>> c.code
'CRS84'
>>> c.version
'1.3'
>>> c.getcodeurn()
'urn:ogc:def:crs:OGC:1.3:CRS84'

0 comments on commit 5d8e193

Please sign in to comment.