library(httr)
library(glue)
library(dplyr)
library(tidyr)
library(purrr)
library(tibble)
library(stringr)
library(sf)
library(leaflet)Day 1 of 30DayMapChallenge: « Points ».
Mapping the mountains above 8000 m, also known as the eight-thousanders.
Config
Data
Several non-trivial options for obtaining the data:
- english Wikipedia doesn’t have the geographic coordinates to scrape (although other language Wikipedias do);
- I can’t get a working SPARQL query on Wikidata (lack of knowledge from me) even with the help of SPINACH Wikidata Agent;
- there is no easy OpenStreetMap relation to import (such categorical relations are discouraged).
So finally I resorted to make a direct Overpass API call, although {osmdata} should have also worked.
Using a Himalaya and Karakoram bounding box, we keep the summits above 8000 m having a prominence > 500 m (major peaks, otherwise we would get several secondary summits).
It should take about 1 minute… And we get a JSON, converted to a list, cleaned to a nice sf-data.frame.
overpass_query <- URLencode(
r"([out:json][timeout:250];
node
["natural"="peak"]
(25,70,38,98)
["ele"]
["prominence"]
(if:number(t["prominence"]) > 500 && number(t["ele"]) > 8000);
out body;)",
reserved = TRUE)
summits <- glue("https://overpass-api.de/api/interpreter?data={overpass_query}") |>
GET() |>
content() |>
pluck("elements") |>
map(unlist) |>
map(enframe) |>
map(pivot_wider) |>
list_rbind() |>
rename_with(\(x) str_replace(x, "^tags\\.", "")) |>
st_as_sf(coords = c("lon", "lat"), crs = "EPSG:4326")Simple feature collection with 14 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 74.58954 ymin: 27.70301 xmax: 88.14748 ymax: 35.88168
Geodetic CRS: WGS 84
# A tibble: 14 × 3
name elevation geometry
<chr> <chr> <POINT [°]>
1 Mount Everest 8848.86 (86.92521 27.98806)
2 K2 8611 (76.51333 35.88168)
3 Kangchenjunga 8586 (88.14748 27.70301)
4 Lhotse 8516 (86.9325 27.96199)
5 Mount Makalu 8485 (87.08844 27.89144)
6 Cho Oyu 8201 (86.65963 28.09675)
7 Dhaulagiri 8167 (83.48949 28.69761)
8 Manaslu 8163 (84.55973 28.54998)
9 Nanga Parbat 8126 (74.58954 35.23846)
10 Annapurna I 8091 (83.81992 28.59581)
11 Gasherbrum I 8080 (76.69762 35.72468)
12 Broad Peak 8051 (76.56556 35.81369)
13 Gasherbrum II 8034 (76.65327 35.75773)
14 Shishapangma 8027 (85.78207 28.35176)
Map
summits |>
leaflet() |>
addTiles(attribution = r"(
<a href="https://r.iresmi.net/">r.iresmi.net</a>.
data and map: <a href="https://www.openstreetmap.org/copyright/">OpenStreetMap</a>)") |>
addCircleMarkers(popup = ~ glue("<b>{name}</b> ({`name:en`})<br />
{ele} m"),
clusterOptions = markerClusterOptions())