-1

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

如果没有,是否有建议的解决方法?我看到了如何将 Google KML 导入到一个 tileset中,但是导入的路线没有捕捉到 Mapbox 道路。

谢谢

4

1 回答 1

0

可以使用Mapbox 的 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)
于 2021-01-31T20:48:28.670 回答