Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Lookup elevation in Norway based on geonorge's wms service
Author: Ole Jørgen Brønner,
Lookup elevation in Norway (NB: might need to change dataset for northern Norway)
- owslib
- rasterio
import owslib.wcs as wcs
import rasterio as rio
import io
# See
# for other datasets.
# NB: owslib doesn't support 1.1.2 which is the native WCS version of geonorge atm. Request an older version explicitly as a workaround
wcs_url = ""
client = wcs.WebCoverageService(wcs_url)
def bbox_around(long, lat, d=1e-4*3):
# IMPROVEMENT: calculate a square box (square in lat/lons is not square in meters)
return [long-d, lat-d, long+d, lat+d]
def find_ele(lon, lat):
Find elevation in meters at given WGS84 coordinate
:param lon:
:param lat:
:return: elevation in meters
res = client.getCoverage(
bbox=bbox_around(lon, lat),
crs='EPSG:4326', # Note: same as WGS84
width=100, height=100, # IMPROVEMENT: estimate resolution in a better way
bs =
with as ds:
ele_map =
i, j = ds.index(lon, lat)
return ele_map[0, i, j]

This comment has been minimized.

Copy link
Owner Author

@olejorgenb olejorgenb commented Sep 4, 2019

NB: the DTM model might be more suitable depending on your the application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment