Defibrillator from OSM

Day 15 of 30DayMapChallenge
R
30DayMapChallenge
spatial
datavisualization
OSM
Author

Michaël

Published

2023-11-15

Modified

2023-11-15

A photo of flowers in the shape of hearts

Bleeding Heart – CC-BY by Theo Crazzolara

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>")) 
Figure 1: Defibrillator in AURA