Python folium.PolyLine() Examples
The following are 4
code examples of folium.PolyLine().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
folium
, or try the search function
.
Example #1
Source File: visualization.py From PyMove with MIT License | 6 votes |
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_
Example #2
Source File: visualization.py From PyMove with MIT License | 5 votes |
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)
Example #3
Source File: trajectories.py From PyMove with MIT License | 4 votes |
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
Example #4
Source File: folium.py From osmnx with MIT License | 4 votes |
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