MCPcopy Create free account
hub / github.com/holoviz/hvplot / process_crs

Function process_crs

hvplot/util.py:339–412  ·  view source on GitHub ↗

Parses cartopy CRS definitions defined in one of a few formats: 1. EPSG codes: Defined as string of the form "EPSG: {code}" or an integer 2. proj.4 string: Defined as string of the form "{proj.4 string}" 3. cartopy.crs.CRS instance 3. pyproj.Proj or pyproj.CRS instanc

(crs)

Source from the content-addressed store, hash-verified

337
338
339def process_crs(crs):
340 """
341 Parses cartopy CRS definitions defined in one of a few formats:
342
343 1. EPSG codes: Defined as string of the form "EPSG: {code}" or an integer
344 2. proj.4 string: Defined as string of the form "{proj.4 string}"
345 3. cartopy.crs.CRS instance
346 3. pyproj.Proj or pyproj.CRS instance
347 4. WKT string: Defined as string of the form "{WKT string}"
348 5. None defaults to crs.PlateCaree
349 """
350 missing = []
351 try:
352 import cartopy.crs as ccrs
353 except ImportError:
354 missing.append('cartopy')
355 try:
356 import geoviews as gv # noqa
357 except ImportError:
358 missing.append('geoviews')
359 try:
360 import pyproj
361 except ImportError:
362 missing.append('pyproj')
363 if missing:
364 raise ImportError(f'Geographic projection support requires: {", ".join(missing)}.')
365
366 if crs is None:
367 return ccrs.PlateCarree()
368 elif isinstance(crs, ccrs.CRS):
369 return crs
370 elif isinstance(crs, str):
371 all_crs = [
372 proj
373 for proj in dir(ccrs)
374 if callable(getattr(ccrs, proj))
375 and proj not in ['ABCMeta', 'CRS']
376 and proj[0].isupper()
377 or proj == 'GOOGLE_MERCATOR'
378 ]
379 if crs in all_crs and crs != 'GOOGLE_MERCATOR':
380 return getattr(ccrs, crs)()
381 elif crs == 'GOOGLE_MERCATOR':
382 return getattr(ccrs, crs)
383 elif isinstance(crs, pyproj.CRS):
384 crs = crs.to_wkt()
385
386 errors = []
387 if isinstance(crs, (str, int, pyproj.Proj)):
388 wkt = crs
389 if isinstance(crs, (str, int)): # epsg codes
390 try:
391 wkt = pyproj.CRS.from_epsg(crs).to_wkt()
392 except Exception as e:
393 errors.append(e)
394 try:
395 return proj_to_cartopy(wkt) # should be all proj4 or wkt strings
396 except Exception as e:

Callers 10

test_process_crsFunction · 0.90
drawFunction · 0.85
__init__Method · 0.85
_process_crsMethod · 0.85

Calls 1

proj_to_cartopyFunction · 0.85

Tested by 7

test_process_crsFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…