Skip to content

Commit

Permalink
Fix CRS.units extraction logic #120
Browse files Browse the repository at this point in the history
Do not assume number of axis or their order, instead
use `.direction` to select y,x units
  • Loading branch information
Kirill888 committed Jan 26, 2024
1 parent 70bdb77 commit 9d159aa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions odc/geo/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,12 @@ def units(self) -> Tuple[str, str]:
return "degrees_north", "degrees_east"

if self.projected:
x, y = self._crs.axis_info
return x.unit_name, y.unit_name
_dir_renames = {"north": "y", "south": "y", "east": "x", "west": "x"}
units = {
_dir_renames.get(ax.direction, ax.direction): ax.unit_name
for ax in self._crs.axis_info
}
return units.get("y", ""), units.get("x", "")

raise ValueError("Neither projected nor geographic") # pragma: no cover

Expand Down

0 comments on commit 9d159aa

Please sign in to comment.