def uploaded(): global file_out_name if request.method == 'POST': uploaded = request.files.to_dict() file_in = uploaded['uploaded_file'] file_in_name = secure_filename('uploaded_{}_{}'.format(datetime.now().strftime('%Y%m%d%H%M%S'), file_in.filename)) file_in.save(file_in_name) if file_in.filename[-3:] == 'csv': df = pd.read_csv(file_in_name) if file_in.filename[-4:] == 'xlsx': df = pd.read_excel(file_in_name, sheet_name = 0) if 'Unnamed: 0' in df.columns: df = df.drop('Unnamed: 0', 1) df['_ID'] = list(range(1, len(df)+1)) df.set_index('_ID', inplace = True) if any(c.lower() in ['address', 'add', 'addresses'] for c in df.columns): file_out_name = 'geocoded_{}'.format(file_in_name) for c in df.columns: if c.lower() in ['address', 'add', 'addresses']: df['longitude'] = [ArcGIS().geocode(i, timeout = 1000).longitude for i in df[c]] df['latitude'] = [ArcGIS().geocode(i, timeout = 1000).latitude for i in df[c]] if file_in.filename[-3:] == 'csv': df.to_csv(file_out_name) if file_in.filename[-4:] == 'xlsx': df.to_excel(file_out_name) df['map'] = ['show map'] * len(df) df_html_0 = df.to_html().replace('NaN', '').replace("<th>_ID</th>", "<th></th>").replace("dataframe", "results_table") df_html_dict = {} df_html_dict[0] = df_html_0 for i in range(1, len(df)+1): map = folium.Map(location = [df.latitude[i], df.longitude[i]], zoom_start = 6, tiles = 'Stamen Terrain') map.add_child(folium.Marker(location = [df.latitude[i], df.longitude[i]], popup = folium.Popup(df[c][i], parse_html = True), icon = folium.Icon(color = 'blue'))) map.save('./templates/map{}.html'.format(i)) map_html = open('./templates/map{}.html'.format(i), 'r+') map_html.seek(101) map_html.write("""<link rel="icon" href="./static/assets/favicon.ico"><script>\n""") map_url = 'lat={}&lng={}.html'.format(df.latitude[i], df.longitude[i]) mapurl_dict[map_url] = 'map{}.html'.format(i) df_html_dict[i] = df_html_dict[i-1].replace('<td>show map</td>', "<td><a target='_blank' href='/{}'>show map</a></td>".format(map_url), 1) map2 = folium.Map(location = [df.latitude[1], df.longitude[1]], zoom_start = 4, tiles = 'Stamen Terrain') fg = folium.FeatureGroup(name = 'all_add') for i in range(1, len(df)+1): fg.add_child(folium.Marker(location = [df.latitude[i], df.longitude[i]], popup = folium.Popup(df[c][i], parse_html = True), icon = folium.Icon(color = 'blue'))) map2.add_child(fg) map2.save('./templates/all_map.html') map2_html = open('./templates/all_map.html', 'r+') map2_html.seek(101) map2_html.write("""<link rel="icon" href="./static/assets/favicon.ico"><script>\n""") map2_url = 'all=True&filename={}'.format(file_out_name) mapurl_dict[map2_url] = 'all_map.html' return render_template('valid.html', filename = file_out_name, table = df_html_dict[len(df)], all_in_map = '/{}'.format(map2_url)) else: return render_template('invalidupload.html') else: return 'Something went wrong. Please try again!'
import folium import pandas data = pandas.read_csv('metroson.csv', encoding="utf-8") LAT = list(data['LAT']) LON = list(data['LON']) name = list(data['NAME']) picture = list(data['picture']) fg = folium.FeatureGroup('my map') fg.add_child( folium.GeoJson(data=(open('m1-m2.json', 'r', encoding='utf-8').read()))) for lt, ln, nm, pic in zip(LAT, LON, name, picture): fg.add_child( folium.Marker(location=[lt, ln], popup="<b>Station Name: </b>" + nm + "<br> <img src=" + pic + " height=250 width=400>", icon=folium.Icon(color='red'))) #height=142 width=290 map = folium.Map(location=[39.93495537428379, 32.74075984954834], zoom_start=11) map.add_child(fg) map.save('Gülsüm&Gizem.html')
import pandas import folium map = folium.Map( location=[39.11, -98.08], zoom_start=3, tiles="Stamen Terrain") #this creates the base layer for the map fg = folium.FeatureGroup( Name='My Map' ) #this is a way to keep your code organized because you can keep loading in features into a feature group. #this is a base layer ######BEGINNING OF THE SECOND LAYER OF THE MAP -- THE VOLCANO MARKERS fgv = folium.FeatureGroup(Name="Volcanos") #Creating a new feature group layer volcanos = pandas.read_csv( "course/section17map/volcanos.csv") #reading data on the USA volcanos lat = list( volcanos["LAT"] ) #just taking the data from the LAT column and putting it into a native python list for use in a for loop lon = list(volcanos["LON"]) elev = list(volcanos["ELEV"]) nam = list(volcanos["NAME"]) voltype = list(volcanos["TYPE"]) status = list(volcanos["STATUS"]) ####Style points here html = """ Volcano name:<a href="https://www.google.com/search?q=%%22%s%%22" target="_blank">%s</a><br> Height: %s m """ #need to reveiw html code #<br> is a break
lon = list(data["LON"]) rtg = list(data["RATING"]) def color_producer(rating): if rating == 7: return 'red' else: return 'orange' map = folium.Map(location=[17.403434, 78.452859], zoom_start=5, tiles="Mapbox Bright") fgh = folium.FeatureGroup(name="Hotels") for nm, lt, ln, rt in zip(name, lat, lon, rtg): fgh.add_child( folium.CircleMarker(location=[lt, ln], radius=6, popup=nm + " " + str(rt) + "star", fill_color=color_producer(rt), fill=True, color='grey', fill_opacity=0.7)) fgp = folium.FeatureGroup(name="Population") fgp.add_child( folium.GeoJson(
import folium import pandas as pd data = pd.read_csv("Volcanoes.csv") lat = list(data["LAT"]) lon = list(data["LON"]) elev = list(data["ELEV"]) html = """<h4>Volcano information:</h4> Height: %s m """ map = folium.Map(location=[38.58, -99.09], zoom_start=6, tiles="Mapbox Bright") fg = folium.FeatureGroup(name="My Map") #for lt,ln,el in zip(lat, lon, elev) : # fg.add_child(folium.Marker(location=[lt, ln], popup=str(el)+"m", icon=folium.Icon(color='red'))) for lt, ln, el in zip(lat, lon, elev): iframe = folium.IFrame(html=html % str(el), width=200, height=100) fg.add_child( folium.Marker(location=[lt, ln], popup=folium.Popup(iframe), icon=folium.Icon(color="green"))) map.add_child(fg) map.save("Map_html_popup_simple.html")
import pandas import folium data = pandas.read_json('coordinates.json') lat = data['DD']['lat'] log = data['DD']['lng'] dataCollections = data["DD"]['popup'] testmap = folium.Map(location=[3.1465, 101.6923], zoom_start=10, title='Stamen Terrain') record = folium.FeatureGroup(name='COVID') # looping through every cordinate and popup message in the JSON file for lt, lg, dc in zip(lat, log, dataCollections): record.add_child(folium.Marker(location=[lt, lg], popup=dc)) Border = folium.FeatureGroup(name="Populations") # GeoJson for border of the malaysia data = open('package.json', 'r', encoding='utf-8-sig').read() Border.add_child( folium.GeoJson(data, style_function=lambda x: { 'fillColor': '#00ff00' if x['properties']['ISO3'] == 'MYS' else '#000000' })) testmap.add_child(record)
# Spatial Distribution of Supermarkets within the United Kingdom # Using the attribute and spatial data of each Supermarket import folium import os import pandas as pd from folium import plugins # Creating Feature Grouping for each Feature Layer fg1 = folium.FeatureGroup(name='0.5km Radius') fg2 = folium.FeatureGroup(name='Nodes') fg3 = folium.FeatureGroup(name='Customer Access Point') fg4 = folium.FeatureGroup(name='Customer Entrance') # Creating the Map Location and Zoom Level m = folium.Map(location=[55.171, -2.82], zoom_start=8, control_scale=True) # Connecting the File Directory and Assigning them to their Variables store = os.path.join('data', 'supermarket.csv') node = os.path.join('data', 'new_new_node2.csv') Customer_Entrance = os.path.join('data', 'customer_entrance.csv') Customer_Access_Point = os.path.join('data', 'customer_access_point.csv') # Reading through the CSV file for each Feature Layer df_st = pd.read_csv(store, usecols=['LONG', 'LAT']) df_no = pd.read_csv(node, usecols=['id', 'LONG', 'LAT'], dtype={ 'id': 'int32', 'LONG': 'float16', 'LAT': 'float16'
import folium import pandas lat = [39.95, 27.04, 18.52, 37.77, 24] lon = [-86.13, 88.26, 73.86, -122.42, 90] purpose = [ 'Exchange Program, 2014', 'Boarding School, 2007', 'Summer School, 2016', 'College, 2017', 'Born' ] map = folium.Map(location=[24, 90], zoom_start=6, tiles="Mapbox Bright") fg = folium.FeatureGroup(name="My Map") for lt, ln, purp in zip(lat, lon, purpose): fg.add_child( folium.Marker(location=(lt, ln), popup=str(purp), icon=folium.Icon(color='lightgray'))) fgp = folium.FeatureGroup(name='Population') fgp.add_child( folium.GeoJson( data=open('world.json', 'r', encoding='utf-8-sig').read(), style_function=lambda x: { 'fillColor': 'green' if x['properties']['POP2005'] < 10000000 else 'orange' if 10000000 <= x['properties']['POP2005'] < 20000000 else 'red' })) map.add_child(fg)
return "green" elif elevation < 3000: return "orange" else: return "red" data = pd.read_csv("Volcanoes_USA.txt") lat = data["LAT"] lon = data["LON"] elev = data["ELEV"] map = folium.Map(location=[38.58, -99.09], zoom_start=6, tiles="Mapbox Bright") fgv = folium.FeatureGroup(name="Volcanoes") fgc = folium.FeatureGroup(name="Population coloring") for la, lo, el in zip(lat, lon, elev): fgv.add_child( folium.CircleMarker(location=(la, lo), popup=str(el), color="grey", radius=6, fill=True, fill_color=color_producer(el), fill_opacity=.8)) fgc.add_child( folium.GeoJson( data=open('world.json', 'r', encoding='utf-8-sig').read(),
import folium import pandas data = pandas.read_csv("cities.txt") lat = list(data["LAT"]) lon = list(data["LON"]) elev = list(data["PLACE"]) map = folium.Map(location=[21.10, 79.09], zoom_start=6, tiles="Mapbox Bright") fgc = folium.FeatureGroup(name=" Major States of India") for lt, ln, el in zip(lat, lon, elev): fgc.add_child( folium.Marker(location=[lt, ln], popup=el, icon=folium.Icon(color='green'))) data = pandas.read_csv("Volcanoes.txt") lat = list(data["LAT"]) lon = list(data["LON"]) elev = list(data["ELEV"]) def color_producer(elev): if elev < 1000: return 'green' elif 1000 <= elev < 3000: return 'orange' else: return 'red'
import folium mappa = folium.Map(location=[45.495523, 9.190973], zoom_start=8, tiles="Mapbox Bright") mia_mappa = folium.FeatureGroup(name="Mia Mappa") mia_mappa.add_child( folium.Marker(location=[45.495523, 9.190973], popup="Milano", icon=folium.Icon(color='red'))) mia_mappa.add_child( folium.Marker(location=[41.901210, 12.585783], popup="Roma", icon=folium.Icon(color='blue'))) mia_mappa.add_child( folium.CircleMarker(location=[45.495523, 8.190973], popup="Milano", radius=10, color='violet', fill_color="green", fill_opacity=1)) regioni = folium.FeatureGroup(name="Regioni") regioni.add_child( folium.GeoJson(data=open("geo.json", "r", encoding="utf-8-sig").read()))
def set_marker_color(population): """ Returns a color str based on relative population for city markers """ if population in range(minimum_population, lower_quartile): color = 'lightgreen' elif population in range(lower_quartile, second_quartile): color = 'green' elif population in range(second_quartile, third_quartile): color = 'orange' else: color = 'darkred' return color # Feature group to hold all the city markers on the base map city_fg = folium.FeatureGroup(name='50 Most Populous US Cities') for population, latitude, longitude, name, rank in zip(city_df['population'], city_df['lat'], city_df['lon'], city_df['place'], city_df['rank']): formatted_population = "{:,}".format(population) # Adding one marker per city on the map with a population color and XY coords city_fg.add_child( folium.Marker(location=[latitude, longitude], popup=f'#{rank}, {name}, Population: {formatted_population}', icon=folium.Icon( color=set_marker_color(population)))) # Adding the feature group to the base map once all markers have been added base_map.add_child(city_fg) # Reading oceans.json which has polygon details for the world oceans
map_cctv = folium.Map(location=[35.22323, 128.60946], zoom_start=11, tiles='OpenStreetMap') rfile = open("changwon.json", 'r', encoding='cp949').read() jsonData = json.loads(rfile) folium.GeoJson(jsonData, name='읍면동 구분').add_to(map_cctv) # 4-3-5. 마우스 포지션(위도, 경도) 찾기 기능 # from folium.plugins import MousePosition # MousePosition().add_to(map_cctv) # 4-3-6. 측정도구 기능 # from folium.plugins import MeasureControl # map_pplace.add_child(MeasureControl()) len(data[data['카메라대수'] == 4]) fg = folium.FeatureGroup(name="cctv 전체") # 전체그룹 설정 g1 = plugins.FeatureGroupSubGroup(fg, '교통용 cctv') # 서브그룹 틀 만들기 g2 = plugins.FeatureGroupSubGroup(fg, '비교통용 cctv') map_cctv.add_child(fg) # 서브 그룹 맵에 넣기 map_cctv.add_child(g1) map_cctv.add_child(g2) for i in range(0, len(data_traffic)): folium.Circle([data_traffic["위도"][i], data_traffic["경도"][i]], radius=50, color="#ffc039", fill=True).add_to(g1) for j in range(0, len(data_non_traffic)): folium.Circle([data_non_traffic["위도"][j], data_non_traffic["경도"][j]], radius=50, color="#376091", fill=True).add_to(g2) folium.LayerControl(collapsed=False).add_to(map_cctv) map_cctv.save("map_cctv.html")
if (el > 2500): return 'red' elif (2000 < el < 2500): return 'blue' elif (1000 < el < 2000): return 'orange' else: return 'green' map = folium.Map(location=[44.31916539, -110.02333324], zoom_start=2, tiles="Mapbox Bright") #AREA":44,"POP2005":83039,"REGION":19,"SUBREGION":29, fgv = folium.FeatureGroup(name="Volcano") fgp = folium.FeatureGroup(name="Population") fga = folium.FeatureGroup(name="area") for lt, ln, el in zip(lat, lon, elev): fgv.add_child( folium.CircleMarker(location=[lt, ln], radius=6, popup=str(el) + " m", fill_color=color_producer(el), color='grey', fill=True, fill_opacity=0.5)) fgp.add_child( folium.GeoJson(
price = float(price.replace("$", "").replace(",", "")) if price < 600: return "green" elif 600 <= price < 1000: return "orange" else: return "red" except Exception as e: return "blue" map = folium.Map(location=[47.5669, -52.7067], zoom_start=13) marker_cluster = MarkerCluster().add_to(map) update_time = datetime.now().strftime("%m/%d/%Y") fg1 = folium.FeatureGroup( name=f"Rental places from kijiji updated on {update_time}.") for i in range(len(houseLocation)): iframe = folium.IFrame(html=html % (titleList[i], priceList[i], houseInfo[i], houseDescription[i], hrefList[i]), width=300, height=400) folium.Marker(location=houseLocation[i], popup=folium.Popup(iframe), icon=folium.Icon(color_selector( priceList[i]))).add_to(marker_cluster) map.add_child(fg1) map.add_child(folium.LayerControl()) map.save("index.html") print("Map has been generated!")
name = list(fav_data['Name']) rating = list(fav_data['Rating']) website = list(fav_data['Website']) def color_maker(fav): if fav == True: return 'green' else: return 'red' #_________________ ## MARKERS ## cub_foods = folium.FeatureGroup(name='Good Cub Locations') for lt, ln, loc, fav in zip(lat, lon, locale, favorite): cub_foods.add_child( folium.Marker(location=[lt, ln], popup=f'Cub Foods: {loc}', icon=folium.Icon(color=color_maker(fav)))) map.add_child(cub_foods) fav_foods = folium.FeatureGroup(name='Favorite Eateries') for lt, ln, name, rate, url in zip(fav_lat, fav_lon, name, rating, website): fav_foods.add_child( folium.Marker( location=[lt, ln],
#Start position of map map = folium.Map(location=[37.79648, -99.164589], zoom_start=5, tiles="Mapbox Bright") #HTML to allow users to lookup university & HS htmlUniv = """ Name:<br> <a href="https://www.google.com/search?q=%%22%s%%22" target="_blank">%s</a><br><br> Year Founded: %s """ #My schools feature group fg = folium.FeatureGroup(name="University") fg.add_child( folium.Marker( location=[40.862243, -73.88566], popup=folium.Popup( folium.IFrame(html=htmlUniv % ("Fordham University", "Fordham University", "1841"), width=200, height=100)), icon=folium.Icon(color='blue'))) fg.add_child( folium.Marker( location=[40.729938, -73.997374], popup=folium.Popup( folium.IFrame( html=htmlUniv %
elev.append(e) return (coordinates, elev) def height_intensity(h): if h < 1000 : return 'green' elif h > 3000 : return 'red' else : return 'orange' # getting coordinates (lst, height) = get_coordinates(data) map = fl.Map(location=[40,-100]) #creating a map object fgv = fl.FeatureGroup(name='Volcanoes') # lst = [[13.357,74.79], [13.356,74.79], [13.358,74.79], [13.357,74.80]] for coordinate, ele in zip(lst, height): fgv.add_child(fl.CircleMarker(location=coordinate, radius=6, popup="Elevation = {}".format(ele), fill_color=height_intensity(ele), color='grey', fill_opacity=0.6)) #adding popurlation polygon using geoJSON fgp = fl.FeatureGroup(name='Popurlation') fh = '''D:/Code/Python/Courses/The Python Mega Course Build 10 Real World Applications/11 Application 2 Creating Webmaps with Python and Folium/world.json''' dat = open(fh, encoding="utf-8-sig").read() fgp.add_child(fl.GeoJson(data=dat, style_function = lambda x: { 'fillColor' : 'green' if x['properties']['POP2005'] < 10000000 # lesser than 10,000,000 else 'red' if x['properties']['POP2005'] > 20000000 # greater than 20,000,000
location = list(data["LOCATION"]) contact = list(data["CONTACT"]) def color_producer(catg): if catg == "Gym": return 'green' elif catg == "Momo": return 'red' else: return 'blue' map = folium.Map(location=[27.673378, 85.317900], zoom_start=16) #first feature group shows all fg1 = folium.FeatureGroup(name="All") for lt, ln, nm, cat, lc, con in zip(lat, lon, name, category, location, contact): fg1.add_child( folium.Marker(location=[lt, ln], popup=(nm + "\nCategory: " + cat + "\nContact: " + str(con) + "\nLocation: " + lc), icon=folium.Icon(color_producer(cat)))) #second feature group shows gym fg2 = folium.FeatureGroup(name="Gym") for lt, ln, nm, cat, lc, con in zip(lat, lon, name, category, location, contact): if (cat == "Gym"): fg2.add_child( folium.Marker(location=[lt, ln],
import folium import pandas data = pandas.read_csv("spotonmap.txt") lat = list(data["LAT"]) lon = list(data["LON"]) name = list(data["NAME"]) map = folium.Map(location=[55.753220, 37.618068], zoom_start=15) fgv = folium.FeatureGroup(name="Spotonmap") for lt, ln, name in zip(lat, lon, name): fgv.add_child( folium.Marker(location=[lt, ln], popup=str(name), icon=folium.Icon(color='green'))) map.add_child(fgv) map.save("Map1.html")
import folium #Adding a starting point map = folium.Map(location = [60.1733244,24.9410248], tiles = "Stamen Terrain") #Adding a point on the map with information #map.add_child(folium.Marker(location = [60.1733244,24.9410248], popup = "Lorem", icon = folium.Icon(color = "green"))) #Adding a feature-group fg = folium.FeatureGroup(name = "newmap") elements = {"M1":[60.1733244,24.9410248], "M2": [60.9533244,24.9410248], "M3": [60.0133244,24.9410248]} for key in elements: fg.add_child(folium.Marker(location = elements[key], popup = key, icon = folium.Icon(color = "green"))) map.add_child(fg) map.save("mymap.html")
case = list(data["CASE"]) fat = list(data["FATALITIES"]) def color_producer(fatal): if fatal < 10: return 'darkblue' elif 10 < fatal < 20: return 'orange' else: return 'red' map = folium.Map(location=[38.58, -99.09], zoom_start=6, tiles='OpenStreetMap') fgm = folium.FeatureGroup(name="Mass Killings") for lt, ln, nm, ft in zip(lat, lon, case, fat): fgm.add_child( folium.CircleMarker(location=[lt, ln], radius=10, popup=str(nm), fill_color=color_producer(ft), color='grey', fill_opacity=0.7)) fgp = folium.FeatureGroup(name="Population") fgp.add_child( folium.GeoJson( data=open("world.json", 'r', encoding='utf-8-sig').read(), style_function=lambda x: { 'fillColor':
return "orange" else: return "red" #converting to list nam = list(data["NAME"]) lat = list(data["LAT"]) lon = list(data["LON"]) elev = list(data["ELEV"]) #styling the banner html = """<h4>Volcano information:</h4> Height: %s m """ #feature group fg = folium.FeatureGroup(name="my map") #loop for plotting multiple points for lt, ln, el, in zip(lat, lon, elev): iframe = folium.IFrame(html=html % str(el), width=200, height=100) fg.add_child( folium.CircleMarker(location=[lt, ln], radius=6, popup=folium.Popup(iframe), fill_color=color_finder(el), color="gray", fill=True, fill_opacity=0.7)) map.add_child(fg) #saving files as html map.save("newmap.html")
import folium map = folium.Map(location=[32.58, -99.09], zoom_start=6, title="Mapbox Bright") fg = folium.FeatureGroup(name="Volcanoes") for coordinate in [[32.58, -99.09], [33.58, -98.09]]: fg.add_child( folium.Marker(location=coordinate, popup="Hi i am marker", icon=folium.Icon(color="green"))) map.add_child(fg) map.save("Map3.html") print(map)
def color_producer(elevation): if elevation < 1000: return "green" elif 1000 <= elevation < 3000: return "orange" else: return "red" map = folium.Map(location=[47.6182513, -122.35406], zoom_start=6, tiles="Stamen Terrain") fgv = folium.FeatureGroup(name="Volcanoes") for lt, ln, lv in zip(lat, lon, elev): fgv.add_child( folium.CircleMarker( location=[lt, ln], radius=6, popup=str(lv) + " m", fill_color=color_producer(lv), color="grey", fill_opacity=0.7, )) fgp = folium.FeatureGroup(name="Population") fgp.add_child( folium.GeoJson(
import folium import pandas cities = pandas.read_json("Morocco.json") cities latCity = list(cities["lat"]) lonCity = list(cities["lng"]) nameCity = list(cities["name"]) country = list(cities["country"]) cityMap = folium.FeatureGroup(name="Cities") for lat, lon, city in zip(latCity, lonCity, nameCity): html = "<main class='main' id='" + str(lat) + "," + str( lon ) + "'><div class='location'><h1 class='loc-timezon'></h1><canvas id='icon1' width='100' height='100'></canvas></div><div class='temperatur'><div> <h2 class='degre'></h2> <span id='fc'>C</span></div><div class='discription'></div></div></main>" cityMap.add_child( folium.CircleMarker(location=[lat, lon], popup=html, radius=6, fill_color='red', icon=folium.Icon(color='red'))) #f = folium.FeatureGroup(name="ZACK Map") fg = folium.FeatureGroup(name="geojson") fg.add_child(folium.CircleMarker(location=[31.056376, -9.033904], radius=1)) map1 = folium.Map(Location=[34.056376, -5.033904], zoom_start=13, center=[34.056376, -5.033904]) # for la ,lo , na in zip(lat, lon , name):
map = f.Map(location=[df["LAT"].mean(), df["LON"].mean()], zoom_start=5) def color(elev): min_elev = int(min(df["ELEV"])) step = int((max(df["ELEV"]) - min(df["ELEV"])) / 4) if elev in range(min_elev, min_elev + step): col = 'green' elif elev in range(min_elev + step, min_elev + step * 2): col = 'yellow' elif elev in range(min_elev + step * 2, min_elev + step * 3): col = 'orange' else: col = 'red' return col fg = f.FeatureGroup(name="Volcanoes Locations") for lat, lon, details, elev in zip(df["LAT"], df["LON"], df["DETAILS"], df["ELEV"]): # print(lat,lon,details) fg.add_child( f.Marker(location=[lat, lon], popup=f.Popup(details), icon=f.Icon(color=color(elev)))) map.add_child(fg) map.add_child(f.LayerControl()) map.save("volcanoes.html")
# map object from folium map = folium.Map(location=[23.13, 72.53]) f = open('kotaatm.txt', 'r') cordinates = [] for line in f.readlines(): location = do_geocode(line) if location != None: cordinates.append([location.latitude, location.longitude]) f.close() print(cordinates) fg = folium.FeatureGroup(name='MyMap') for cord in cordinates: fg.add_child(folium.Marker( location=cord, popup='Kotak ATM', icon=folium.Icon(color='red'))) map.add_child(fg) # map save with html format map.save('map.html') print('map is saved')
#!/usr/bin/env python3 import folium import pandas beaches = pandas.read_csv('thasos.beaches.txt') map = folium.Map(location=[40.6, 24.5], zoom_start=9) beaches.set_index('Title') beach_titles = list(beaches['Title']) beach_lon = list(beaches['Long']) beach_lat = list(beaches['Lat']) fg = folium.FeatureGroup('Thasos Beaches') for title,lon,lat in zip(beach_titles, beach_lon, beach_lat): fg.add_child(folium.Marker(location=[lon,lat], popup=title,icon=folium.Icon(icon='bicycle'))) fg.add_child(folium.CircleMarker(location=[40.6, 24.5], radius = 20)) map.add_child(fg) map.add_child(folium.ClickForMarker()) map.save("BaseMap.html")
mapbox = "https://api.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiYWFyb24wMjIxIiwiYSI6ImNqcTBiNHJlZDBqODQ0Mm11aWpqejk4ZWgifQ.ZXaiQzs7b3iwntK9_Nv-0w" with open("D:\\大學課程\\大二上\\社會科學程式設計\\Youbike專題\\json\\YouBike.json", "r") as f: data = (json.load(f))["features"] with open("D:\\大學課程\\大二上\\社會科學程式設計\\Youbike專題\\json\\MRT.json", "r") as f: data1 = (json.load(f))["features"] myMap = folium.Map(location=[25.03, 121.55], zoom_start=12, prefer_canvas=True, tiles=mapbox, attr="Mapbox attribution") fg1 = folium.FeatureGroup(name="YouBike") for i in range(len(data)): place = data[i]["geometry"]["coordinates"] place = [place[1], place[0]] fg1.add_child(folium.Circle(location=place, radius=2, weight=4)) fg2 = folium.FeatureGroup(name="MRT") for i in range(len(data1)): place = data1[i]["geometry"]["coordinates"] place = [place[1], place[0]] line, name = data1[i]["properties"]["Line"], data1[i]["properties"]["Name"] if line == "BR": # 文湖 fg2.add_child( folium.Marker(location=place, popup=folium.Popup(name),