/
day03_polygons.R
44 lines (37 loc) · 1.19 KB
/
day03_polygons.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
library(sf)
library(rnaturalearth)
library(dplyr)
library(tmap)
library(here)
library(osmdata)
extrafont::loadfonts(device = "win")
ec = ne_countries(scale = "medium", country = "Ecuador", returnclass = "sf")
bbox_cont = ec %>%
st_cast("POLYGON") %>%
mutate(area = st_area(geometry)) %>%
top_n(1) %>%
st_bbox()
reserves = opq(bbox = bbox_cont) %>%
add_osm_feature(key = 'leisure', value = "nature_reserve", value_exact = FALSE) %>%
osmdata_sf()
reserves_uq = reserves %>%
unique_osmdata() %>%
unname_osmdata_sf()
reserves_multi = reserves_uq$osm_multipolygons %>%
st_cast("POLYGON")
reserves_poly = reserves_uq$osm_polygons %>%
bind_rows(reserves_multi) %>%
filter(leisure == "nature_reserve")
tm_shape(ec, bbox = bbox_cont) +
tm_fill(col = "#090909") +
tm_shape(reserves_multi, bbox = bbox_cont) +
tm_fill(
col = "white",
alpha = 0.2
) +
tm_layout(bg.color = "black") +
tm_credits(
"SNAP: National System of Protected Areas \n #30DayMapChallenge | Day 3: Polygons \n Data: OpenStreetMap | Created by @loreabad6",
col = "white", align = "right", position = "right", fontfamily = "Futura LT"
)
tmap_save(filename = "maps/day03.png", bg = "black")