<jupyter_start><jupyter_text>Table of Contents1&nbsp;&nbsp;Creating a web map using geospatial1.1&nbsp;&nbsp;Step 1: Creating a base map1.2&nbsp;&nbsp;Step 2: Adding marker1.3&nbsp;&nbsp;Step 3: Adding multiple markers1.4&nbsp;&nbsp;Step 4: Adding markers from data1.5&nbsp;&nbsp;Step 5: Adding different colors to markers1.6&nbsp;&nbsp;Step 6: Changing markers icons and adding LayerControl1.7&nbsp;&nbsp;Step 7: Clustering all markers1.8&nbsp;&nbsp;Step 8: One step forward - a choropleth map with unemployment rate1.9&nbsp;&nbsp;The end of Part II  Creating a web map using geospatial<jupyter_code>Part II of series "Master Python through building real-world applications"
To create multi-purpose web maps there will be used Folium library
Folium is a  Data Visualization library to visualize geospatial data or data that involves coordinates and locations.<jupyter_output><empty_output><jupyter_text>from IPython.core.interactiveshell import InteractiveShell<jupyter_code>Each step in the project is taken as separate in purpose to better visualize the process of building the really fine map. In consequence there will be a few html files with maps in working directory. 
                        “Start from the basics and don’t use a lot where a little will do.”<jupyter_output><empty_output><jupyter_text>Step 1: Creating a base map<jupyter_code>import folium
print(folium.__version__)

map = folium.Map(location=[51.803961, 16.304582], zoom_start=16) #Wschowa
map.save('..\\Real_World_applications\\output_data\\map_wschowa.html') # saving the map in working folder<jupyter_output>0.7.0<jupyter_text>Step 2: Adding marker<jupyter_code># adding marker to the map of Belchatow (additionaly tiles layers used to show diffent kinds of map)
map_1 = folium.Map(location=[51.363406, 19.366805], zoom_start=8, tiles='Mapbox bright')
folium.TileLayer('stamenwatercolor').add_to(map_1)
folium.TileLayer('OpenStreetMap').add_to(map_1)
folium.TileLayer('Mapbox Bright').add_to(map_1)
folium.TileLayer('stamentoner').add_to(map_1)
folium.TileLayer('cartodbpositron').add_to(map_1)
folium.LayerControl().add_to(map_1)
folium.Marker(location=[51.373717, 19.361421], popup = 'Home',
              icon=folium.Icon(color='gray')).add_to(map_1)
