Work on parsing wikicode (currently Rodelbahnbox).
[philipp/winterrodeln/wrpylib.git] / tests / test_wrdem.py
index 05700d57109e907c4aedc450545055a9d57aea9c..fb6f0f69fa3dc70c2279e1feb6e562d07ec02388 100644 (file)
@@ -1,9 +1,10 @@
 import unittest
 
 import owslib.wms
-import rasterio
+import rasterio  # pip install rasterio
 
-from wrpylib.wrdem import get_ele_from_raster, get_ele_from_wms, MultiDem
+from wrpylib.wrdem import get_ele_from_raster, get_ele_from_wms, MultiDem, transform_lon_lat, DemSwitzerland, \
+    DemBasemap, DemBavaria
 from wrpylib.wrvalidators import LonLat
 
 
@@ -17,17 +18,19 @@ class TestWrDemRaster(unittest.TestCase):
         self.dataset.close()
 
     def test_get_ele_from_raster_inside_valid(self):
-        value = get_ele_from_raster(LonLat(13.682109, 47.934012), self.dataset)
-        ele = round(int(value))
-        self.assertEqual(ele, 557)
+        x_y = transform_lon_lat(LonLat(13.682109, 47.934012), self.dataset.crs.to_proj4())
+        ele = get_ele_from_raster(self.dataset, x_y)
+        self.assertAlmostEqual(ele, 557, delta=0.5)
 
     def test_get_ele_from_raster_inside_invalid(self):
-        value = get_ele_from_raster(LonLat(14.67656, 48.16182), self.dataset)
-        self.assertIsNone(value)
+        x_y = transform_lon_lat(LonLat(14.67656, 48.16182), self.dataset.crs.to_proj4())
+        ele = get_ele_from_raster(self.dataset, x_y)
+        self.assertIsNone(ele)
 
     def test_get_ele_from_raster_outside(self):
-        value = get_ele_from_raster(LonLat(8.67656, 47.16182), self.dataset)
-        self.assertIsNone(value)
+        x_y = transform_lon_lat(LonLat(8.67656, 47.16182), self.dataset.crs.to_proj4())
+        ele = get_ele_from_raster(self.dataset, x_y)
+        self.assertIsNone(ele)
 
 
 class TestWrDemWms(unittest.TestCase):
@@ -50,6 +53,70 @@ class TestWrDemWms(unittest.TestCase):
         self.assertIsNone(ele)
 
 
+class TestDemBasemap(unittest.TestCase):
+    def setUp(self):
+        self.dem = DemBasemap()
+
+    def tearDown(self):
+        self.dem.close()
+
+    def test_get_ele_inside_valid(self):
+        ele = self.dem.get_ele(LonLat(13.682109, 47.934012))
+        self.assertAlmostEqual(ele, 557, delta=0.5)
+
+    def test_get_ele_inside_invalid(self):
+        ele = self.dem.get_ele(LonLat(14.67656, 48.16182))
+        self.assertIsNone(ele)
+
+    def test_get_ele_outside(self):
+        ele = self.dem.get_ele(LonLat(8.67656, 47.16182))
+        self.assertIsNone(ele)
+
+
+class TestDemSwitzerland(unittest.TestCase):
+    def setUp(self):
+        self.dem = DemSwitzerland()
+
+    def tearDown(self):
+        self.dem.close()
+
+    def test_get_ele_inside_valid(self):
+        ele = self.dem.get_ele(LonLat(8.452512, 47.064715))
+        self.assertAlmostEqual(ele, 818, delta=0.5)
+
+    def test_get_ele_inside_invalid(self):
+        ele = self.dem.get_ele(LonLat(8.319, 45.970))
+        self.assertIsNone(ele)
+
+    def test_get_ele_outside(self):
+        ele = self.dem.get_ele(LonLat(5.182008, 46.799233))
+        self.assertIsNone(ele)
+
+
+class TestDemBavaria(unittest.TestCase):
+    def setUp(self):
+        self.dem = DemBavaria()
+
+    def tearDown(self):
+        self.dem.close()
+
+    def test_get_ele_inside_valid(self):
+        ele = self.dem.get_ele(LonLat(11.5396, 47.6809))
+        self.assertAlmostEqual(ele, 863, delta=0.5)
+        # ele = self.dem.get_ele(LonLat(11.010041, 47.618947))
+        # self.assertAlmostEqual(ele, 998, delta=0.5)
+        # ele = self.dem.get_ele(LonLat(11.019577, 47.620695))
+        # self.assertAlmostEqual(ele, 833, delta=0.5)
+
+    def test_get_ele_inside_invalid(self):
+        ele = self.dem.get_ele(LonLat(9.91, 48.97))
+        self.assertIsNone(ele)
+
+    def test_get_ele_outside(self):
+        ele = self.dem.get_ele(LonLat(5.182008, 46.799233))
+        self.assertIsNone(ele)
+
+
 class TestWrDemMultiDem(unittest.TestCase):
     def setUp(self):
         self.dem = MultiDem()