Skip to content

Commit 41b66bb

Browse files
committed
Add function to get coordinates from axis of coordinates'crs
1 parent fbcb163 commit 41b66bb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

climada/util/coordinates.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,26 @@ def infer_unit_coords(coords):
145145
return unit
146146

147147

148+
def get_crs_unit(coords):
149+
"""
150+
Retrieve the unit of measurement for the coordinate reference system (CRS).
151+
152+
Parameters
153+
----------
154+
coords : GeoDataFrame
155+
An object with a coordinate reference system (CRS) attribute.
156+
157+
Returns
158+
-------
159+
unit : str
160+
The unit of measurement for the coordinate system, as specified in the
161+
CRS axis information. Assumes that both axes have the same unit.
162+
"""
163+
164+
unit = coords.crs.axis_info[0].unit_name # assume both axes have the same unit
165+
return unit
166+
167+
148168
def latlon_to_geosph_vector(lat, lon, rad=False, basis=False):
149169
"""Convert lat/lon coodinates to radial vectors (on geosphere)
150170

0 commit comments

Comments
 (0)