Implement bounding box check.
[philipp/winterrodeln/wrpylib.git] / tests / test_wrdem.py
1 import unittest
2
3 import owslib.wms
4 import rasterio
5
6 from wrpylib.wrdem import get_ele_from_raster, get_ele_from_wms, MultiDem
7 from wrpylib.wrvalidators import LonLat
8
9
10 class TestWrDemRaster(unittest.TestCase):
11     def setUp(self):
12         filename = '/home/philipp/daten/GeoData/dem/oesterreich_10m/dhm_lamb_10m.tif'
13         # https://www.data.gv.at/katalog/dataset/dgm
14         self.dataset = rasterio.open(filename)
15
16     def tearDown(self):
17         self.dataset.close()
18
19     def test_get_ele_from_raster_inside_valid(self):
20         value = get_ele_from_raster(LonLat(13.682109, 47.934012), self.dataset)
21         ele = round(int(value))
22         self.assertEqual(ele, 557)
23
24     def test_get_ele_from_raster_inside_invalid(self):
25         value = get_ele_from_raster(LonLat(14.67656, 48.16182), self.dataset)
26         self.assertIsNone(value)
27
28     def test_get_ele_from_raster_outside(self):
29         value = get_ele_from_raster(LonLat(8.67656, 47.16182), self.dataset)
30         self.assertIsNone(value)
31
32
33 class TestWrDemWms(unittest.TestCase):
34     def setUp(self):
35         url = 'http://geoservices.buergernetz.bz.it/geoserver/p_bz-elevation/ows?' \
36               'SERVICE=WMS&request=getCapabilities'
37         self.wms = owslib.wms.WebMapService(url, '1.3.0')
38         self.layer = 'DTM-2p5m'
39
40     def test_get_ele_from_wms_inside_valid(self):
41         ele = get_ele_from_wms(LonLat(11.31786, 46.68018), self.wms, self.layer)
42         self.assertAlmostEqual(ele, 2140.460, delta=0.1)
43
44     def test_get_ele_from_wms_inside_invalid(self):
45         ele = get_ele_from_wms(LonLat(10.893336, 46.849965), self.wms, self.layer)
46         self.assertIsNone(ele)
47
48     def test_get_ele_from_wms_outside(self):
49         ele = get_ele_from_wms(LonLat(9.908062, 45.948257), self.wms, self.layer)
50         self.assertIsNone(ele)
51
52
53 class TestWrDemMultiDem(unittest.TestCase):
54     def setUp(self):
55         self.dem = MultiDem()
56
57     def tearDown(self):
58         self.dem.close()
59
60     def test_get_ele_valid(self):
61         ele, name = self.dem.get_ele(LonLat(13.682109, 47.934012))
62         self.assertAlmostEqual(ele, 557, delta=0.5)
63
64         ele, name = self.dem.get_ele(LonLat(11.31786, 46.68018))
65         self.assertAlmostEqual(ele, 2140.460, delta=0.1)
66
67     def test_get_ele_outside(self):
68         ele, name = self.dem.get_ele(LonLat(1., 2.))
69         self.assertIsNone(ele)