是否可以在Folium中绘制路径? [英] Is it possible to draw paths in Folium?
本文介绍了是否可以在Folium中绘制路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了许多与此相关的文档,但是找不到我想要的东西。
我想绘制两点之间的步行路径。可能吗?如果没有,那么python中是否还有其他用于此目的的库?
解决方案
当然可以。使用
编辑1
要在两点之间绘制步行路径,可以结合使用
编辑2
对于叶子类型的地图,您可以使用
I read many documentations related to this, but can't find something what I am looking for.
I want to plot walking paths between two points. Is it possible? if not, is there any other library in python for this purpose ?
解决方案
Of course, you can. Use 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
and you get:
EDIT 1
In order to draw a walking path between two points, you can use a combination of OSMnx
and 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')
and you get:
EDIT 2
For a folium-type map you can use 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')
and you get a useful html file:
这篇关于是否可以在Folium中绘制路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文