Mapping#
Up to this point, we have been working with data plotted on a 2D cartesian coordinate system, with x and y axes. For our purposes, it’s most useful to think of maps in the same way–as data plotted on a coordinate system. Except for maps, that coordinate system is typically some type of latitude or longitude based projection, and the data to be plotted includes explicit location information (rather than a numerical or categorical field that can be mapped to an axis).
This chapter provides an introduction to geospatial data, including structures and formats, with a focus on Python programming workflows. It also covers static visualization workflows with GeoPandas
and interactive visualization workflows with plotly
.
Acknowledgements#
The author consulted the following resources when developing this chapter:
Bonny P. McClain, Python for Geospatial Data Analysis: Theory, Tools, and Practice for Location Intelligence (O’Reilly, 2022).
GeeksForGeeks, “Working With Geospatial Data in Python” (n.d.)
Henrikki Tenkanen, “Spatial Analysis With Python” in Spatial Data Science for Sustainable Development
GeoPandas, “Introduction to GeoPandas”
Chapter Contents#
Data#
We’ll be working with a few different datasets in this chapter.
St. Joseph County zip code boundary file.
-
Note: I’ve renamed this file
zip.geojson
.
Educational outcome attribute data from the American Community Survey with the St. Joseph County zip code boundary file.
-
Note: I’m working with 2022’s 5 year estimate, which I’ve renamed
data.csv
.
-
Park location and feature data from the City of South Bend
-
Note: I’ve renamed this file
parks.csv
.
-
Sample datasets from the plotly
library. Code to load these datasets is included.
2014 U.S. Cities Population
Gapminder Data
NYC Uber Rides
U.S. Unemployment Data
GeoJSON U.S. County Boundaries
Mapbox Access Token#
Later in this chapter, we’ll be working with features of the Mapbox API that require an access token.
Sign up for a free Mapbox account:
Once you have signed up and logged in, click Token
in the top level menu (between Dashboard
and Statistics
).
Click the Create a token
button to create a new access token:
Choose a descriptive name for your token (“Elements of Computing” works fine). The default settings for which boxes are checked/unchecked are fine.
Click the Create token
button at the bottom of the page.
Save this token value (string of numbers and letters) for later in the chapter.
Application#
Click here for a Jupyter Notebook template for this chapter’s application problems.