# GIS mapping with R

April 26, 2021

## 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

## 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

## 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

## 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