Skip to content

Instantly share code, notes, and snippets.

View graticules.md
library(mapsf)
#> Le chargement a nécessité le package : sf
#> Linking to GEOS 3.7.1, GDAL 3.1.2, PROJ 7.1.0
mtq <- mf_get_mtq()
mf_theme("nevermind")
mf_map(mtq, graticule = st_crs(4326), 
       axes = TRUE, 
       lon = seq(-60,-62, by=-.2), 
       lat = seq(14, 15, by = .2))
View osrm.R
library(sf)
library(osrm)
library(maptiles)
# build a bbox for Paris
bb <- st_bbox(c(xmin = 643069, ymin = 6857478,
xmax = 661079, ymax = 6867081),
crs = 2154)
# get map tiles
osm <- get_tiles(x = bb, provider = "CartoDB.PositronNoLabels",
crop = TRUE, zoom = 13)
View bang.R
library(sf)
library(elevatr)
library(raster)
library(tanaka)
# a polygon of bangalore
bangalore <- st_read("export.geojson")
elevation <- get_elev_raster(bangalore, z = 10)
bangalore_elevation <- trim(mask(elevation, bangalore))
# inspect min and max values
View lakes.R
library(rnaturalearth)
library(cartography)
library(sf)
lakes <- ne_download(scale = 10, type = "lakes", category = c("physical"),
destdir = tempdir(), load = TRUE, returnclass = c("sf"))
countries <- ne_download(scale = 10, type = "countries",
category = c("cultural"), destdir = tempdir(),
load = TRUE, returnclass = c("sf"))
countries <- st_transform(countries, "ESRI:54017")
View points.R
library(units)
library(sf)
library(cartography)
# library(osmdata)
#
# # define a bounding box
# q0 <- opq(bbox = c(2.2247, 48.8188, 2.4611, 48.9019))
#
# # extract Paris boundaries
View plot.R
library(sf)
nc = st_read(system.file("shape/nc.shp", package="sf"))
nc <- st_transform(nc, 32119)
# regular grid 512096 polygons
grid <- st_make_grid(x = nc, cellsize = 500)
t0 <- Sys.time()
plot(st_geometry(nc))
plot(grid, add = TRUE)
# end of the second plot
View mapbox.md
library(cartography)
library(sf)
#> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0

# create an sf object centered on Tizi Ouzou city
tizi <- data.frame(name = "Tizi Ouzou", longitude = 4.06, latitude = 36.71)
tizi <- st_as_sf(tizi, coords = c("longitude", "latitude"), crs = 4326)
tizi <- st_transform(tizi, 3857)
tizi <- st_buffer(tizi, 5000)
View interactiveposition.R
library(cartography)
library(sf)
mtq <- st_read(system.file("gpkg/mtq.gpkg",
package="cartography"))
bks <- getBreaks(v = mtq$MED, nclass = 5,
method = "quantile")
cols <- carto.pal(pal1 = "turquoise.pal", n1 = 5)
choroLayer(x = mtq, var = "MED",
breaks = bks, col = cols,
View localpeaks.R
library(SpatialPosition)
library(raster)
data(hospital)
# Compute Stewart potentials from known points (hospital) on a
# grid defined by its resolution
pot <- stewart(knownpts = hospital, varname = "capacity",
typefct = "exponential", span = 750, beta = 3,
resolution = 100, mask = paris)
# Create a raster of potentials values
ras <- rasterStewart(x = pot)
View carto_facet.R
# World basemap
download.file(url = "https://raw.githubusercontent.com/riatelab/basemaps/master/World/countries.geojson",
destfile = "country.geojson")
# Graticules layer
download.file(url = "https://raw.githubusercontent.com/riatelab/basemaps/master/World/graticule30.geojson",
destfile = "graticule.geojson")
# Population data base
download.file(url = "https://population.un.org/wup/Download/Files/WUP2018-F12-Cities_Over_300K.xls",
destfile = "citypop.xls")