【问题标题】:How to visualize on map a get response如何在地图上可视化获取响应
【发布时间】:2020-01-02 13:21:16
【问题描述】:

大家早上好,我是这个世界的新手,如果这是一个幼稚的问题,请原谅我。 我正在使用 OSRM api 服务来获取一些 GPS 轨迹的地图匹配。我已经通过 Postman 完成了这个获取请求:

http://router.project-osrm.org/match/v1/driving/9.2254166,45.4774997;9.2254372,45.4775121;9.2254452,45.477521;9.2254506,45.4775307;9.2254591,45.477548;9.2254738,45.477559;9.2254909,45.4775711;9.2254943,45.4775796;9.2255169,45.4775856;9.2255374,45.4775928?overview=full&geometries=geojson

输出响应应该是 Geojson 格式,但我在 qgis 中打开它时遇到问题。 那么问题来了:我如何在地图中可视化这些类型的结果? 结果代码是这样的:

{
"matchings": [
    {
        "confidence": 0,
        "geometry": {
            "coordinates": [
                [
                    9.225701,
                    45.477585
                ],
                [
                    9.225701,
                    45.477592
                ]
            ],
            "type": "LineString"
        },
        "legs": [
            {
                "summary": "",
                "weight": 0.1,
                "duration": 0.1,
                "steps": [],
                "distance": 0.8
            }
        ],
        "weight_name": "routability",
        "weight": 0.1,
        "duration": 0.1,
        "distance": 0.8
    }
],
"tracepoints": [
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    {
        "alternatives_count": 1,
        "waypoint_index": 0,
        "matchings_index": 0,
        "hint": "RZoigAmaIgAiAAAAEAAAAEwAAAATAAAA3yinQZJ9HEEuMTpCgLs6QSIAAAAQAAAATAAAABMAAAB8pgAA5cWMANHutQItxYwA0u61AgMADwC15fcK",
        "distance": 14.388305747573964,
        "name": "Piazza Leonardo da Vinci",
        "location": [
            9.225701,
            45.477585
        ]
    },
    {
        "alternatives_count": 1,
        "waypoint_index": 1,
        "matchings_index": 0,
        "hint": "RZoigAmaIgAjAAAADwAAAEwAAAATAAAAI2KtQRELEEEuMTpCgLs6QSMAAAAPAAAATAAAABMAAAB8pgAA5cWMANjutQJBxYwA2e61AgMADwC15fcK",
        "distance": 12.824458473911934,
        "name": "Piazza Leonardo da Vinci",
        "location": [
            9.225701,
            45.477592
        ]
    }
],
"code": "Ok" }

【问题讨论】:

    标签: python json postman geojson


    【解决方案1】:

    试试这个:

    data = {
    "matchings": [
        {
            "confidence": 0,
            "geometry": {
                "coordinates": [
                    [
                        9.225701,
                        45.477585
                    ],
                    [
                        9.225701,
                        45.477592
                    ]
                ],
                "type": "LineString"
            },
            "legs": [
                {
                    "summary": "",
                    "weight": 0.1,
                    "duration": 0.1,
                    "steps": [],
                    "distance": 0.8
                }
            ],
            "weight_name": "routability",
            "weight": 0.1,
            "duration": 0.1,
            "distance": 0.8
        }
    ],
    "tracepoints": [
        "null",
        "null",
        "null",
        "null",
        "null",
        "null",
        "null",
        "null",
        {
            "alternatives_count": 1,
            "waypoint_index": 0,
            "matchings_index": 0,
            "hint": "RZoigAmaIgAiAAAAEAAAAEwAAAATAAAA3yinQZJ9HEEuMTpCgLs6QSIAAAAQAAAATAAAABMAAAB8pgAA5cWMANHutQItxYwA0u61AgMADwC15fcK",
            "distance": 14.388305747573964,
            "name": "Piazza Leonardo da Vinci",
            "location": [
                9.225701,
                45.477585
            ]
        },
        {
            "alternatives_count": 1,
            "waypoint_index": 1,
            "matchings_index": 0,
            "hint": "RZoigAmaIgAjAAAADwAAAEwAAAATAAAAI2KtQRELEEEuMTpCgLs6QSMAAAAPAAAATAAAABMAAAB8pgAA5cWMANjutQJBxYwA2e61AgMADwC15fcK",
            "distance": 12.824458473911934,
            "name": "Piazza Leonardo da Vinci",
            "location": [
                9.225701,
                45.477592
            ]
        }
    ],
    "code": "Ok" }
    
    def myfunc_map(a, b, c):
      return a + b +c
    
    x = map(myfunc_map, data["matchings"], data["tracepoints"], data["code"])
    

    结果:

    <map object at 0x0000000004276A20>
    

    【讨论】:

    • 啊,你想可视化地图的图像,那我不知道男人:S
    猜你喜欢
    • 2019-10-19
    • 2013-07-06
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多