Modern GeoSpatial Data Analysis in R

Research Fellow, International Institute of Tropical Agriculture (IITA)

Oluwafemi Oyedele

About me

Headshot of Dr. Maria Tackett

Workshop agenda

  • Intro (this section)

  • Getting to know vector data in R

  • Getting to know raster data in R

  • Getting your spatial data into R

  • Coordinate reference systems (CRS)

  • Mapping your spatial data

What is Spatial Data ?

  • Technically spatial can refer to non-earth based positions and geographic/geospatial is a subset

  • Spatial Data refers to geographic data in Space.

Point

Line

Polygon

Vector data also can have non-spatial variables

  • Points, lines and polygons can have associated, non spatial data

  • In the example below the non-spatial variables of coastline10 dataset are featurecla, scalerank, min_zoom.

Rows: 4,133
Columns: 4
$ featurecla <chr> "Coastline", "Coastline", "Coastline", "Coastline", "Coastl…
$ scalerank  <chr> "0", "0", "6", "0", "0", "6", "5", "5", "6", "6", "6", "6",…
$ min_zoom   <dbl> 0, 0, 5, 0, 0, 5, 3, 3, 6, 5, 5, 6, 5, 6, 3, 3, 6, 6, 0, 6,…
$ geometry   <LINESTRING [°]> LINESTRING (59.91603 -67.40..., LINESTRING (-51.…

Vector data comes in a variety of different file formats
  • Shapefiles

  • Geopackages

  • GeoJSON

Raster data comes in a variety of differnt file formats

  • IMG

  • TIF

  • SID

Most spatial processing and visualization can be done with these packages

  • {sf}

  • {raster}

  • {tmap} or {ggplot2}

  • {mapview} or {leaflet}

{sf}

A package for vector data

{raster}

For working with raster data (obviously!)

{tmap}

For creating static (and interactive!) maps

{mapview}

For creating interactive maps

Additional Packages for GeoSpatial Analysis

  • {ggspatial}

  • {leaflet}

  • {ggmap}

  • {tidycensus}

  • {rayshader}

  • {rgrass7}

  • {stars}

  • {geogrid}

Many of these packages (including {sf}) have non-R dependencies

Getting Geospatial Data Into R

Ways to get spatial data into R

  • Load external spatial files

  • Load or fetch data with specialized R packages

What function you use depends on the type of data

  • Read vector data with the {sf} package

  • Read raster data with the {raster} package

For vector data use read_sf() from {sf}

You can also use st_read() from {sf} but read_sf() is more “tidy”

  • stringsAsFactors = FALSE

  • quiet = TRUE

  • as_tibble = TRUE

read_sf() to read many different file format

  • Shapefiles

  • Geopackages

  • Geojson

  • Even databases!