-
Notifications
You must be signed in to change notification settings - Fork 95
/
densest.R
58 lines (44 loc) · 1.48 KB
/
densest.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
library(sf)
library(tidyverse)
library(elevatr)
library(rayshader)
library(glue)
library(colorspace)
library(tigris)
library(stars)
library(NatParksPalettes)
library(leaflet)
library(htmlwidgets)
library(webshot)
# Set map name that will be used in file names, and
# to get get boundaries from master NPS list
map <- "oklahoma"
# Kontur data source: https://data.humdata.org/organization/kontur
d_layers <- st_layers("data/kontur/kontur_population_US_20220630.gpkg")
d_crs <- d_layers[["crs"]][[1]][[2]]
s <- states() |>
st_transform(crs = d_crs)
st <- s |>
filter(NAME == str_to_title(str_replace_all(map, "_", " ")))
wkt_st <- st_as_text(st[[1,"geometry"]])
data <- st_read("data/kontur/kontur_population_US_20220630.gpkg",
wkt_filter = wkt_st)
# data |>
# ggplot() +
# geom_sf()
st_d <- st_join(data, st, left = FALSE)
ll <- st_centroid(st_d |> filter(population == max(population))) |>
st_transform(crs = "+proj=longlat +datum=WGS84") |>
st_coordinates()
walk(c(11, 14), function(z) {
max_ca <- leaflet() |>
addTiles() |>
addPolygons(data = st_d |>
filter(population == max(population)) |>
st_transform(crs = "+proj=longlat +datum=WGS84")) |>
setView(lat = ll[[2]], lng = ll[[1]], zoom = z)
saveWidget(max_ca, glue("R/portraits/{map}/temp.html"), selfcontained = FALSE)
webshot(glue("R/portraits/{map}/temp.html"),
file = glue("images/{map}/max_wi_zoom_{z}.png"),
cliprect = "viewport")
})