Create World Maps in Python using Folium
Today, in this Blog we will explore the basics of using the Geospatial data and plot a World Map using Folium.
Creation of World Maps using Folium
Folium Installation
To get started, we will first install the required Python package using the command:
pip install folium
Output:
You will see something like this, let it get completed. Once it gets completed, open up the Jupyter Notebook.
You can check: How to add the marker to the folium map in Python
Creation and Styling of a Map in Folium
A beginner-friendly feature of Folium is to create maps with minimal lines of code. The initial map or the default map looks pretty good since there are various tile providers to provide high-quality map backgrounds for our web maps.
To begin with, let us first create our very first map using just three lines of code:
import folium
map = foilum.Map() map
Output:
We can even customize the default tile style, for example (that is available for free) CartoDB and Stamen.
Let’s Explore the CartoDB tile style:
map = folium.Map(tiles=’cartodbdark_matter’) map
Output:
map = folium.Map(tiles='cartodbpositron') map
Output:
Addition of a Geolocation
First of all, adjust the map’s zoom level such that we only want the world map in a position that gives us a good view of the continents.
For that, we will need to adjust the location parameter in the function such that the map is focused on such a place that will make all the continents visible properly.
map = folium.Map(location=(10, 10), zoom_start=2.4, tiles="cartodb positron") map
Output:
Addition of GeoJSON Countries’ Layer
In this process of map visualization, adding this layer serves the critical and crucial process of delineating country boundaries on the world map. This leads to the addition of country-specific data onto the maps and enables the creation of choropleth maps.
political_countries_url = ( "http://geojson.xyz/naturalearth-3.3.0/ne_50m_admin_0_countries.geojson" ) map = folium.Map(location=(30, 10), zoom_start=2.4, tiles="cartodb positron") geojson = folium.GeoJson(political_countries_url) geojson.add_to(map) map
Output:
Here, the variable: political_countries_url
is an endpoint that serves GeoJSON Data representing the boundaries of countries in the world. Specifically, it provides data from the Natural Earth Dataset which includes the administrative boundaries of the dataset.
Since we have added a vector layer representing the political boundaries of the countries, our world map is ready to connect that layer with the country-specific data.
That is, now our map is ready for further use, such as creating choropleth maps, and heatmaps, adding some custom markers, layer controls, interactive features, etc.
To learn more about the Folium package please check this blog post: Create Interactive Maps using Folium
Leave a Reply