Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEM.to_vref fails if CRS does not have an EPSG code #262

Closed
adehecq opened this issue Apr 21, 2022 · 0 comments · Fixed by #350
Closed

DEM.to_vref fails if CRS does not have an EPSG code #262

adehecq opened this issue Apr 21, 2022 · 0 comments · Fixed by #350
Assignees
Labels
bug Something isn't working

Comments

@adehecq
Copy link
Member

adehecq commented Apr 21, 2022

When running the command my_dem.to_vref('WGS84'), it fails with the following error:

~/development/GlacioHack/xdem/xdem/dem.py in ccrs(self)
146 with warnings.catch_warnings():
147 warnings.filterwarnings("ignore", module="pyproj")
--> 148 self._ccrs = pyproj.Proj(init="EPSG:" + str(int(crs.to_epsg())), geoidgrids=self.vref_grid).crs
149 else:
150 self._ccrs = None

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

This is because in that case, my_dem.crs.to_epsg() returns None. The CRS of that DEM was set with a proj4 string and never with an EPSG code, so gdal probably does not find it.

You can reproduce the error by reprojecting the xdem sample DEM in a different projection e.g.,:

import geoutils as gu
import matplotlib.pyplot as plt
import xdem

reference_dem = xdem.DEM(xdem.examples.get_path("longyearbyen_ref_dem"))
test_dem = reference_dem.reproject(dst_crs='+proj=aea +lat_0=30 +lon_0=95 +lat_1=15 +lat_2=65 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs=True')
test_dem.set_vref('EGM08')
test_dem.to_vref('WGS84')
# -> Fails
reference_dem.set_vref('EGM08')
reference_dem.to_vref('WGS84')
# -> works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants