GIS mapping with R

Marie-Hélène Burle

April 26, 2021


GIS concepts

Types of spatial data

Vector data

Discrete objects

Contain:  - geometry:  shape & location of the objects
    - attributes:  additional variables (e.g. name, year, type)

Common file format:  GeoJSON, shapefile

Examples: countries, roads, rivers, towns

Types of spatial data

Raster data

Continuous phenomena or spatial fields

Common file formats:  TIFF, GeoTIFF, NetCDF, Esri grid

Examples: temperature, air quality, elevation, water depth

Vector data

Types

  • point:       single set of coordinates
  • multi-point:   multiple sets of coordinates
  • polyline:      multiple sets for which the order matters
  • multi-polyline:  multiple of the above
  • polygon:      same as polyline but first & last sets are the same
  • multi-polygon:  multiple of the above

Raster data

Grid of equally sized rectangular cells containing values for some variables

Size of cells = resolution

For computing efficiency, rasters do not have coordinates of each cell, but the bounding box & the number of rows & columns

Coordinate Reference Systems (CRS)

A location on Earth’s surface can be identified by its coordinates & some reference system called CRS

The coordinates (x, y) are called longitude & latitude

There can be a 3rd coordinate (z) for elevation or other measurement—usually a vertical one

And a 4th (m) for some other data attribute—usually a horizontal measurement

In 3D, longitude & latitude are expressed in angular units (e.g. degrees) & the reference system needed is an angular CRS or geographic coordinate system (GCS)

In 2D, they are expressed in linear units (e.g. meters) & the reference system needed is a planar CRS or projected coordinate system (PCS)

Datums

Since the Earth is not a perfect sphere, we use spheroidal models to represent its surface. Those are called geodetic datums

Some datums are global, others local (more accurate in a particular area of the globe, but only useful there)

Examples of commonly used global datums:

  • WGS84 (World Geodesic System 1984)
  • NAD83 (North American Datum of 1983)

Angular CRS

An angular CRS contains a datum, an angular unit & references such as a prime meridian (e.g. the Royal Observatory, Greenwich, England)

In an angular CRS or GCS:

  • Longitude (\(\lambda\)) represents the angle between the prime meridian & the meridian that passes through that location

  • Latitude (\(\phi\)) represents the angle between the line that passes through the center of the Earth & that location & its projection on the equatorial plane

Longitude & latitude are thus angular coordinates

Projections

To create a two-dimensional map, you need to project this 3D angular CRS into a 2D one

Various projections offer different characteristics. For instance:

  • some respect areas (equal-area)
  • some respect the shape of geographic features (conformal)
  • some almost respect both for small areas

It is important to choose one with sensible properties for your goals

Examples of projections:

  • Mercator
  • UTM
  • Robinson

Planar CRS

A planar CRS is defined by a datum, a projection & a set of parameters such as a linear unit & the origins

Common planar CRS have been assigned a unique ID called EPSG code which is much more convenient to use

In a planar CRS, coordinates will not be in degrees anymore but in meters (or other length unit)

Projecting into a new CRS

You can change the projection of your data

Vector data won’t suffer any loss of precision, but raster data will

→  best to try to avoid reprojecting rasters: if you want to combine various datasets which have different projections, reproject vector data instead

GIS in R

Resources

Open GIS data

Free GIS Data: list of free GIS datasets

Books

Geocomputation with R by Robin Lovelace, Jakub Nowosad & Jannes Muenchow
Spatial Data Science by Edzer Pebesma & Roger Bivand
Spatial Data Science with R by Robert J. Hijmans
Using Spatial Data with R by Claudia A. Engel

Tutorial

An Introduction to Spatial Data Analysis and Visualisation in R by the CDRC

Resources

Website

r-spatial by Edzer Pebesma, Marius Appel & Daniel Nüst

CRAN package list

Analysis of Spatial Data

Mailing list

R Special Interest Group on using Geographical data and Mapping