gpt4 book ai didi

python - 是否可以在 Folium 中绘制路径?

转载 作者:行者123 更新时间:2023-12-04 14:37:23 27 4
gpt4 key购买 nike

我阅读了许多与此相关的文档,但找不到我要找的东西。

我想绘制两点之间的步行路径。是否可以?如果没有,python 中是否还有其他库用于此目的?

最佳答案

当然可以。使用 PolyLine :

import folium

m = folium.Map(location=[40.720, -73.993],
zoom_start=15)

loc = [(40.720, -73.993),
(40.721, -73.996)]

folium.PolyLine(loc,
color='red',
weight=15,
opacity=0.8).add_to(m)
m

你会得到:

enter image description here

编辑 1

为了画一个 步行道两点之间,可以使用 OSMnx 的组合和 networkx :

import osmnx as ox
import networkx as nx

ox.config(log_console=True,
use_cache=True)

G_walk = ox.graph_from_place('Manhattan Island, New York City, New York, USA',
network_type='walk')

orig_node = ox.get_nearest_node(G_walk,
(40.748441, -73.985664))

dest_node = ox.get_nearest_node(G_walk,
(40.748441, -73.4))

route = nx.shortest_path(G_walk, orig_node, dest_node, weight='length')

fig, ax = ox.plot_graph_route(G_walk,
route,
node_size=0,
save=True,
file_format='svg',
filename='test')

你会得到:

enter image description here

编辑 2

对于大叶型 map ,您可以使用 plot_route_folium :

import osmnx as ox
import networkx as nx

ox.config(log_console=True, use_cache=True)

G_walk = ox.graph_from_place('Manhattan Island, New York City, New York, USA',
network_type='walk')

orig_node = ox.get_nearest_node(G_walk,
(40.748441, -73.985664))

dest_node = ox.get_nearest_node(G_walk,
(40.748441, -73.4))

route = nx.shortest_path(G_walk,
orig_node,
dest_node,
weight='length')

route_map = ox.plot_route_folium(G_walk, route)

route_map.save('route.html')

你会得到一个有用的 html 文件:

enter image description here

关于python - 是否可以在 Folium 中绘制路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60578408/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com