Tidy geographic data

with sf, dplyr, ggplot2, geos and friends

Introduction

Session overview

Source: pretalx.earthmonitor.org/opengeohub-summer-school-2023/schedule/v/0.7/

About me

  • Associate Professor, University of Leeds
  • Head of Data and Digital at Active Travel England
  • Author of Geocomputation with R
  • Research: geocomputation + transport decarbonisation
  • Research question: where to build bike lanes?

Source: www.npt.scot

From research to impact

Geocomputation to tackle the climate crisis

System dependencies

Source: Pebesma (2018)

System dependencies: code

  • sf startup message:
sf::sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
      "3.10.2"        "3.4.1"        "8.2.1"         "true"         "true" 
          PROJ 
       "8.2.1" 
  • On Linux sf uses system installations of GDAL, GEOS and PROJ.4:
gdalinfo --version
which gdal-config
GDAL 3.4.1, released 2021/12/27
/usr/bin/gdal-config
  • On Windows, sf ships with binary versions installed

Development environments

RStudio

  • Pro: works out of the box
  • Pro: Great R autocomplete
  • Pro: Features for data science + R package development
  • Con: A bit R specific

VS Code

  • Pro: Works with many languages
  • Pro: Unbeatable ecosystem of extensions
  • Pro: Advanced features such as copilot + works in Codespaces
  • Con: A bit fiddly to set up, rough edges when using R

RStudio

VS Code

Which IDE to you use?

Results

  • On Twitter:

  • On Mastodon:

On Mattermost

Mattermost results

Mattermost results 2…

Part 1: Sections 2 and 3

Key features of sf

Source: Lovelace, Nowosad, and Muenchow (2019)

sf functions

Source: Pebesma (2018)

Practical (~13:30-14:30)

Work through the code in Section 2 and 3 at ogh23.robinlovelace.net/tidy and answer the questions at your own pace.

remotes::install_github("robinlovelace/opengeohub2023")
sapply(pkgs, require, character.only = TRUE)
       sf tidyverse      geos    spData 
     TRUE      TRUE      TRUE      TRUE 

Part 2: Sections 4 to 7

geos

rsgeo

rsgeo II

tidyverse alternatives

Comparing R with Python

Inspiration: Working with Spatial Data in Python materials

Vector data in R/Python

Aim: cross-compare approaches

Source: Python version and R version

References

Lovelace, Robin, Jakub Nowosad, and Jannes Muenchow. 2019. Geocomputation with R. CRC Press. https://r.geocompx.org/.
Pebesma, Edzer. 2018. “Simple Features for R: Standardized Support for Spatial Vector Data.” The R Journal. https://journal.r-project.org/archive/2018/RJ-2018-009/index.html.