当前位置: 首页>>代码示例>>Python>>正文


Python DummyRequest.params["geom"]方法代码示例

本文整理汇总了Python中pyramid.testing.DummyRequest.params["geom"]方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.params["geom"]方法的具体用法?Python DummyRequest.params["geom"]怎么用?Python DummyRequest.params["geom"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.testing.DummyRequest的用法示例。


在下文中一共展示了DummyRequest.params["geom"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_profile_csv

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import params["geom"] [as 别名]
    def test_profile_csv(self):
        from pyramid.testing import DummyRequest
        from c2cgeoportal.views.profile import Profile

        request = DummyRequest()
        request.registry.settings = {
            "raster": {
                "dem": {"file": "c2cgeoportal/tests/data/dem.shp", "round": 1},
                "dem2": {"file": "c2cgeoportal/tests/data/dem.shp", "round": 1}
            }
        }
        profile = Profile(request)

        request.params["nbPoints"] = "3"
        request.params["geom"] = '{"type":"LineString",' \
            '"coordinates":[[548009.5,215990],[547990,216009.5]]}'
        response = profile.csv()
        self.assertEqual(response.body, """distance,dem2,dem,x,y
0.0,1166,1166,548009,215990
9.2,1181,1181,548003,215996
18.4,1181,1181,547996,216003""")

        request.params["layers"] = "dem"
        response = profile.csv()
        self.assertEqual(response.body, """distance,dem,x,y
0.0,1166,548009,215990
9.2,1181,548003,215996
18.4,1181,547996,216003""")
开发者ID:eleu,项目名称:c2cgeoportal,代码行数:30,代码来源:test_raster.py

示例2: test_profile_json

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import params["geom"] [as 别名]
    def test_profile_json(self):
        from decimal import Decimal
        from pyramid.testing import DummyRequest
        from pyramid.httpexceptions import HTTPNotFound
        from c2cgeoportal.views.profile import Profile

        request = DummyRequest()
        request.registry.settings = {
            "raster": {
                "dem": {"file": "c2cgeoportal/tests/data/dem.shp", "round": 4},
                "dem2": {"file": "c2cgeoportal/tests/data/dem.shp", "round": 4}
            }
        }
        profile = Profile(request)

        request.params["nbPoints"] = "3"
        request.params["geom"] = '{"type":"LineString",' \
            '"coordinates":[[548009.5,215990],[547990,216009.5]]}'
        result = profile.json()
        self.assertEqual(len(result["profile"]), 3)
        self.assertAlmostEqual(result["profile"][0]["y"], 215990)
        self.assertAlmostEqual(result["profile"][0]["values"]["dem2"], 1166)
        self.assertAlmostEqual(result["profile"][0]["values"]["dem"], 1166)
        self.assertAlmostEqual(result["profile"][0]["dist"], Decimal("0.0"))
        self.assertAlmostEqual(result["profile"][0]["x"], 548009.5)
        self.assertAlmostEqual(result["profile"][1]["y"], 215996.5)
        self.assertAlmostEqual(result["profile"][1]["values"]["dem2"], 1181)
        self.assertAlmostEqual(result["profile"][1]["values"]["dem"], 1181)
        self.assertAlmostEqual(result["profile"][1]["dist"], Decimal("9.2"))
        self.assertAlmostEqual(result["profile"][1]["x"], 548003.0)
        self.assertAlmostEqual(result["profile"][2]["y"], 216003.0)
        self.assertAlmostEqual(result["profile"][2]["values"]["dem"], 1181)
        self.assertAlmostEqual(result["profile"][2]["values"]["dem2"], 1181)
        self.assertAlmostEqual(result["profile"][2]["dist"], Decimal("18.4"))
        self.assertAlmostEqual(result["profile"][2]["x"], 547996.5)

        request.params["layers"] = "dem"
        result = profile.json()
        self.assertEqual(len(result["profile"]), 3)
        self.assertAlmostEqual(result["profile"][0]["y"], 215990)
        self.assertAlmostEqual(result["profile"][0]["values"]["dem"], 1166)
        self.assertAlmostEqual(result["profile"][0]["dist"], Decimal("0.0"))
        self.assertAlmostEqual(result["profile"][0]["x"], 548009.5)
        self.assertAlmostEqual(result["profile"][1]["y"], 215996.5)
        self.assertAlmostEqual(result["profile"][1]["values"]["dem"], 1181)
        self.assertAlmostEqual(result["profile"][1]["dist"], Decimal("9.2"))
        self.assertAlmostEqual(result["profile"][1]["x"], 548003.0)
        self.assertAlmostEqual(result["profile"][2]["y"], 216003.0)
        self.assertAlmostEqual(result["profile"][2]["values"]["dem"], 1181)
        self.assertAlmostEqual(result["profile"][2]["dist"], Decimal("18.4"))
        self.assertAlmostEqual(result["profile"][2]["x"], 547996.5)

        # test length = 0
        request.params["geom"] = '{"type":"LineString",' \
            '"coordinates":[[548000,216000]]}'
        result = profile.json()
        self.assertEqual(len(result["profile"]), 1)
        self.assertAlmostEqual(result["profile"][0]["y"], 216000)
        self.assertAlmostEqual(result["profile"][0]["values"]["dem"], 1169)
        self.assertAlmostEqual(result["profile"][0]["dist"], Decimal("0.0"))
        self.assertAlmostEqual(result["profile"][0]["x"], 548000)

        # test cur_nb_points < 1
        request.params["geom"] = '{"type":"LineString",' \
            '"coordinates":[[548000,216000],[548001,216001],[548009,216009]]}'
        result = profile.json()
        self.assertEqual(len(result["profile"]), 3)
        self.assertAlmostEqual(result["profile"][0]["y"], 216000)
        self.assertAlmostEqual(result["profile"][0]["values"]["dem"], 1169)
        self.assertAlmostEqual(result["profile"][0]["dist"], Decimal("0.0"))
        self.assertAlmostEqual(result["profile"][0]["x"], 548000)
        self.assertAlmostEqual(result["profile"][1]["y"], 216003.66666666666)
        self.assertAlmostEqual(result["profile"][1]["values"]["dem"], 1155)
        self.assertAlmostEqual(result["profile"][1]["dist"], Decimal("5.2"))
        self.assertEqual(result["profile"][1]["x"], 548003.66666666663)
        self.assertAlmostEqual(result["profile"][2]["y"], 216006.33333333334)
        self.assertAlmostEqual(result["profile"][2]["values"]["dem"], 1154)
        self.assertAlmostEqual(result["profile"][2]["dist"], Decimal("9.0"))
        self.assertAlmostEqual(result["profile"][2]["x"], 548006.33333333337)

        # test wrong layer name
        request.params["layers"] = "wrong"
        self.assertRaises(HTTPNotFound, profile.json)
开发者ID:eleu,项目名称:c2cgeoportal,代码行数:85,代码来源:test_raster.py


注:本文中的pyramid.testing.DummyRequest.params["geom"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。