Resources
Goals and Outcomes
- Summarize the functionality of modern R packages for handling spatial data.
- Discuss the retirement of
rgdal,rgeos, andmaptoolsand its effect on the rest of the spatial data ecosystem in R. - Provide additional resources for handling spatial data in R
sf
The sf R package (pebesma2018sf?) implements an R-based approach to handling spatial data based on simple features, a set of standards that specify how spatial objects are represented by computers. The simple features standards are widely implemented in spatial databases like GIS and GDAL. They have a geometry that describes their location on Earth using a coordinate reference system. Simple features objects in R are called sf objects and build upon R’s standard data frame by adding geometry. sf objects have two main components:
- A
data.framewith feature attributes - A list-column with geometries for each feature
You can operate on sf objects just as you would a operate on a data.frame, and there are many tidyverse operations (e.g., select(), filter()) that work directly with sf objects. All sf functions that operate on spatial data are prefixed by st_, which refers to spatial type. The prefix makes them easy to find via tab (or command-line) completion. For example, to inspect the sf function’s geometry as well-known text, run st_geometry().
The sf R package is the modern approach to manipulating spatial data in R using simple features and is designed to completely supersede sp. For more of sf, visit their website here or this overview here.
terra
The terra R package (hijmans2023terra?) is used to create, read, manipulate, and write raster data. Raster data is a spatial data structure that divides a region into rectangles called “cells” or “pixels” that can store one or more values fore each cell. Raster data structures are often called “grids”, a contrast with the “vector” data used to represent points, lines, and polygons as in the sf package. One advantage of the terra package and raster data structures is that it can handle large data sets on disk that are too large to be loaded into memory.
Raster objects in terra are typically created or read in using the rast() function. Raster objects in terra support common algebraic operations (e.g., +, *), logical operations (e.g., >=, ==), and functionals (e.g., round, log) on raster cells. There are several options for modifying raster objects: crop, which subsets a larger terra object; trim, which removes outer rows and columns with NA values; extend, which adds outer rows and columns with NA values, merge, which merges two or more raster objects into a single object; aggregate and disagg for changing the resolution (cell size) of a raster object; wrap for transforming to a new coordinate reference system; and more. There are also options for computing distances, summary statistics, prediction, and visualization.
The terra R package is the modern approach to manipulating raster data in R and is designed to completely supersede raster``. For more ofterra`, visit their website here.
Other Useful Spatial Data Packages
starsfor handling spatio-temporal vector and raster data (link here)leafletfor an R package that accesses leaflet, a population JavaScript library for interactive maps (link here)tmapfor generating thematic maps in R for (link here)mapviewfor a different approach to interacting with the leaflet Javascript library (link here)ggplot2for general graphics in R (link here), with a focus ongeom_sf()(link here)
Retirement of rgdal, rgeos, and maptools; Plan for sp
The rgdal, rgeos, and maptools R packages won’t be available on CRAN after October, 2023. Preparation for these retirements has been worked on for quite some time and is one of the motivating factors in pursuing modern alternatives like sf and terra. The sp package will still be available from CRAN, but it won’t be actively maintained, and sf should be used instead. To learn more about these retirements and understand how you may be affected, visit this link here.
R Spatial Resources
- Spatial Data Science With Applications in R
- R Spatial - Spatial Data Science with R
- Geocomputation with R
- R-Spatial Task View
- R-Spatial Website
- Modern Geospatial Data Analysis with R by Zev Ross **Spatial Statistics for Data Science: Theory and Practice with R
- SIGR2021 Summer School
- Spatial Data Science - Pebesma and Bivand
- Spatial Data Science Course- Prof. Adam Wilson
- Introduction to Mapping and Spatial Analysis with R
- R Spatial Workshop for EPA R User Group
- Intro to GIS and Spatial Analysis by Manuel Gimond
- FOSS4G2019 R for Geospatial Processing
- An Introduction to Spatial Analysis and Mapping in R
- Earth Analytics Spatial Data in R
- Hydroinformatics at VT: Extensive Notes and exercises for a course on data analysis techniques in hydrology using the programming language R
R Vector Processing / Simple Features Resources
R Raster Resources
R Mapping Resources
Web Services in R
General R Resources
Previous R Spatial Workshops
- ‘Working with Geospatial Hydrologic Data for Watershed Analyses in R and Python Using Web Services’ Workshop for the International Conference on the Watersheds
- AWRA 2022 Geospatial R and Python Workshop
- EPA R User Group Spatial Workshop 2021
- AWRA 2020 Spatial Analysis in R Workshop
- AWRA 2018 Geospatial R Workshop