Esempio n. 1
0
 def __init__(self, request):
     self.request = request
     if "geom" in self.request.params:
         geoms = self.request.params["geom"]
         self.valid_request = True
         geom = geojson.loads(
             geoms,
             object_hook=geojson.GeoJSON.to_instance)
         if geom.type not in ["MultiLineString", "LineString"]:
             self.valid_request = False
         Raster.__init__(self, request)
Esempio n. 2
0
    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)
Esempio n. 3
0
    def test_raster(self):
        from decimal import Decimal
        from pyramid.testing import DummyRequest
        from pyramid.httpexceptions import HTTPNotFound
        from c2cgeoportal_geoportal.views.raster import Raster

        request = DummyRequest()
        request.registry.settings = {
            "raster": {
                "dem1": {
                    "file": "/src/geoportal/tests/data/dem.shp",
                    "round": 0.1
                },
                "dem2": {
                    "file": "/src/geoportal/tests/data/dem.shp",
                    "round": 1
                },
                "dem3": {"file": "/src/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("1169.5"))
        self.assertAlmostEqual(result["dem2"], Decimal("1170"))
        self.assertAlmostEqual(result["dem3"], Decimal("1169.51"))

        request.params["layers"] = "dem2"
        result = raster.raster()
        self.assertFalse("dem1" in result)
        self.assertFalse("dem3" in result)
        self.assertAlmostEqual(result["dem2"], Decimal("1170"))

        # test wrong layer name
        request.params["layers"] = "wrong"
        self.assertRaises(HTTPNotFound, raster.raster)
Esempio n. 4
0
    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"))
Esempio n. 5
0
    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)
Esempio n. 6
0
 def __init__(self, request):
     Raster.__init__(self, request)
Esempio n. 7
0
 def __init__(self, request: pyramid.request.Request):
     Raster.__init__(self, request)
Esempio n. 8
0
 def __init__(self, request):
     self.request = request
     Raster.__init__(self, request)
Esempio n. 9
0
 def __init__(self, request):
     self.request = request
     Raster.__init__(self, request)
Esempio n. 10
0
    def test_round_bigvalue(self):
        from decimal import Decimal

        from c2cgeoportal_geoportal.views.raster import Raster

        assert Raster._round(-5.4775915e29, 1) == Decimal("-5.4775915E+29")