def get_map_list_after_segmentation(section_map, outlier_algo = None, filter_algo = None): mapList = [] for trip, section_list in section_map: logging.debug("%s %s -> %s %s" % ("=" * 20, trip.start_time, trip.end_time, "=" * 20)) trip_df = lq.get_points_for_section(trip) curr_map = folium.Map([trip_df.mLatitude.mean(), trip_df.mLongitude.mean()]) last_section_end = None for (i, section) in enumerate(section_list): logging.debug("%s %s: %s -> %s %s" % ("-" * 20, i, section.start_time, section.end_time, "-" * 20)) raw_section_df = trip_df[np.logical_and(trip_df.mTime >= section.start_ts, trip_df.mTime <= section.end_ts)] section_df = ls.filter_points(raw_section_df, outlier_algo, filter_algo) if section_df.shape[0] == 0: logging.info("Found empty df! skipping...") continue logging.debug("for section %s, section_df.shape = %s, formatted_time.head() = %s" % (section, section_df.shape, section_df["formatted_time"].head())) update_map(curr_map, section_df, line_color = sel_color_list[section.activity.value], popup = "%s" % (section.activity)) if section_df.shape[0] > 0: curr_section_start = section_df.iloc[0] if i != 0 and last_section_end is not None: # We want to join this to the previous section. curr_map.line([[last_section_end.mLatitude, last_section_end.mLongitude], [curr_section_start.mLatitude, curr_section_start.mLongitude]], line_color = sel_color_list[-1], popup = "%s -> %s" % (section_list[i-1].activity, section.activity)) last_section_end = section_df.iloc[-1] mapList.append(curr_map) return mapList
def get_maps_for_range_old(user_id, start_ts, end_ts): # First, get the timeline for that range. ts = esta.TimeSeries.get_time_series(user_id) trip_list = esdt.get_trips(user_id, estt.TimeQuery("data.start_ts", start_ts, end_ts)) # TODO: Should the timeline support random access as well? # If it did, we wouldn't need this additional map # I think that it would be good to support a doubly linked list, i.e. prev and next in addition # to the iteration interface place_list = esdp.get_places(user_id, estt.TimeQuery("data.exit_ts", start_ts, end_ts)) place_list = place_list + (esdp.get_places(user_id, estt.TimeQuery("data.enter_ts", start_ts, end_ts))) place_map = dict([(p.get_id(), p) for p in place_list]) map_list = [] flipped_midpoint = lambda p1_p22: [old_div((p1_p22[0].coordinates[1] + p1_p22[1].coordinates[1]),2), old_div((p1_p22[0].coordinates[0] + p1_p22[1].coordinates[0]),2)] for i, trip in enumerate(trip_list): logging.debug("-" * 20 + trip.start_fmt_time + "=>" + trip.end_fmt_time + "(" + str(trip.end_ts - trip.start_ts) + ")") if (len(esdt.get_raw_sections_for_trip(user_id, trip.get_id())) == 0 and len(esdt.get_raw_stops_for_trip(user_id, trip.get_id())) == 0): logging.debug("Skipping trip because it has no stops and no sections") continue start_point = gj.GeoJSON.to_instance(trip.start_loc) end_point = gj.GeoJSON.to_instance(trip.end_loc) curr_map = folium.Map(flipped_midpoint((start_point, end_point))) map_list.append(curr_map) logging.debug("About to display places %s and %s" % (trip.start_place, trip.end_place)) update_place(curr_map, trip.start_place, place_map, marker_color='green') update_place(curr_map, trip.end_place, place_map, marker_color='red') # TODO: Should get_timeline_for_trip work on a trip_id or on a trip object # it seems stupid to convert trip object -> id -> trip object curr_trip_timeline = esdt.get_raw_timeline_for_trip(user_id, trip.get_id()) for i, trip_element in enumerate(curr_trip_timeline): # logging.debug("Examining element %s of type %s" % (trip_element, type(trip_element))) if type(trip_element) == ecws.Stop: time_query = esds.get_time_query_for_stop(trip_element.get_id()) logging.debug("time_query for stop %s = %s" % (trip_element, time_query)) stop_points_df = ts.get_data_df("background/filtered_location", time_query) # logging.debug("stop_points_df.head() = %s" % stop_points_df.head()) if len(stop_points_df) > 0: update_line(curr_map, stop_points_df, line_color = sel_color_list[-1], popup="%s -> %s" % (trip_element.enter_fmt_time, trip_element.exit_fmt_time)) else: assert(type(trip_element) == ecwsc.Section) time_query = esdsc.get_time_query_for_section(trip_element.get_id()) logging.debug("time_query for section %s = %s" % (trip_element, "[%s,%s,%s]" % (time_query.timeType, time_query.startTs, time_query.endTs))) section_points_df = ts.get_data_df("background/filtered_location", time_query) logging.debug("section_points_df.tail() = %s" % section_points_df.tail()) if len(section_points_df) > 0: update_line(curr_map, section_points_df, line_color = sel_color_list[trip_element.sensed_mode.value], popup="%s (%s -> %s)" % (trip_element.sensed_mode, trip_element.start_fmt_time, trip_element.end_fmt_time)) else: logging.warning("found no points for section %s" % trip_element) return map_list
def get_maps_for_geojson_unsectioned(feature_list): map_list = [] for feature in feature_list: # logging.debug("Getting map for feature %s" % bju.dumps(feature)) feature_coords = list(get_coords(feature)) # feature_coords = list(gj.utils.coords(feature)) curr_map = folium.Map(get_center_for_map(feature_coords)) curr_plugin = fgjp.FoliumGeojsonPlugin(dict(feature)) curr_map.add_plugin(curr_plugin) map_list.append(curr_map) return map_list
def draw_stations(all_stations_in_one_line): map = folium.Map(location=[43.25654, 76.92848], zoom_start=12) for j in all_stations_in_one_line: folium.CircleMarker(location=[j.get_lat(), j.get_lng()], radius=9, popup=j.get_name(), fill_color=j.get_color(), color="black", fill_opacity=0.9).add_to(map) return map
def cctv_map(): popup=[] data_lat_log=[] a_path='c:/hj/data/' df=pd.read_csv(os.path.join(a_path,'cctv.csv'),encoding='utf-8') print(df) for data in df.values: #필드빼고 값만 가져온다. if data[4]>0: popup.append(data[1]) data_lat_log.append([data[10],data[11]]) m=folium.Map([35.1803305,129.0516257],zoom_start=11) plugins.MarkerCluster(data_lat_log, popups=popup).add_to(m) m.save(os.path.join(TEMPLATE_DIR, 'map/map01.html'))
def get_maps_for_geojson_list(trip_geojson_list): map_list = [] for trip_doc in trip_geojson_list: # logging.debug(trip_doc) trip_geojson = ad.AttrDict(trip_doc) logging.debug("centering based on start = %s, end = %s " % (trip_geojson.features[0], trip_geojson.features[1])) flipped_midpoint = lambda(p1, p2): [(p1.coordinates[1] + p2.coordinates[1])/2, (p1.coordinates[0] + p2.coordinates[0])/2] curr_map = folium.Map(flipped_midpoint((trip_geojson.features[0].geometry, trip_geojson.features[1].geometry))) curr_plugin = fgjp.FoliumGeojsonPlugin(dict(trip_geojson)) curr_map.add_plugin(curr_plugin) map_list.append(curr_map) return map_list
def map_02_details(): # let's start again with a clean copy of the map of United State san_map = folium.Map(location=[latitude, longitude], zoom_start=4) # instantiate a mark cluster object for the incidents in the dataframe incidents = plugins.MarkerCluster().add_to(san_map) # loop through the dataframe and add each data point to the mark cluster for lat, lng, label, in zip(data.latitude, data.longitude, cdata1.Title): folium.Marker( location=[lat, lng], icon=None, popup=label, ).add_to(incidents) # add incidents to map incident_map2 = san_map.add_child(incidents) display(incident_map2) incident_map2.save('templates/map_02_details.html') return render_template("map_02_details.html")
def map_view(request): """ Main page - map of all the sensors """ gmaps = googlemaps.Client(key='AIzaSyCZO9lx7k1gFhU-Fv9hSZ9PUynZb0EjeBg') sensors = Sensor.objects.all() sensor_map = folium.Map(location=[50.064316, 19.985638], zoom_start=12, tiles='Stamen Terrain') for sensor in sensors: localisation = sensor.localisation sensor_id = sensor.sensor_id coordinates = (gmaps.geocode(localisation))[0]['geometry']['location'] popup = '%s; sensor_id = %i' % (localisation, sensor_id) folium.Marker([coordinates['lat'], coordinates['lng']], popup=popup).add_to(sensor_map) sensor_map.save('templates/map.html') return render_to_response('sensors_map.html')
def map_01_details(): incidents = folium.map.FeatureGroup() # 将每个枪击案件添加到事件特性组 for lat, lng, in zip(cdata1.latitude, data.longitude): incidents.add_child( folium.CircleMarker( [lat, lng], radius=7, # define how big you want the circle markers to be color='yellow', fill=True, fill_color='red', fill_opacity=0.4)) # Add incidents to map san_map = folium.Map(location=[latitude, longitude], zoom_start=4) incidents_map = san_map.add_child(incidents) display(incidents_map) incidents_map.save('templates/map_01_details.html') return render_template("map_01_details.html")
def layer() -> None: """Create map with layer. Creates map with given data, where f.geo_lat and f.get_long are latitude and longitude respectively, avg(f.ppm) is weight for such point on map. """ m = folium.Map(location=[59.93399475, 30.367615217112643]) query = db_query_hm() g = { 0: "black", 0.2: "blue", 0.3: "teal", 0.4: "green", 0.5: "yellow", 0.6: "orange", 0.7: "red", } heatmap = HeatMap(query, radius=25, blur=45, gradient=g) m.add_child(heatmap) m.save("./templates/heatmap.html")
def draw_choropleth_map(dataset): # Draw the choropleth map according to the average price of AV_TOTAL based on zip code m = folium.Map(location=[42.37909, -71.03215], zoom_start=12) bins = list(dataset['average_price'].quantile([0, 0.25, 0.5, 0.75, 1])) print(dataset.info()) dataset = dataset.dropna() folium.Choropleth( geo_data=bzp, data=dataset, columns=['zipcode', 'average_price'], key_on='feature.properties.ZCTA5CE10', # fill_color='red', fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.2, highlight=True, bins = bins, legend_name='Boston Average House Price' ).add_to(m) m.save('choropleth.html')
def get_map_for_geojson_unsectioned(geojson): div_icon = folium.DivIcon() all_div_markers = [folium.CircleMarker(p["geometry"]["coordinates"][::-1], popup=bju.dumps(p["properties"]), radius=5) for p in geojson["features"][0]["features"]] # all_div_markers = [folium.Marker(p["geometry"]["coordinates"][::-1], # popup=json.dumps(p["properties"]), # icon=div_icon) # for p in all_geojson["features"][0]["features"]] print("Points are ", [m.location for m in all_div_markers[:5]], "...") geojson_line_string = geojson["features"][1]["geometry"] polyline_coords = [c[::-1] for c in geojson_line_string["coordinates"]] print("Linestring is", polyline_coords[:5], "...") polyline = folium.PolyLine(polyline_coords) bounds = polyline.get_bounds() m = folium.Map(tiles='Stamen Terrain') m.fit_bounds(bounds) for marker in all_div_markers: marker.add_to(m) polyline.add_to(m) return m
from folium import folium import markers import methods import trasyPlugin mapka = folium.Map(location=[42.77, -7.41], zoom_start=8, control_scale=True) trasyPlugin.trasy_camino2019(mapka) markers.camino_marker(mapka) tooltip = 'RAPORT Camino Santiago de Compostela 2019' methods.marker_raport(mapka, 42.98, -9.36, methods.popup_raport(), tooltip) methods.open_webb_and_save(mapka, 'C:/Users/zs/Downloads/Camino.html')
def generateBaseMap(default_location=[42.37909, -71.03215]): base_map = folium.Map(location=default_location ) return base_map
from folium import folium map = folium.Map(location=[19.0760, 72.8777]) map.save("mylocation.html")
from folium import folium import methods import trasy import markers import private lat = 52.22534 lng = 21.02793 mapka = folium.Map(location=[lat, lng], zoom_start=6, control_scale=True) trasy.trasy_beskidy2016(mapka) trasy.trasy_beskidy2017(mapka) trasy.trasy_beskidy2018(mapka) trasy.trasy_beskidy2019(mapka) trasy.trasy_beskidy2020(mapka) trasy.trasy_tatry2015(mapka) trasy.trasy_tatry2016(mapka) trasy.trasy_tatry2018(mapka) trasy.trasy_tatry2019(mapka) trasy.trasy_tatry2020(mapka) trasy.trasy_sudety2016(mapka) trasy.trasy_sudety2018(mapka) trasy.trasy_sudety2019(mapka) trasy.trasy_slovakia2016(mapka) trasy.trasy_slovakia2017(mapka) trasy.trasy_slovakia2018(mapka)
which_result=2) #返回结果为graph 对象 street_gdfs = ox.save_load.graph_to_gdfs( street_graph, nodes=False, edges=True, node_geometry=True, fill_edge_geometry=True) #将graph_转化为_gdf 对象 ox.save_load.save_graph_shapefile(street_graph, filename='Baoji_jintai', folder=None, encoding='utf-8') #保存graph 对象为shape文件 ox.save_gdf_shapefile(street_gdfs, 'Baoji_jintai', r'./data/') # 保存gdf类型的对象 ox.plot_graph(street_graph) #graph 对象绘图 foliumHtml = ox.plot.plot_graph_folium(street_graph, graph_map=None, popup_attribute=None, tiles='cartodbpositron', zoom=1, fit_bounds=True, edge_color='#333333', edge_width=5, edge_opacity=1) foliumHtml.save('./Features_0.html') #保存为网页 print('ppp') map_osm = folium.Map(location=[45.5236, -122.6750]) #此处 map_osm.create_map() 方法 貌似失效了 替换为 map_osm.save() 方法可用 map_osm.save('./Features_0.html') #address_rect city
def get_map(section_points, line_color=None, popup=None): currMap = folium.Map( [section_points.mLatitude.mean(), section_points.mLongitude.mean()]) update_map(currMap, section_points, line_color, popup) return currMap
from folium import folium import methods import trasyPlugin import markers mapka = folium.Map(location=[46.47, 11.77], zoom_start=11, control_scale=True) trasyPlugin.trasy_camino2016(mapka) markers.dolomity_marker(mapka) tooltip = 'RAPORT z wszystkich tras w Alpach (Dolomity)' methods.marker_raport(mapka, 46.47, 11.77, methods.popup_raport(), tooltip) methods.open_webb_and_save(mapka, 'C:/Users/zs/Downloads/Dolomity.html')
def cluster(locationdata): print "generating a clustered map" map_osm.add_children(plugins.MarkerCluster(locationdata)) if __name__ == "__main__": input_files = [] for filename in args.filename: input_files.append(filename.name) parsedlocations, frequentLocation = parser(input_files, args.accuracy) if args.heatmap: map_osm = folium.Map( location=[frequentLocation[0], frequentLocation[1]]) heatmap(parsedlocations) if args.night: map_osm.add_children(plugins.Terminator()) map_osm.save('./heat_map.html') map_osm._repr_html_() if args.cluster: map_osm = folium.Map( location=[frequentLocation[0], frequentLocation[1]]) cluster(parsedlocations) if args.night: map_osm.add_children(plugins.Terminator()) map_osm.save('./cluster_map.html') map_osm._repr_html_()
# -*- coding: utf-8 -*- import os import pandas as pd from folium import folium from pandas import compat from folium.plugins import MarkerCluster os.chdir('../VKHCG/01-Vermeulen/00-RawData') compat.PY3 = True universities = pd.read_csv("uk_universities_locations2.csv") uk = folium.Map( location=[universities.lat.mean(axis=0), universities.lon.mean(axis=0)], zoom_start=5) marker_cluster = MarkerCluster("Universities").add_to(uk) #add a marker for each university for each in universities.iterrows(): folium.Marker(list([each[1]['lat'], each[1]['lon']]), popup=each[1]['Name']).add_to(marker_cluster) uk.save("./universities.html")