如何在地图上可视化获取回复

时间:2019-08-29 09:34:04

标签: python json postman geojson

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

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" }

1 个答案:

答案 0 :(得分:0)

尝试一下:

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>