def test_raster(self): from decimal import Decimal from pyramid.httpexceptions import HTTPNotFound from tests import DummyRequest from c2cgeoportal_geoportal.views.raster import Raster request = DummyRequest() request.registry.settings = { "raster": { "dem1": { "file": "/opt/c2cgeoportal/geoportal/tests/data/dem.shp", "round": 0.1 }, "dem2": { "file": "/opt/c2cgeoportal/geoportal/tests/data/dem.shp", "round": 1 }, "dem3": { "file": "/opt/c2cgeoportal/geoportal/tests/data/dem.shp" }, } } raster = Raster(request) request.params["lon"] = "565000" request.params["lat"] = "218000" result = raster.raster() self.assertEqual(result["dem1"], None) self.assertEqual(result["dem2"], None) self.assertEqual(result["dem3"], None) request.params["lon"] = "548000" request.params["lat"] = "216000" result = raster.raster() self.assertAlmostEqual(result["dem1"], Decimal("1171.6")) self.assertAlmostEqual(result["dem2"], Decimal("1172")) self.assertAlmostEqual(result["dem3"], Decimal("1171.62")) request.params["layers"] = "dem2" result = raster.raster() self.assertFalse("dem1" in result) self.assertFalse("dem3" in result) self.assertAlmostEqual(result["dem2"], Decimal("1172")) # test wrong layer name request.params["layers"] = "wrong" self.assertRaises(HTTPNotFound, raster.raster)
def test_raster_angle(self): from decimal import Decimal from tests import DummyRequest from c2cgeoportal_geoportal.views.raster import Raster request = DummyRequest() request.registry.settings = { "raster": { "dem5": { "file": "/opt/c2cgeoportal/geoportal/tests/data/dem4.bt", "type": "gdal", "round": 0.01, } } } raster = Raster(request) # Upper left request.params["lon"] = "547990.0" request.params["lat"] = "216009.1" result = raster.raster() self.assertEqual(result["dem5"], Decimal("1164.2")) request.params["lon"] = "547990.9" request.params["lat"] = "216010.0" result = raster.raster() self.assertEqual(result["dem5"], Decimal("1164.2")) # Lower right request.params["lon"] = "547996.0" request.params["lat"] = "216003.1" result = raster.raster() self.assertEqual(result["dem5"], Decimal("1180.77")) request.params["lon"] = "547996.9" request.params["lat"] = "216004.0" result = raster.raster() self.assertEqual(result["dem5"], Decimal("1180.77")) # Out request.params["lon"] = "547997.4" request.params["lat"] = "216003.5" result = raster.raster() self.assertEqual(result["dem5"], None)
def test_raster_vrt(self): from decimal import Decimal from pyramid.testing import DummyRequest from c2cgeoportal_geoportal.views.raster import Raster request = DummyRequest() request.registry.settings = { "raster": { "dem6": { "file": "/src/geoportal/tests/data/dem4.vrt", "type": "gdal", "round": 0.01 } } } raster = Raster(request) # Upper left request.params["lon"] = "547990.4" request.params["lat"] = "216009.5" result = raster.raster() self.assertEqual(result["dem6"], Decimal("1164.2"))