These days, the recommendation is to use
sf (instead of
terra (instead of
sf package is great and should no
doubt be used instead of
sp. It drops easily into
ggplot2 and other packages.
terra may need to be converted to a raster for compatibility with
some packages or functions.
To crop a raster to the extent of relocations:
## Packages library(data.table) library(raster) library(rasterVis) library(ggplot2) ## Load data # DT is a data.table load('data/DT.rda') # DEM is a raster load('data/dem.rda') ## Plot # Plot raster and points gplot(dem) + geom_tile(aes(fill = value)) + geom_point(aes(X, Y), data = DT) ## Crop to points cropped <- crop(dem, DT[, as.matrix(cbind(X, Y))]) gplot(cropped) + geom_tile(aes(fill = value)) + geom_point(aes(X, Y), data = DT)
If you’d like to buffer the points first, use
Open sources: Open Street Map, Natural Earth, Canadian Government, Provincial Governments.
Examples of downloading and preparing spatial data from these sources in the study-area-figures repository (*-prep.R scripts). Packages used for downloading data include:
Recently from rOpenSci, Dilinie Seimon, Varsha Ujjinni Vijay Kumar highlighted many collections of open spatial data, from land cover to administrative boundaries and air pollution to malaria: https://rspatialdata.github.io/, https://ropensci.org/blog/2021/09/28/rspatialdata/
Calculating distance to something, eg. distance from moose relocations to the
nearest road, using Alec’s
It can be installed with the following code
install.packages('distanceto', repos = 'https://robitalec.r-universe.dev')
Here are the docs: https://robitalec.github.io/distance-to/