Defibrillator from OSM
[This article was first published on r.iresmi.net, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Day 15 of 30DayMapChallenge: « OpenStreetMap » (previously).
Using data from OSM we’ll make a web map of defibrillators (AED) in Auvergne-Rhône-Alpes.
library(tidyverse) library(sf) library(osmdata) library(glue) library(leaflet) library(htmltools)
We send an Overpass API query with {osmdata}:
# France regions
# See https://r.iresmi.net/posts/2021/simplifying_polygons_layers/ for the data
fr <- read_sf("~/data/adminexpress/adminexpress_cog_simpl_000_2022.gpkg", layer = "region") |>
filter(insee_reg > "06")
# Get and cache OSM data for France
if (!file.exists("aed.rds")) {
aed <- opq(st_bbox(fr), osm_types = "node", timeout = 6000) |>
add_osm_features(features = c(
'"emergency"="defibrillator"')) |>
osmdata_sf() |>
pluck("osm_points") |>
st_join(fr, left = FALSE) |>
write_rds("aed.rds")
} else {
aed <- read_rds("aed.rds")
}
Automated external defibrillator in AURA
icons <- awesomeIcons(
library = "fa",
icon = "heart",
markerColor = "white",
iconColor = "darkgreen")
# Just keep the region data
aed |>
st_join(fr |>
filter(insee_reg == 84),
left = FALSE) |>
leaflet(options = leafletOptions(preferCanvas = TRUE)) |>
addTiles() |>
addAwesomeMarkers(
clusterOptions = markerClusterOptions(),
icon = icons,
popup = ~glue("
<table>
<tr><th style='font-weight:bold'>localisation</th>
<td>{htmlEscape(coalesce(`defibrillator:location:fr`, `defibrillator:location`))}</td></tr>
<tr><th>intérieur</th><td>{htmlEscape(coalesce(indoor, `indoor:description`))}</td></tr>
<tr><th>niveau</th><td>{htmlEscape(level)}</td></tr>
<tr><th>accès</th><td>{htmlEscape(access)}</td></tr>
<tr><th>horaires</th><td>{htmlEscape(opening_hours)}</td></tr>
<tr><th>opérateur</th><td>{htmlEscape(operator)}</td></tr>
<tr><th>tél.</th><td>{htmlEscape(phone)}</td></tr>
<tr><th>réf.</th><td>{htmlEscape(`ref:FR:GeoDAE`)}</td></tr>
<tr><th>particularité</th><td>{htmlEscape(defibrillator)}</td></tr>
<tr><th>description</th><td>{htmlEscape(coalesce(`description:fr`, description))}</td></tr>
</table>"))
To leave a comment for the author, please follow the link and comment on their blog: r.iresmi.net.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
