Skip to content

Commit bde927a

Browse files
authored
Make crs better at handling EPSG (#1330)
1 parent f7f2d1c commit bde927a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

hvplot/tests/testutil.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ def test_check_crs():
261261
[
262262
'+init=epsg:26911',
263263
'PlateCarree',
264+
'epsg:6933',
265+
6933,
266+
'EPSG: 6933',
264267
],
265268
)
266269
def test_process_crs(input):

hvplot/util.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,24 @@ def process_crs(crs):
303303
crs = crs.to_wkt()
304304

305305
errors = []
306-
if isinstance(crs, (str, int)): # epsg codes
306+
if isinstance(crs, (str, int, pyproj.Proj)):
307+
wkt = crs
308+
if isinstance(crs, (str, int)): # epsg codes
309+
try:
310+
wkt = pyproj.CRS.from_epsg(crs).to_wkt()
311+
except Exception as e:
312+
errors.append(e)
307313
try:
308-
crs = pyproj.CRS.from_epsg(crs).to_wkt()
314+
return proj_to_cartopy(wkt) # should be all proj4 or wkt strings
309315
except Exception as e:
310316
errors.append(e)
311-
if isinstance(crs, (str, pyproj.Proj)): # proj4/wkt strings
317+
318+
if isinstance(crs, (str, int)):
319+
if isinstance(crs, str):
320+
# pyproj does not expect epsg to be prefixed with `EPSG:`
321+
crs = crs.upper().replace('EPSG:', '').strip()
312322
try:
313-
return proj_to_cartopy(crs)
323+
return ccrs.epsg(crs)
314324
except Exception as e:
315325
errors.append(e)
316326

0 commit comments

Comments
 (0)