Summary and Schedule
This lesson is an introduction to working with raster and vector data in R for researchers in urbanism or related fields. After a brief introduction to R, it focuses on vector and raster data and their use in practical GIS operations on urban datasets.
The content of the workshop was adapted from the three lessons of Data Carpentry Geospatial workshop, as follows:
Stachelek, J., & Marwaha, K. (2023). datacarpentry/organization-geospatial: Data Carpentry: Introduction to Geospatial Concepts 2023-05 (2023.05) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.7897047
Stachelek, J., Njambi, S., Mahoney, M., sheila, Thomaz, A. T., Rasel, A. A., Pérez-Suárez, D., Koontz, E., Molloy, J., Jablonski, J., Fung, J., Leinweber, K., Sisk, M., Detomasi, R., Stevens, S. L., Stewart, S., Chen, S., & Ng, W. (2023). datacarpentry/r-intro-geospatial: Introduction to R for Geospatial Data 2023-05 (2023.05) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.7897052
Stachelek, J., Becker, E. A., Asberry, D., Strimas-Mackey, M., Rasel, A. A., Li, A., Avery, R., kcarini, Marwaha, K., mneilson-usgs, Sparks, A. H., bart1, Knudsen, C. B., Kerchner, D., Vanichkina, D. P., Pérez-Suárez, Jablonski, J., Liou, M., Morandeira, N., & Williams, R. (2023). datacarpentry/r-raster-vector-geospatial: Data Carpentry: Introduction to Geospatial Raster and Vector Data with R, February 2023 (v2023.02.06) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.7612769
Setup Instructions | Download files required for the lesson | |
Duration: 00h 00m | 1. Introduction to R and RStudio |
How can I find my way around RStudio? How can I manage projects in R? How can I install packages? How can I interact with R? |
Duration: 00h 50m | 2. Data Structures |
What are the basic data types in R? How do I represent categorical information in R? |
Duration: 01h 02m | 3. Exploring Data Frames & Data frame Manipulation with dplyr |
What is a data frame? How can I read data in R? How can I get basic summary information about my data set? How can I select specific rows and/or columns from a data frame? How can I combine multiple commands into a single command? How can I create new columns or remove existing columns from a data frame? |
Duration: 01h 14m | 4. Introduction to visualisation |
How can I create a basic plot in R? How can I add features to a plot? How can I get basic summary information about my data set? How can I include addition information via a colours palette. How can I find more information about a function and its arguments? How can I create new columns or remove existing columns from a data frame? |
Duration: 01h 26m | 5. Introduction to Geospatial Concepts |
How do I describe the location of a geographic feature on the surface of
the earth? What is coordinate reference system (CRS) and how do I describe different types of CRS? How do I decide on what CRS to use? |
Duration: 01h 38m | 6. Open and Plot Vector Layers | How can I read, examine and visualize point, line and polygon vector data in R? |
Duration: 02h 08m | 7. Explore and plot by vector layer attributes | How can I examine the attributes of a vector layer? |
Duration: 02h 58m | 8. Plot multiple shapefiles | How can I create map compositions with custom legends using ggplot? |
Duration: 03h 33m | 9. Handling Spatial Projections & CRS | What do I do when vector data don’t line up? |
Duration: 04h 03m | 10. Intro to Raster Data |
What is a raster dataset? How do I work with and plot raster data in R? ::: |
Duration: 04h 35m | 11. Plot Raster Data |
How can I create categorized or customized maps of raster data? How can I customize the colour scheme of a raster image? |
Duration: 05h 10m | 12. Reproject Raster Data | How do I work with raster data sets that are in different projections? |
Duration: 05h 42m | 13. Raster Calculations | How do I subtract one raster from another and extract pixel values for defined locations? |
Duration: 06h 12m | 14. Work with Multi-Band Rasters | How can I visualize individual and multiple bands in a raster object? |
Duration: 06h 37m | 15. Import and Visualise OSM Data | How to import and work with vector data from OpenStreetMap? |
Duration: 07h 47m | 16. Basic GIS operations with R and sf |
How to perform basic GIS operations with the sf package?
|
Duration: 08h 57m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
Overview
This workshop is designed to be run on your local machine. For this, you need to (i) download the geospatial data we use in the workshop and (ii) set up your machine with the software required to analyse and process the data. We provide installation instructions below for these steps. Please read carefully before installing anything!
Data
Download the data zip file and unzip it to your Desktop. The file is 67.5 MB.
Software
We provide quick instructions below for installing the various software needed for this workshop. They assume minimal familiarity with the command line and with installation in general. As there are different operating systems and many different versions of operating systems and environments, these may not work on your computer. If an installation doesn’t work for you, please refer to the installation instructions for that software listed in the table on the bottom of this page.
If you have previously installed these software on your computer, please make sure the versions used in the workshop match your installation. Using the latest versions of R, RStudio, R packages and external dependencies indicated in the setup instructions will ensure that the software we use behaves the same way on all computers during the workshop.
Note for MacOS users: The workshop is only testes for macOS 11 and above. If you have an older version please contact the workshop providers prior to the start of the workshop.
GDAL, GEOS, and PROJ.4
The installation of the geospatial libraries GDAL, GEOS, and PROJ.4
varies significantly based on operating system. These are all
dependencies for sf
, the R
package that we
will be using for spatial data operations throughout this workshop. If
you already have one of these libaries in your system, please make sure
to uninstall it before following the instructions below. Otherwise you
might have conflicts between your libraries. If uninstallation is not
possible, please join to the pre-workshop installation meeting.
To install the geospatial libraries GDAL, GEOS, and PROJ.4, install Rtools version 4.4 RTools
Install the geospatial libraries GDAL, GEOS, and PROJ.4 individually using homebrew. Open Terminal.app and run the following commands:
Steps for installing the geospatial libraries will vary based on
which form of Linux you are using. These instructions are adapted from
the sf
package’s
README
.
For Ubuntu:
BASH
$ sudo add-apt-repository ppa:ubuntugis
$ sudo apt-get update
$ sudo apt-get install libgdal-dev libgeos-dev libproj-dev
For Fedora:
For Arch:
For Debian: The rocker geospatial Dockerfiles may be helpful. Ubuntu Dockerfiles are found here. These may be helpful to get an idea of the commands needed to install the necessary dependencies.
UDUNITS
Linux users will have to install UDUNITS separately. Like the
geospatial libraries discussed above, this is a dependency for the
R
package sf
. Due to conflicts, it does not
install properly on Linux machines when installed as part of the
sf
installation process. It is therefore necessary to
install it using the command line ahead of time.
Steps for installing the geospatial will vary based on which form of
Linux you are using. These instructions are adapted from the sf
package’s
README
.
For Ubuntu:
For Fedora:
For Arch:
For Debian:
R
Participants who do not already have R
installed should
download and install the latest version. For those who already have R
installed, make sure to have at least version 4.4.0. If not, please
upgrade. You can check your R version by typing the following code in
your R console.
R
version[['version.string']]
To install R
, Windows users should select “Download R
for Windows” from RStudio and CRAN’s cloud download page, which will
automatically detect a CRAN mirror for you to use. Select the
base
subdirectory after choosing the Windows download page.
A .exe
executable file containing the necessary components
of base R can be downloaded by clicking on “Download R for Windows”.
To install R
, macOS users should select “Download R for
macOS” from RStudio and CRAN’s cloud download page, which will
automatically detect a CRAN mirror for you to use. A .pkg
file containing the necessary components of base R can be downloaded by
clicking on the first available link (this will be the most recent),
which will read R-4.x.x-arm64.pkg
for Apple silicon (M1/M2)
Macs and R-4.x.x-x86_64.pkg
for older Intel Macs.
To install R
, Linux users should select “Download R for
Linux” from RStudio and CRAN’s cloud download page, which will
automatically detect a CRAN mirror for you to use. Instructions for a
number of different Linux operating systems are available.
RStudio
RStudio is a GUI for using R
that is available for
Windows, macOS, and various Linux operating systems. It can be
downloaded here. You
will need the free Desktop version for your computer.
In order to address issues with ggplot2
, learners and
instructors should run a recent version of RStudio (v1.2 or
greater).
R Packages
The following R
packages are used in the various
geospatial lessons.
-
tidyverse
v.2.0 - this is a collection of packages for data science that contains thedplyr
andggplot2
packages we will use throughout the lessons. -
terra
v.1.7 -
sf
v1.0
To install these packages in RStudio, do the following:
1. Open RStudio by double-clicking the RStudio application icon. You
should see something like this:
2. Type the following into the console and hit enter.
R
install.packages(c("tidyverse", "terra", "sf"))
You should see a status message starting with:
OUTPUT
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/tidyverse_2.0.0.tgz'
Content type 'application/x-gzip' length 428470 bytes (418 KB)
==================================================
downloaded 418 KB
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/terra_1.7-55.tgz'
Content type 'application/x-gzip' length 97482563 bytes (93.0 MB)
==================================================
downloaded 93.0 MB
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/sf_1.0-14.tgz'
Content type 'application/x-gzip' length 86848420 bytes (82.8 MB)
==================================================
downloaded 82.8 MB
When the installation is complete, you will see a status message like:
OUTPUT
The downloaded binary packages are in
/var/folders/hk/0c_kwgjs1zlgczjlszxgq348281j_b/T//RtmpTmRDrL/downloaded_packages
You are now ready for the workshop!
Below is a summary table of what have been installed in your machine after following the instructions above. Please use this summary for reference and DO NOT install the software from it unless you encounter issues with the installation above. The links in the table provide more detailed software- and platform-specific information.
Software | Install | Manual | Available for | Description |
---|---|---|---|---|
GDAL | Link | Link | Linux, MacOS, Windows | Geospatial model for reading and writing a variety of formats |
GEOS | Link | Link | Linux, MacOS, Windows | Geometry models and operations |
PROJ.4 | Link | Link | Linux, MacOS, Windows | Coordinate reference system transformations |
R | Link | Link | Linux, MacOS, Windows | Software environment for statistical and scientific computing |
RStudio | Link | Linux, MacOS, Windows | GUI for R | |
UDUNITS | Link | Link | Linux, MacOS, Windows | Unit conversions |