Code
source("../dsan-globals/_globals.r")
library(rnaturalearth)
library(mapview)
PPOL 6805 / DSAN 6750: GIS for Spatial Data Science
Fall 2025
source("../dsan-globals/_globals.r")
library(rnaturalearth)
library(mapview)
“Simplest” / Most Efficient Representation
“Indicate which of the seven geometries above would provide the simplest representation of the entity”
GEOMETRYCOLLECTION
could represent any of the geographic entities in Q1, but would be overkill for representing e.g. a single point or line
For the United Arab Emirates (UAE) data… we have what we call the Not-Paraguay-Problem: Most countries, including the UAE, have a bunch of lil “pieces”:
<- ne_countries(type = "countries", country = "Russia", scale = "medium", returnclass = "sf")
ru_national_map mapview(ru_national_map)
<- ne_countries(type = "countries", country = "United Arab Emirates", scale = "large", returnclass = "sf")
uae_national_map mapview(uae_national_map)
So, for Q1.8: Assume we’re just trying to have the computer represent the “mainland” (the biggest contiguous landmass, with Dubai on it!)
The Earth’s “width” is slightly greater than its “length” 😰
Is poverty a “significant issue” in the US?
Is poverty a “significant issue” in the US?
Assigns the same number of observations to each color
Is poverty a “significant issue” in the US?
Boundaries between colors come at regular (equal) intervals
Is poverty a “significant issue” in the US?
Clustering algorithm chooses classes to (a) minimize differences within classes, (b) maximize differences between classes
Is poverty a “significant issue” in the US?
A government program offers special funding for counties with above 25% poverty
Is poverty a “significant issue” in the US?
Using rnaturalearth
with mapview
set.seed(6805)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ lubridate 1.9.4 ✔ tibble 3.3.0
✔ purrr 1.0.4 ✔ tidyr 1.3.1
── 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
library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(rnaturalearth)
library(mapview)
<- ne_countries(country = "France", scale = 50)
france_sf <- mapview(france_sf, label = "geounit", legend = FALSE)) (france_map
<- sf::st_centroid(france_sf) france_cent_sf
Warning: st_centroid assumes attributes are constant over geometries
+ mapview(france_cent_sf, label = "Centroid", legend = FALSE) france_map
Computing the union of all geometries in the sf
via sf::st_union()
library(leaflet.extras2)
Loading required package: leaflet
<- ne_countries(continent = "Africa", scale = 50)
africa_sf <- sf::st_union(africa_sf)
africa_union_sf <- mapview(africa_sf, label="geounit", legend=FALSE)
africa_map <- mapview(africa_union_sf, label="st_union(africa)", legend=FALSE)
africa_union_map | africa_union_map africa_map
<- sf::st_bbox(africa_sf)
africa_bbox_sf <- mapview(africa_bbox_sf, label="st_bbox(africa)", legend=FALSE)
africa_bbox_map | africa_bbox_map africa_map
<- sf::st_convex_hull(africa_sf)
africa_countries_cvx <- mapview(africa_countries_cvx, label="geounit", legend=FALSE)
africa_countries_cvx_map | africa_countries_cvx_map africa_map
Use st_union()
first:
<- africa_sf |> st_union() |> st_convex_hull()
africa_cvx <- mapview(africa_cvx, label="geounit", legend=FALSE)
africa_cvx_map | africa_cvx_map africa_map
Computing the centroid of all geometries in the sf
via sf::st_centroid()
<- sf::st_centroid(africa_sf) africa_cents_sf
Warning: st_centroid assumes attributes are constant over geometries
<- mapview(africa_cents_sf, label="geounit", legend=FALSE)
africa_cents_map | africa_cents_map africa_map