python - 如何在 map 上可视化得到的响应

标签 python json postman geojson

大家早上好,我是这个世界的新人,所以如果这是一个天真的问题,请原谅我。 我正在使用 OSRM api 服务来获取一些 GPS 轨迹的 map 匹配。我已经通过 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 中打开它时遇到问题。 所以问题是:如何在 map 中可视化这些类型的结果? 结果代码是这样的:

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

最佳答案

试试这个:

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>

关于python - 如何在 map 上可视化得到的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57707229/

相关文章:

python - 从字典创建 pandas 数据框

python - 在 Python 3 中输入 int 列表

python - 对称频谱的 iFFT

json - Postman - 如何从 JSON 响应中获取最后一次出现的所需属性的值

python - numpy,其中 RGB channel 大于 [0,0,0]

php - 如何在数组中产生行空间

php - Golang 常量结构键

c# - 给出 json 作为响应,但不知道如何解析它

postman - 如何在postman/newman中传递字符串环境变量

javascript - 在 POST 方法中使用 Postman 发送正文 JSON 以在 ms sql server 中执行过程