knitr::opts_chunk$set( collapse = TRUE, comment = "#>", error=TRUE )
Slides: https://nowosad.github.io/SIGR2021/workshop1/workshop1_rl.html#1
size of a sample dataset: - small enough to be fast - but with edge cases
You can have multiple datasets (small/large, differents areas)
Robin recommends to create an example dataset to save time. Documenting it is recommended but not mandatory.
ActDev example: know where to stop R: R is the backend, the webapplication to visualise the data is in JS.
library(help ="datasets") # full list of datasets
Listed datasets are available directly from R.
plot(trees)
plot(LakeHuron)
help(package = "spData")
?AirPassengers
library(spData) plot(nz) # if list error, maybe because sf is not loaded yet and plot don't know how to plot sf objects plot(nz$geom)
Make a copy to work on is good practice.
nz2 = nz plot(nz)
library(nzelect) nz_lonlat = sf::st_transform(nz, 4326) names(voting_places) # create points from coordinates voting_places_sf = sf::st_as_sf(voting_places, coords = c("longitude", "latitude")) plot(sf::st_geometry(nz_lonlat)) plot(voting_places_sf, add = TRUE)
Filtering voting places that are inside NZ island
vsub = voting_places_sf[nz,] # Error message because mismatching CRS issues
sf::st_crs(voting_places_sf, error=TRUE) # NA sf::st_crs(nz) # EPSG:2193
Voting_places_sf does not have a crs
Fixing issues
voting_places_sf <- sf::st_set_crs(voting_places_sf, st_crs(4326)) sf::st_crs(voting_places_sf) nz_lonlat <- sf::st_transform(crs = st_crs(4326)) vsub = voting_places_sf[nz_lonlat,]
plot(sf::st_geometry(nz_lonlat)) plot(vsub, add = TRUE)
Quite informal but very very rich Interesting when you can't access official data
Simple requests: {osmdata}
library(osmdata)
schools_nz_osm <- opq(bbox = sf::st_bbox(nz_lonlat)) %>% add_osm_feature(key = "amenity", value = "school")
skimr:skim
: resume data
source("https://raw.githubusercontent.com/Nowosad/SIGR2021/master/workshop1/osm_combine.R") # osm_combine() is available in the environnment
For large dataset (> 100 MB)
library(osmextract)
Needs a place name, and parameters (date type (e.g. "amenity") and an SQL query for the OSM server)
library(spData) library(sf) library(tidyverse) nz %>% filter(Island == "South")
rmapshaper::ms_simplify
st_is_valid()
: check if geometries are validst_make_valid()
: fixes geometriesdownload.file
readr
can read some ressourcesAdd the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.