Python-bloggers

Introduction to Folium

This article was first published on The Pleasure of Finding Things Out: A blog by James Triveri , and kindly contributed to python-bloggers. (You can report issue about the content on this page here)
Want to share your content on python-bloggers? click here.

Learning geospatial data science is crucial in today’s data-driven world for several reasons. Geospatial data science enables individuals to understand and analyze complex spatial phenomena, including natural disasters, urbanization, climate change, and environmental degradation. By gaining familiarity with geospatial analysis techniques, individuals can gain insights into spatial patterns, relationships and processes, which is essential for making informed decisions.

Moreover, geospatial data science provides valuable skills and knowledge that are highly relevant across various domains and industries. From urban planning and environmental management to public health and disaster response, proficiency in geospatial data science opens up diverse career opportunities and enhances professional development prospects.

Additionally, learning geospatial data science fosters critical thinking, problem-solving, and interdisciplinary collaboration skills. It requires learners to integrate spatial data from multiple sources, apply statistical and computational methods, and communicate findings effectively to diverse stakeholders.

Furthermore, as the availability and complexity of geospatial data continue to grow with advancements in technology and data collection methods, the demand for skilled geospatial data scientists is expected to rise. Therefore, investing in learning geospatial data science equips individuals with valuable skills that are not only relevant today but also increasingly essential for future career success.

Folium

Folium is a Python library used for visualizing geospatial data interactively on web maps. Leveraging the capabilities of Leaflet.js, Folium allows users to create maps directly within Python code, making it an accessible and powerful tool for geospatial visualization and analysis.

With Folium, users can create various types of interactive maps, including point maps, choropleth maps, heatmaps, and vector overlays, by simply specifying geographic coordinates and map styling options. The library provides intuitive APIs for customizing map features such as markers, popups, tooltips, legends, and map layers, enabling users to create visually appealing and informative maps with ease.

Folium integrates with other popular Python libraries such as Pandas and Matplotlib, allowing users to visualize geospatial data stored in DataFrame objects or plot data directly onto Folium maps. It also supports various tile providers and basemaps, enabling users to choose from a wide range of map styles and sources.

Creating Interactive Maps in Folium

Creating maps with folium is straightforward. We simply pass the latitude and longitude of the point of interest (POI) and specify a zoom level. We can then drop a marker on the point of interest, and interact with the map however we’d like.

We can get the latitude and longitude for a given POI by performing a google search. Latitude ranges from -90 to 90 degrees, longitude from -180 to 180 degrees. The latitude and longitude for the DMACC Ankeny campus is (41.5996, -93.6276), which is (latitude, longitude). Note that for US coordinates, the longitude will always be negative. An illustration is provided below:

img01

To illustrate, let’s render a map over the park I used to play at as a child (Durkin Park on the southwest side of Chicago). Note that zoom level provides more detail as the number gets larger. A zoom level of 4 would show the entire US; a zoom level of 17 would render roughly a city block:

import folium

# Latitude and longitude for Durkin Park, 84th & Kolin Ave, Chicago IL. 
lat = 41.739
lon = -87.729
zoom = 18

m = folium.Map(location=[lat, lon], zoom_start=zoom)
folium.Marker(location=[lat, lon]).add_to(m)

m
Make this Notebook Trusted to load map: File -> Trust Notebook