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

Function check_crs

hvplot/util.py:96–143  ·  view source on GitHub ↗

Checks if the crs represents a valid grid, projection or ESPG string. (Code copied and adapted from https://github.com/fmaussion/salem) Examples -------- >>> p = check_crs('epsg:26915 +units=m') >>> p.srs '+proj=utm +zone=15 +datum=NAD83 +units=m +no_defs' >>> p =

(crs)

Source from the content-addressed store, hash-verified

94
95
96def check_crs(crs):
97 """
98 Checks if the crs represents a valid grid, projection or ESPG string.
99
100 (Code copied and adapted from https://github.com/fmaussion/salem)
101
102 Examples
103 --------
104 >>> p = check_crs('epsg:26915 +units=m')
105 >>> p.srs
106 '+proj=utm +zone=15 +datum=NAD83 +units=m +no_defs'
107 >>> p = check_crs('wrong')
108 >>> p is None
109 True
110
111 Returns
112 -------
113 A valid crs if possible, otherwise None.
114 """
115 import pyproj
116
117 try:
118 crs_type = pyproj.crs.CRS
119 except AttributeError:
120
121 class Dummy:
122 pass
123
124 crs_type = Dummy
125
126 if isinstance(crs, pyproj.Proj):
127 out = crs
128 elif isinstance(crs, crs_type):
129 out = pyproj.Proj(crs.to_wkt(), preserve_units=True)
130 elif isinstance(crs, dict) or isinstance(crs, str):
131 if isinstance(crs, str):
132 try:
133 crs = pyproj.CRS.from_wkt(crs)
134 except RuntimeError:
135 # quick fix for https://github.com/pyproj4/pyproj/issues/345
136 crs = crs.replace(' ', '').replace('+', ' +')
137 try:
138 out = pyproj.Proj(crs, preserve_units=True)
139 except RuntimeError:
140 out = None
141 else:
142 out = None
143 return out
144
145
146def proj_is_latlong(proj):

Callers 2

test_check_crsFunction · 0.90
proj_to_cartopyFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_check_crsFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…