map_1.save('..\\Real_World_applications\\output_data\\map_belchatow.html');<jupyter_output><empty_output><jupyter_text>Some problem with map rendering in Internet Explorer when Marker's parameter 'popup' has string value, so map has to be opened in other web browser (Chrome, etc)<jupyter_code>#### Step 3: Adding multiple markers<jupyter_output><empty_output><jupyter_text>adding multiple markers but not large numberfrom IPython.display import HTML, displaymy_map = folium.Map(location=[51.373715, 19.361612], zoom_start=8, tiles='OpenStreetMap')coordinate_list = [[51.373715,19.361612],[52.251150,20.999029],                  [51.155389,16.929876],[51.809204,16.315827]]for coordinates in coordinate_list:    folium.Marker(location=coordinates,                  icon=folium.Icon(color='green')).add_to(my_map)    my_map.save('..\\Real_World_applications\\output_data\\belchatow.html')my_map;<jupyter_code>#### Step 4: Adding markers from data<jupyter_output><empty_output><jupyter_text>adding plenty of markers from data earlier downloaded from authorimport foliumimport pandas as pddata = pd.read_csv('input_data\\Volcanoes_USA.txt')lat = data['LAT']lon = data['LON']elevation = data['ELEV']data.head()print('Number of volcanoes in USA:', data.shape[0]) creating base map is done with some coordinates of the areanew_map = folium.Map(location=[37.296933,-121.9574983], zoom_start=5, tiles='Mapbox bright') plotting markersfor lat, lon, elevation in zip(lat, lon, elevation):    folium.Marker(location=[lat, lon], popup=str(elevation)+' m',                 icon=folium.Icon(color='gray')).add_to(new_map)new_map.save('..\\Real_World_applications\\output_data\\volcano_map.html');<jupyter_code>#### Step 5: Adding different colors to markers<jupyter_output><empty_output><jupyter_text>using colors to group volcanoes by elevation ranges function to change colorsdef color_change(elev):    if elev < 1000:        return 'green'    elif (1000 <= elev < 3000):        return 'orange'    else:        return 'red'color_markers_map = folium.Map(location=[37.296933, -121.9574983],                               zoom_start=5, tiles='Mapbox bright')data = pd.read_csv('input_data\\Volcanoes_USA.txt')lat = data.LATlon = data.LONelevation = data.ELEV plotting markersfor lat, lon, elevation in zip(lat, lon, elevation):    folium.Marker(location=[lat,lon], popup=str(elevation)+' m',                  icon=folium.Icon(color=color_change(elevation))).add_to(color_markers_map)color_markers_map.save('output_data\\c_vol_map.html');<jupyter_code>#### Step 6: Changing markers icons and adding LayerControl<jupyter_output><empty_output><jupyter_text>importing librariesfrom folium.plugins import MarkerClusterimport pandas as pddata = pd.read_csv('input_data\\Volcanoes_USA.txt')lat= data.LATlon = data.LONelevation = data.ELEV function to change colorsdef color_change(elev):    if elev < 1000:        return 'green'    elif 1000 <= elev < 3000:        return 'orange'    else:        return 'red'     creating base mapmap_2 = folium.Map(location=[37.296933, -121.9574983], zoom_start=5,                  tiles='Mapbox bright')folium.TileLayer('CartoDB dark_matter').add_to(map_2)folium.LayerControl().add_to(map_2) plotting markers with new methodfor lat, lon, elevation in zip(lat, lon, elevation):    folium.CircleMarker(location=[lat, lon], radius=9,    popup=str(elevation)+' m', fill_color=color_change(elevation),                         color='gray', fill_opacity=0.9).add_to(map_2) saving mapmap_2.save('..\\Real_World_applications\\output_data\\map_2.html');<jupyter_code>#### Step 7: Clustering all markers<jupyter_output><empty_output><jupyter_text>to improve visualization while there are thousands of markers clustering markers is helpful - grouping icons according to map scale markers will be added to cluster via .add_to method - not to mapimport foliumfrom folium.plugins import MarkerClusterimport pandas as pddata = pd.read_csv('input_data\\Volcanoes_USA.txt')lat = data.LATlon = data.LONelevation = data['ELEV']def color_change(elev):    if elev < 1000:        return 'green'    elif 1000 <= elev < 3000:        return 'orange'    else:        return 'red'map_3 = folium.Map(location=[37.296933,-121.9574983], zoom_start=5,                  tiles='CartoDB dark_matter') creating Clustermarker_cluster = MarkerCluster().add_to(map_3) plotting markers and adding to 'marker_cluster'for lat, lon, elevation in zip(lat, lon, elevation):    folium.CircleMarker(location=[lat,lon], radius=9, popup=str(elevation)+' m',                       fill_color=color_change(elevation), color='gray',                       fill_opacity=0.9).add_to(marker_cluster) saving mapmap_3.save('output_data\\map_3.html');<jupyter_code>#### Step 8: One step forward - a choropleth map with unemployment rate<jupyter_output><empty_output><jupyter_text>Other kind of map, showing regions/states with use of another way of showing numbers/statistics.Files with data and map downloaded due to author's info<jupyter_code>import folium, os
import pandas as pd

# joining the folder path with file name - to make localization of the 'us-states' data
state_geo = os.path.join('../Real_World_applications/input_data/', 'us-states.json')
# making access to 'us-unemployed.csv' data file and saving it as DataFrame
state_unemployment = os.path.join('../Real_World_applications/input_data/', 'us-unemployment.csv')
state_data = pd.read_csv(state_unemployment)

# initializing basic map
map = folium.Map(location=[37, -102], zoom_start=5)

# adding the data and color for the Choropleth object
folium.Choropleth(geo_data=state_geo,
               name='choropleth',
              data=state_data,
              columns=['State', 'Unemployment'],
              key_on='feature.id',
              fill_color='YlGn',
              fill_opacity=0.7,
              line_opacity=0.2,
              legend_name='Unemployment Rate (%)').add_to(map)
map.save('output_data\\folium_choropleth_USA.html');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1149313570647552, 'fraction_numerical': 0.03863443081035111, 'mean_word_length': 4.995630007283321, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '272999', 'license': 'MIT', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2551, 'n_words': 634, 'path': 'Real_World_applications/creating_web_map.ipynb', 'repo_name': 'Licho59/job_data_visualize', 'size': '8231'}