Commit 20c990a0 authored by Kris Vanneste's avatar Kris Vanneste
Browse files

Added rob submodule with geoserver.py containing extract_elevation_from_dem...

Added rob submodule with geoserver.py containing extract_elevation_from_dem copied from geosurvey.dgps.rtklib.

git-svn-id: https://svn.seismo.oma.be/svn/seismo/mapping/layeredbasemap/trunk@7525 40b490c5-b4d9-47cb-8714-9bef99b524d5
parent f2cf6ec5
"""
ROB-specific functionality related to layeredbasemap
"""
from __future__ import absolute_import, division, print_function, unicode_literals
## Reloading mechanism
try:
reloading
except NameError:
## Module is imported for the first time
reloading = False
else:
## Module is reloaded
reloading = True
try:
## Python 3
from importlib import reload
except ImportError:
## Python 2
pass
## Import submodules
## geoserver
if not reloading:
from . import geoserver
else:
reload(geoserver)
from .geoserver import *
"""
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
from secrets.geoserver import host
URL = 'http://%s/geoserver' % host
__all__ = ['extract_elevation_from_dem']
def extract_elevation_from_dem(xdata, ydata, dem_name, resolution=0, order=1):
"""
Extract elevation from DEM on Geoserver through WCS service.
This requires a connection to the ROB network.
:param xdata:
list or array of floats, X positions in native coordinates of DEM
:param ydata:
list or array of floats, Y positions in native coordinates of DEM
:param dem_name:
str, layer name of DEM on Geoserver
Known layer names are: 'ngi:DTM10k', 'agiv:DTM5m', 'agiv:DTM1m',
'ahn2:AHN2_5m' and "wallonie:MNT_1m_2013-2014"
:param resolution:
float, resolution of DEM in native units
(default: 0, will use best resolution available)
:param order:
int, type of interpolation, 0=nearest neighbor, 1=bilinear,
3=cubic spline
(default: 1)
:return:
numpy float array, elevations in m
"""
from ..data_types import WCSData
url = "%s/wcs" % URL
if not resolution:
if dem_name == 'agiv:DTM5m':
resolution = 5
elif dem_name == 'agiv:DTM1m':
resolution = 1
elif dem_name == 'ngi:DTM10k':
resolution = 20
elif dem_name == 'ahn2:AHN2_5m':
resolution = 5
xdata = np.asarray(xdata)
ydata = np.asarray(ydata)
xmin = np.floor(xdata.min() / resolution) * resolution
xmax = np.ceil(xdata.max() / resolution) * resolution
ymin = np.floor(ydata.min() / resolution) * resolution
ymax = np.ceil(ydata.max() / resolution) * resolution
bbox = (xmin, ymin, xmax, ymax)
print(bbox)
wcs_data = WCSData(url, dem_name, resolution=resolution, bbox=bbox)
elevs = wcs_data.interpolate(xdata, ydata, order=order)
return elevs
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment