如何解决在数据集编辑器中绘制行驶路线
是否有一种简单的方法可以在 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 举报,一经查实,本站将立刻删除。