What is Folium in Python?
Folium is a Python Library that allow us to visualize spatial data (geographical data) in an interactive manner (you can drag,zoom,click on the map ).Manipulate your data in Python, then visualize it in on a Leaflet map via folium.
Official Documentation of Folium (Click Here)
Geographical Data: All kinds of data that contain geographical (latitude, longitude, altitude, shape) as part of its feature. (Maps!).
Note that to see the position of any place (place in city,city,district, state,country etc...) on the map, we need latitude and longitude.
Here is a link to a site that I follow to find the position (latitude and longitude) of any place (click here).
Installation of folium
Installation is same as other libraries in python
$ pip install folium
How do you use(Install) Folium in Jupyter Notebook or Anaconda?
$ conda install folium -c conda-forge
What are tile styles of Folium maps?
Before getting started let's understand what is tiles and zooming in map
Tiles are 256x256 pixels.At the outer most zoom level, 0, the entire world can be rendered in a single map tile (consider world map as one tile).Each zoom level doubles in both dimensions, so a single tile is replaced by 4 tiles when zooming in.
This means that about 22 zoom levels are sufficient for most practical purposes. (You can also see it by doing it on Google map, try it just open your google map start with maximum zoom and see the map after 22 zooms.)
Most tiled web maps follow certain Google Maps conventions.
For clarification see the image below where you can see that how tiles and zooms work in a map.
To create a basic map, simply pass your starting coordinates (longitude and latitude) to Folium map function.
#Creating simple map
#saving a map in folium (create a html page)
We have not done much here, just pass the position/location (longitude and latitude) in the folium map function and we got our map. We can save the map in Folium. The map will be saved in the form of html file (that you can use later).
#styling of map
mapp= folium.Map(location=[26.920980,75.794220],zoom_start=4,tiles="Stamen Terrain")
The default tiles are set to OpenStreetMap in folium library but Stamen Terrain, Stamen Toner , Mapbox Bright and Mapbox Control Room and many other tiles are built in , in folium.
To get any of these tiles (map style) you just have to pass a parameter tiles in folium map function as we did in above code.
Markers and Popup
There are numerous marker types (see the google map), start with simple style location marker with popup.
#creating a simple marker
folium.Marker([28.609140,77.234138], popup='India Gate', tooltip="click me for more").add_to(marker)
Note: As you can see from the output we have created a simple marker on location of India gate Delhi with popup message 'India Gate'.
Creating different markers and icons in map
#Different types of markers and icon
#adding blue circle marker to india gate
#adding red circle marker to red fort
#adding icon to the map
icon=folium.Icon(color='#ff0033', icon='fas fa-shopping-cart')
As you can see in the output, we have made three markers here.
The first marker, which is a circle marker, is used in red color for the red fort.
We used the second marker in blue color circle for India Gate.
And the third marker in which we have shown a shopping cart icon, used for the cp (Connaught Place, shopping mart) Delhi .
When you people use Google Map, then you must have seen many icons popping location name.Here is a link of listed icons (click here).
Plotting Geojson/ json and Topojson file on map
TopoJSON: An extension of GeoJSON is TopoJSON that is smaller in size and encodes geospatial topology.
Here we used Indian states json file to define the state boundaries and multiple layers can be visualized on the same map. Link of Indian states Geo json file ( click here ).used here.
#plotting Geojson data on map
Note: Here we just Indian state Geojson file to define Indian state boundaries.
Machine Learning Tutorial