library(dplyr)
library(readr)
library(ggplot2)
library(sf)
library(osmdata)
library(ggspatial)
library(glue)
library(httr)
library(units)
<- getbb("France métropolitaine", featuretype = "area")
fr_bbox
# GET("http://r.iresmi.net/wp-content/uploads/2021/12/adminexpress_simpl.gpkg_.zip",
# write_disk("~/adminexpress_simpl.gpkg_.zip"))
# dir.create("~/adminexpress")
# unzip("~/adminexpress_simpl.gpkg_.zip", exdir = "~/data/adminexpress")
<- read_sf("~/data/adminexpress/adminexpress_cog_simpl_000_2022.gpkg", layer = "region") |>
fr filter(insee_reg > "06")
# 6 hours
<- opq(fr_bbox, timeout = 600) |>
pool add_osm_feature(key = "leisure", value = "swimming_pool") |>
add_osm_feature(key = "access", value = "private") |>
osmdata_sf()
<- pool$osm_polygons |>
pool_p select(osm_id)
<- pool$osm_multipolygons |>
pool_mp select(osm_id)
rm(pool) ; gc()
# keep only pools in France (bbox was wider)
<- pool_p |>
pool_fr bind_rows(pool_mp) |>
st_filter(fr) |>
mutate(area = st_area(geometry))
# what resulting dimension ?
<- pool_fr |>
olympic_pool_dim st_drop_geometry() |>
summarise(total_area = drop_units(sum(area, na.rm = TRUE))) |>
mutate(width = 25,
length = total_area / width)
# rotate sf object
<- function(a) matrix(c(cos(a), sin(a), -sin(a), cos(a)), 2, 2)
rot
# create the pool, translate it in France and rotate
<- c(0, 0,
olympic_pool 0, olympic_pool_dim$length,
$width, olympic_pool_dim$length,
olympic_pool_dim$width, 0,
olympic_pool_dim0, 0) |>
matrix(ncol = 2, byrow = TRUE) |>
list() |>
st_polygon() |>
st_sfc(crs = "EPSG:2154") *
rot(pi / 4) +
c(400000, 6300000)
# map
|>
fr st_transform("EPSG:2154") |>
ggplot() +
geom_sf() +
geom_sf(data = st_sf(olympic_pool, crs = "EPSG:2154"), color = "blue") +
labs(title = "The giant French Olympic-size swimming pool",
subtitle = glue("What if all private swimming pools could be merged
into one 25 m width pool?"),
caption = glue("pool data from © OpenStreetMap contributors
map IGN Adminexpress
r.iresmi.net - {Sys.Date()}")) +
annotation_scale(height = unit(0.1, "cm")) +
theme_minimal() +
theme(panel.grid = element_blank(),
axis.text = element_blank())
Day 8 of 30DayMapChallenge: « Openstreetmap » (previously).
What if all private swimming pools could be merged into one 25 m width pool? OSM is not just a map, it’s a database, so ask OSM… I know that not all swimming pools are present in OSM, but it’s just an exercise 🙂 and it can give us an order of magnitude or at least a minimum.
We will use a simplified map of France in the background and ask to the Overpass API (with {osmdata}) all « leisure=swimming_pool » and « access=private ». It takes 6 hours and 15 Go of RAM…
We get an Olympic swimming pool (25 m width) measuring at least 755 km in length!