Implement DEM for South Tyrol.
[philipp/winterrodeln/wrpylib.git] / tests / test_wrdem.py
1 import unittest
2
3 import owslib.wms
4
5 from wrpylib.wrdem import get_ele_from_raster, get_ele_from_wms
6 from wrpylib.wrvalidators import LonLat
7
8
9 class TestWrDemRaster(unittest.TestCase):
10     def setUp(self):
11         self.filename = '/home/philipp/daten/GeoData/dem/oesterreich_10m/dhm_lamb_10m.tif'
12         # https://www.data.gv.at/katalog/dataset/dgm
13
14     def test_get_ele_from_raster_inside_valid(self):
15         value = get_ele_from_raster(LonLat(13.682109, 47.934012), self.filename)
16         ele = round(int(value))
17         self.assertEqual(ele, 557)
18
19     def test_get_ele_from_raster_inside_invalid(self):
20         value = get_ele_from_raster(LonLat(14.67656, 48.16182), self.filename)
21         self.assertIsNone(value)
22
23     def test_get_ele_from_raster_outside(self):
24         value = get_ele_from_raster(LonLat(8.67656, 47.16182), self.filename)
25         self.assertIsNone(value)
26
27
28 class TestWrDemWms(unittest.TestCase):
29     def setUp(self):
30         url = 'http://geoservices.buergernetz.bz.it/geoserver/p_bz-elevation/ows?' \
31               'SERVICE=WMS&request=getCapabilities'
32         self.wms = owslib.wms.WebMapService(url, '1.3.0')
33         self.layer = 'DTM-2p5m'
34
35     def test_get_ele_from_wms_inside_valid(self):
36         ele = get_ele_from_wms(LonLat(11.31786, 46.68018), self.wms, self.layer)
37         self.assertAlmostEqual(ele, 2140.460, delta=0.1)
38
39     def test_get_ele_from_wms_inside_invalid(self):
40         ele = get_ele_from_wms(LonLat(10.893336, 46.849965), self.wms, self.layer)
41         self.assertIsNone(ele)
42
43     def test_get_ele_from_wms_outside(self):
44         ele = get_ele_from_wms(LonLat(9.908062, 45.948257), self.wms, self.layer)
45         self.assertIsNone(ele)