The giant French Olympic-size swimming pool

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

Michaël

Published

2022-11-08

Modified

2024-12-06

A photo of a swimmer

pool swimming – CC BY by VV Nincic

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…

library(dplyr)
library(readr)
library(ggplot2)
library(sf)
library(osmdata)
library(ggspatial)
library(glue)
library(httr)
library(units)

fr_bbox <- getbb("France métropolitaine", featuretype = "area")

# 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")

fr <- read_sf("~/data/adminexpress/adminexpress_cog_simpl_000_2022.gpkg", layer = "region") |> 
  filter(insee_reg > "06")

# 6 hours
pool <- opq(fr_bbox, timeout = 600) |>
  add_osm_feature(key = "leisure", value = "swimming_pool") |> 
  add_osm_feature(key = "access", value = "private") |> 
  osmdata_sf()

pool_p <- pool$osm_polygons |> 
  select(osm_id)
pool_mp <- pool$osm_multipolygons |> 
  select(osm_id)

rm(pool) ; gc()

# keep only pools in France (bbox was wider)
pool_fr <- pool_p |>   
  bind_rows(pool_mp) |> 
  st_filter(fr) |> 
  mutate(area = st_area(geometry)) 

# what resulting dimension ?
olympic_pool_dim <- pool_fr |> 
  st_drop_geometry() |> 
  summarise(total_area = drop_units(sum(area, na.rm = TRUE))) |> 
  mutate(width = 25,
         length = total_area / width)

# rotate sf object
rot <- function(a) matrix(c(cos(a), sin(a), -sin(a), cos(a)), 2, 2)

# create the pool, translate it in France and rotate
olympic_pool <- c(0, 0,
                  0, olympic_pool_dim$length, 
                  olympic_pool_dim$width, olympic_pool_dim$length,
                  olympic_pool_dim$width, 0,
                  0, 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())

We get an Olympic swimming pool (25 m width) measuring at least 755 km in length!

A map of a virtual swimming pool across France

The giant French Olympic-size swimming pool