Skip to content

Instantly share code, notes, and snippets.

View rCarto's full-sized avatar
🛠️
...

Timothée Giraud rCarto

🛠️
...
View GitHub Profile
@rCarto
rCarto / zoom.R
Last active March 3, 2023 22:04
# load libraries
library(sf)
library(cartography)
library(rnaturalearth)
# import world countries and coastlines from Natural Earth
country <- ne_countries(scale = 50, returnclass = "sf",
type="sovereignty")
coastline <- ne_coastline(scale = 50, returnclass = "sf")
## Figure 1
#download the dev version of cartography
devtools::install_github("riatelab/cartography")
library(sf)
library(cartography)
mtq <- st_read(system.file("shape/martinique.shp", package="cartography"))
mt1 <- mtq[3,]
mt2 <- getPencilLayer(mt1, size = 1000, lefthanded = T, buffer = 2000)
png(filename = "fig1.png", width = 474, height = 132, res = 100)
par(mfrow=c(1,3), mar = c(0,0,0,0))
# load libraries
library(sf)
library(cartography)
library(cartogram)
## Import
# get the path to the shapefile embedded in sf package
shapepath <- system.file("shape/nc.shp",
package="sf")
# import the shapefile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
library(sf)
library(spatstat)
library(sp)
library(maptools)
library(raster)
library(cartography)
library(SpatialPosition)
## import dataset
feat <- sf::st_read("https://gist.githubusercontent.com/rCarto/747164575e3f216a123c3092d0ce9162/raw/f12390464f255b5f9760c577ab6bf5456cf61a40/iris75.geojson")
@rCarto
rCarto / mtq.R
Last active August 21, 2023 19:06
library(raster)
library(cartography)
library(sf)
library(SpatialPosition)
mtq <- st_read(system.file("shape/martinique.shp", package="cartography"))
# use WGS84 proj
mtq_latlon <- st_transform(mtq, 4326)
# this call throw an error but seems to work...
getData('SRTM', lon=-61, lat=14)
library(raster)
library(sf)
library(viridis)
library(cartography)
library(tanaka)
temp <- tempfile()
data_url <- "http://cidportal.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/GHS_POP_GPW4_GLOBE_R2015A/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k/V1-0/GHS_POP_GPW42015_GLOBE_R2015A_54009_1k_v1_0.zip"
download.file(data_url, temp)
unzip(temp, exdir = "pop")
library(rnaturalearth)
library(sf)
library(wbstats)
library(popcircle)
library(cartography)
# Get countries
ctry <- ne_countries(scale = 50, returnclass = "sf")
ctry <- st_transform(ctry, 54030)
library(sf)
library(cartography)
library(osrm)
# set osrm to my own server
options(osrm.server = "http://address.of.my.server/", osrm.profile = "driving")
# destination point (useR2019 conference in Toulouse)
dst <- data.frame(id="dst", x = 1.4344, y = 43.6113)
dst <- st_as_sf(dst, coords = c('x','y'), crs = 4326)
library(sf)
library(cartography)
library(png)
# import background image
if (!file.exists("img/background.png")) {
githubURL <- "https://raw.githubusercontent.com/gadenbuie/ggpomological/master/inst/images/pomological_background.png"
download.file(githubURL, "img/background.png")
}
img <- readPNG("img/background.png")
# import Communes of Martinique (sf dataframe within cartography package)