微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在数据集编辑器中绘制行驶路线

如何解决在数据集编辑器中绘制行驶路线

是否有一种简单的方法可以在 MapBox Studio 数据集编辑器中绘制(或通过航点定义)与道路中心线对齐的驾驶路线,就像在 Google 地图 (image) 中可以完成的那样?我知道如何绘制点、线和多边形,但没有选择驾驶(或步行/骑自行车)路线。

如果没有,是否有建议的解决方法?我看到 how to import Google KML into a tileset,但导入的路线没有捕捉到 MapBox 道路。

谢谢

解决方法

可以使用 Mapbox's Directions API Playground 获得可导航的路线。将响应保存到文件中,例如 navigation_route.geojson,以在下面的 Python 代码片段中使用。

然后可以使用下面的代码段从响应中提取多段线,将提取的多段线保存到一个类似命名的文件中(例如,下面的 navigation_route_parsed.geojson)。该文件可以作为数据集上传到 Mapbox Studio,然后作为图层导入 Mapbox Studio 中的地图,最终创建具有多个可导航路线的地图。

import json

input_file_name_prefix = 'navigation_route'
input_file_name = input_file_name_prefix + '.geojson'
output_file_name = input_file_name_prefix + '_parsed.geojson'

data = {}
with open(input_file_name) as json_file:
    data = json.load(json_file)
   
features = data["routes"][0]

coordinates = []

for leg in features["legs"]:
    for step in leg["steps"]:
        coordinates += step["geometry"]["coordinates"]

feature_collection = {
    "type": "FeatureCollection","features": [
        {
            "type": "Feature","geometry": {
                "type": "LineString","coordinates": coordinates
            }
        }
    ]
}

with open(output_file_name,'w') as outfile:
    json.dump(feature_collection,outfile,indent=2)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?