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”:
ru_national_map <- ne_countries(type = "countries", country = "Russia", scale = "medium", returnclass = "sf")
mapview(ru_national_map)uae_national_map <- ne_countries(type = "countries", country = "United Arab Emirates", scale = "large", returnclass = "sf")
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)
library(sf)
library(rnaturalearth)
library(mapview)
france_sf <- ne_countries(country = "France", scale = 50)
(france_map <- mapview(france_sf, label = "geounit", legend = FALSE))france_cent_sf <- sf::st_centroid(france_sf)Warning: st_centroid assumes attributes are constant over geometries
france_map + mapview(france_cent_sf, label = "Centroid", legend = FALSE)Computing the union of all geometries in the sf via sf::st_union()
library(leaflet.extras2)
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_mapafrica_bbox_sf <- sf::st_bbox(africa_sf)
africa_bbox_map <- mapview(africa_bbox_sf, label="st_bbox(africa)", legend=FALSE)
africa_map | africa_bbox_mapafrica_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_mapUse st_union() first:
africa_cvx <- africa_sf |> st_union() |> st_convex_hull()
africa_cvx_map <- mapview(africa_cvx, label="geounit", legend=FALSE)
africa_map | africa_cvx_mapComputing the centroid of all geometries in the sf via sf::st_centroid()
africa_cents_sf <- sf::st_centroid(africa_sf)Warning: st_centroid assumes attributes are constant over geometries
africa_cents_map <- mapview(africa_cents_sf, label="geounit", legend=FALSE)
africa_map | africa_cents_map