本文整理汇总了Python中folium.PolyLine方法的典型用法代码示例。如果您正苦于以下问题:Python folium.PolyLine方法的具体用法?Python folium.PolyLine怎么用?Python folium.PolyLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类folium
的用法示例。
在下文中一共展示了folium.PolyLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_trajectories_to_folium_map
# 需要导入模块: import folium [as 别名]
# 或者: from folium import PolyLine [as 别名]
def _add_trajectories_to_folium_map(
move_data,
items,
base_map,
legend=True,
save_as_html=True,
filename='map.html',
):
"""
Adds a trajectory to a folium map with begin and end markers.
Parameters
----------
move_data : pymove.core.MoveDataFrameAbstract subclass.
Input trajectory data.
legend: boolean, default True
Whether to add a legend to the map
base_map : folium.folium.Map, optional, default None.
Represents the folium map. If not informed, a new map is generated.
save_as_html : bool, optional, default False.
Represents if want save this visualization in a new file .html.
filename : String, optional, default 'plot_trajectory_by_period.html'.
Represents the file name of new file .html.
"""
for _id, color in items:
mv = move_data[move_data[TRAJ_ID] == _id]
_add_begin_end_markers_to_folium_map(move_data, base_map)
folium.PolyLine(
mv[[LATITUDE, LONGITUDE]], color=color, weight=2.5, opacity=1
).add_to(base_map)
if legend:
add_map_legend(base_map, 'Color by user ID', items)
if save_as_html:
base_map.save(outfile=filename)
示例2: save_bbox
# 需要导入模块: import folium [as 别名]
# 或者: from folium import PolyLine [as 别名]
def save_bbox(
bbox_tuple, file='bbox.html', tiles=TILES[0], color='red', return_map=False
):
"""
Save bbox as file .html using Folium.
Parameters
----------
bbox_tuple : tuple.
Represents a bound box, that is a tuple of 4 values with the
min and max limits of latitude e longitude.
file : String, optional, default 'bbox.html'.
Represents filename.
tiles : String, optional, default 'OpenStreetMap'.
Represents tyles'srs type_.
Example: 'openstreetmap', 'cartodbpositron',
'stamentoner', 'stamenterrain',
'mapquestopen', 'MapQuest Open Aerial',
'Mapbox Control Room' and 'Mapbox Bright'.
color : String, optional, default 'red'.
Represents color of lines on map.
return_map: Boolean, optional, default False.
Wether to return the bbox folium map.
Examples
--------
>>> from pymove.trajectories import save_bbox
>>> bbox = (22.147577, 113.54884299999999, 41.132062, 121.156224)
>>> save_bbox(bbox, 'bbox.html')
"""
m = folium.Map(tiles=tiles)
m.fit_bounds(
[[bbox_tuple[0], bbox_tuple[1]], [bbox_tuple[2], bbox_tuple[3]]]
)
points_ = [
(bbox_tuple[0], bbox_tuple[1]),
(bbox_tuple[0], bbox_tuple[3]),
(bbox_tuple[2], bbox_tuple[3]),
(bbox_tuple[2], bbox_tuple[1]),
(bbox_tuple[0], bbox_tuple[1]),
]
folium.PolyLine(points_, weight=3, color=color).add_to(m)
m.save(file)
if return_map:
return m
示例3: save_map
# 需要导入模块: import folium [as 别名]
# 或者: from folium import PolyLine [as 别名]
def save_map(
move_data, filename, tiles=TILES[0], label_id=TRAJ_ID, cmap='tab20', return_map=False
):
"""
Save a visualization in a map in a new file.
Parameters
----------
move_data : pymove.core.MoveDataFrameAbstract subclass.
Input trajectory data.
filename : String
Represents the filename.
tiles : String
Represents the type_ of tile that will be used on the map.
label_id : String
Represents column name of trajectory id.
cmap: String
Represents the Colormap.
"""
map_ = folium.Map(tiles=tiles)
map_.fit_bounds(
[
[move_data[LATITUDE].min(), move_data[LONGITUDE].min()],
[move_data[LATITUDE].max(), move_data[LONGITUDE].max()],
]
)
ids = move_data[label_id].unique()
cmap_ = plt.cm.get_cmap(cmap)
num = cmap_.N
for id_ in ids:
id_index = np.where(ids == id_)[0][0]
move_df = move_data[move_data[label_id] == id_]
points_ = [
(point[0], point[1])
for point in move_df[[LATITUDE, LONGITUDE]].values
]
color_ = cmap_hex_color(cmap_, (id_index % num))
folium.PolyLine(points_, weight=3, color=color_).add_to(map_)
map_.save(filename)
if return_map:
return map_
示例4: _make_folium_polyline
# 需要导入模块: import folium [as 别名]
# 或者: from folium import PolyLine [as 别名]
def _make_folium_polyline(
edge, edge_color, edge_width, edge_opacity, popup_attribute=None, **kwargs
):
"""
Turn row GeoDataFrame into a folium PolyLine with attributes.
Parameters
----------
edge : GeoSeries
a row from the gdf_edges GeoDataFrame
edge_color : string
color of the edge lines
edge_width : numeric
width of the edge lines
edge_opacity : numeric
opacity of the edge lines
popup_attribute : string
edge attribute to display in a pop-up when an edge is clicked, if
None, no popup
kwargs : dict
Extra parameters passed through to folium
Returns
-------
pl : folium.PolyLine
"""
# check if we were able to import folium successfully
if not folium:
raise ImportError("The folium package must be installed to use this optional feature.")
# locations is a list of points for the polyline
# folium takes coords in lat,lon but geopandas provides them in lon,lat
# so we have to flip them around
locations = list([(lat, lng) for lng, lat in edge["geometry"].coords])
# if popup_attribute is None, then create no pop-up
if popup_attribute is None:
popup = None
else:
# folium doesn't interpret html in the html argument (weird), so can't
# do newlines without an iframe
popup_text = json.dumps(edge[popup_attribute])
popup = folium.Popup(html=popup_text)
# create a folium polyline with attributes
pl = folium.PolyLine(
locations=locations,
popup=popup,
color=edge_color,
weight=edge_width,
opacity=edge_opacity,
**kwargs,
)
return pl