Skip to content

Instantly share code, notes, and snippets.

View ahasverus's full-sized avatar

Nicolas Casajus ahasverus

View GitHub Profile
@ahasverus
ahasverus / montpellier_OSM_city_map.R
Created July 16, 2024 08:38 — forked from oliviergimenez/montpellier_OSM_city_map.R
Make a map of Montpellier with R and openstreetmap data
# code from https://gist.github.com/d-qn/4f1c4ed80a4fd6a76cd1153c89f56134
library(tidyverse)
library(sf)
library(osmdata) # to get openstreetmap geo data
# settings
# olivier: get data on Montpellier
bb <- getbb('Montpellier, France') # define the bbox, will be used to fetch OSM data within that box
dest_proj <- 2056
orthomap <- function(lon, lat) {
  g <- as_s2_geography(TRUE)
  co <- s2_data_countries()
  oc <- s2_difference(g, s2_union_agg(co)) # oceans
  co <- s2_difference(co, s2_union_agg(oc)) # land
  
  # visible half
  b <- s2_buffer_cells(as_s2_geography(paste0("POINT(", lon, " ", lat,")")),
                       distance = 9800000)