Week 4: Unary and Binary Operations

PPOL 6805 / DSAN 6750: GIS for Spatial Data Science
Fall 2026

Class Sessions
Author
Affiliation

Jeff Jacobs

Published

Wednesday, September 16, 2026

Open slides in new tab →

Quick Logistical Things

  • Public Tests Updated
  • HW2 Now Available
  • Coding Workshop!

Geospatial Operations 1: Unary Operations

Getting the Geometries

Using rnaturalearth with mapview

Code
set.seed(6805)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ lubridate 1.9.5     ✔ tibble    3.3.1
✔ purrr     1.2.1     ✔ tidyr     1.3.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Code
library(sf)
Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE
Code
library(rnaturalearth)
library(mapview)
france_sf <- ne_countries(country = "France", scale = 50)
(france_map <- mapview(france_sf, label = "geounit", legend = FALSE))

Centroid of France

Code
france_cent_sf <- sf::st_centroid(france_sf)
Warning: st_centroid assumes attributes are constant over geometries
Code
france_map + mapview(france_cent_sf, label = "Centroid", legend = FALSE)

One We Already Saw: Union

Computing the union of all geometries in the sf via sf::st_union()

Code
library(leaflet.extras2)
Loading required package: leaflet
Code
africa_sf <- ne_countries(continent = "Africa", scale = 50)
africa_union_sf <- sf::st_union(africa_sf)
africa_map <- mapview(africa_sf, label="geounit", legend=FALSE)
africa_union_map <- mapview(africa_union_sf, label="st_union(africa)", legend=FALSE)
africa_map | africa_union_map

Helpful for Rasterizing: BBox

Code
africa_bbox_sf <- sf::st_bbox(africa_sf)
africa_bbox_map <- mapview(africa_bbox_sf, label="st_bbox(africa)", legend=FALSE)
africa_map | africa_bbox_map

Convex Hulls by Country

Code
africa_countries_cvx <- sf::st_convex_hull(africa_sf)
africa_countries_cvx_map <- mapview(africa_countries_cvx, label="geounit", legend=FALSE)
africa_map | africa_countries_cvx_map

Convex Hull of Continent

Use st_union() first:

Code
africa_cvx <- africa_sf |> st_union() |> st_convex_hull()
africa_cvx_map <- mapview(africa_cvx, label="geounit", legend=FALSE)
africa_map | africa_cvx_map

One We Already Saw: Centroids

Computing the centroid of all geometries in the sf via sf::st_centroid()

Code
africa_cents_sf <- sf::st_centroid(africa_sf)
Warning: st_centroid assumes attributes are constant over geometries
Code
africa_cents_map <- mapview(africa_cents_sf, label="geounit", legend=FALSE)
africa_map | africa_cents_map

Coordinate Reference Systems

  • First things first… what are coordinates?
  • We need a way to unambiguously specify where things are on the earth

Latitude and Longitude are Angles!

From Krygier and Wood (2016)

Angular Distance vs. Travel Distance

The Earth’s “width” is slightly greater than its “length” 😰

Projections

Smooshing 3D into 2D

From Monmonier (2018)

Avoid Getting Lost in the Sauce

How To Avoid Getting Lost in the Sauce

Tissot Circles: Imagine infinitely small ellipses placed at regular intervals on the curved surface of the earth. Imagine these ellipses being projected along with the earth’s surface. When scaled up, changes in the ellipses show the location and quality of distortions on the projected map.

Your “Escape Rope” When Lost in the Sauce

https://epsg.io/4326

https://epsg.io/3857

Choropleths for Good and Evil

  • Crucial crucial aspect of GIS: Having Domain Knowledge of a Region

The US’s Ur-Choropleth #1: Population

The US’s Ur-Choropleth #2: Race

Crime in Mongolia

From Reddit

Population of Mongolia

Exhibit A

From Monmonier (2018)

Exhibit B

From Monmonier (2018)

Continuous Choropleth

Is poverty a “significant issue” in the US?

From Krygier and Wood (2016)

Quantile Colormap

Is poverty a “significant issue” in the US?

Assigns the same number of observations to each color

From Krygier and Wood (2016)

Equal-Area Colormap

Is poverty a “significant issue” in the US?

Boundaries between colors come at regular (equal) intervals

From Krygier and Wood (2016)

Natural-Break Colormap

Is poverty a “significant issue” in the US?

Clustering algorithm chooses classes to (a) minimize differences within classes, (b) maximize differences between classes

From Krygier and Wood (2016)

Context-Sensitive Colormap

Is poverty a “significant issue” in the US?

A government program offers special funding for counties with above 25% poverty

From Krygier and Wood (2016)

The Importance of History

Is poverty a “significant issue” in the US?

From Krygier and Wood (2016)

References

Krygier, John, and Denis Wood. 2016. Making Maps, Third Edition: A Visual Guide to Map Design for GIS. Guilford Publications.
Monmonier, Mark. 2018. How to Lie with Maps. University of Chicago Press.