2.4 Coordinate Reference Systems

Vector and raster spatial data types share concepts intrinsic to spatial data.Perhaps the most fundamental of these is the Coordinate Reference System (CRS), which defines how the spatial elements of the data relate to the surface of the Earth (or other bodies).CRSs are either geographic or projected, as introduced at the beginning of this chapter (see Figure 2.1).This section will explain each type, laying the foundations for Section 6 on CRS transformations.

2.4.1 Geographic coordinate systems

Geographic coordinate systems identify any location on the Earth’s surface using two values — longitude and latitude.Longitude is location in the East-West direction in angular distance from the Prime Meridian plane.Latitude is angular distance North or South of the equatorial plane.Distances in geographic CRSs are therefore not measured in meters.This has important consequences, as demonstrated in Section 6.

The surface of the Earth in geographic coordinate systems is represented by a spherical or ellipsoidal surface.Spherical models assume that the Earth is a perfect sphere of a given radius.Spherical models have the advantage of simplicity but are rarely used because they are inaccurate: the Earth is not a sphere!Ellipsoidal models are defined by two parameters: the equatorial radius and the polar radius.These are suitable because the Earth is compressed: the equatorial radius is around 11.5 km longer than the polar radius (Maling 1992).13

Ellipsoids are part of a wider component of CRSs: the datum.This contains information on what ellipsoid to use (with the ellps parameter in the PROJ CRS library) and the precise relationship between the Cartesian coordinates and location on the Earth’s surface.These additional details are stored in the towgs84 argument of proj4string notation (see proj4.org/parameters.html for details).These allow local variations in Earth’s surface, for example due to large mountain ranges, to be accounted for in a local CRS.There are two types of datum — local and geocentric.In a local datum such as NAD83 the ellipsoidal surface is shifted to align with the surface at a particular location.In a geocentric datum such as WGS84 the center is the Earth’s center of gravity and the accuracy of projections is not optimized for a specific location.Available datum definitions can be seen by executing st_proj_info(type = "datum").

2.4.2 Projected coordinate reference systems

Projected CRSs are based on Cartesian coordinates on an implicitly flat surface.They have an origin, x and y axes, and a linear unit of measurement such as meters.All projected CRSs are based on a geographic CRS, described in the previous section, and rely on map projections to convert the three-dimensional surface of the Earth into Easting and Northing (x and y) values in a projected CRS.

This transition cannot be done without adding some distortion.Therefore, some properties of the Earth’s surface are distorted in this process, such as area, direction, distance, and shape.A projected coordinate system can preserve only one or two of those properties.Projections are often named based on a property they preserve: equal-area preserves area, azimuthal preserve direction, equidistant preserve distance, and conformal preserve local shape.

There are three main groups of projection types - conic, cylindrical, and planar.In a conic projection, the Earth’s surface is projected onto a cone along a single line of tangency or two lines of tangency.Distortions are minimized along the tangency lines and rise with the distance from those lines in this projection.Therefore, it is the best suited for maps of mid-latitude areas.A cylindrical projection maps the surface onto a cylinder.This projection could also be created by touching the Earth’s surface along a single line of tangency or two lines of tangency.Cylindrical projections are used most often when mapping the entire world.A planar projection projects data onto a flat surface touching the globe at a point or along a line of tangency.It is typically used in mapping polar regions.st_proj_info(type = "proj") gives a list of the available projections supported by the PROJ library.

2.4.3 CRSs in R

Two main ways to describe CRS in R are an epsg code or a proj4string definition.Both of these approaches have advantages and disadvantages.An epsg code is usually shorter, and therefore easier to remember.The code also refers to only one, well-defined coordinate reference system.On the other hand, a proj4string definition allows you more flexibility when it comes to specifying different parameters such as the projection type, the datum and the ellipsoid.14This way you can specify many different projections, and modify existing ones.This also makes the proj4string approach more complicated.epsg points to exactly one particular CRS.

Spatial R packages support a wide range of CRSs and they use the long-established PROJ library.Other than searching for EPSG codes online, another quick way to find out about available CRSs is via the rgdal::make_EPSG() function, which outputs a data frame of available projections.Before going into more detail, it’s worth learning how to view and filter them inside R, as this could save time trawling the internet.The following code will show available CRSs interactively, allowing you to filter ones of interest (try filtering for the OSGB CRSs for example):

  1. crs_data = rgdal::make_EPSG()
  2. View(crs_data)

In sf the CRS of an object can be retrieved using st_crs().For this, we need to read-in a vector dataset:

  1. vector_filepath = system.file("vector/zion.gpkg", package = "spDataLarge")
  2. new_vector = st_read(vector_filepath)

Our new object, new_vector, is a polygon representing the borders of Zion National Park (?zion).

  1. st_crs(new_vector) # get CRS
  2. #> Coordinate Reference System:
  3. #> No EPSG code
  4. #> proj4string: "+proj=utm +zone=12 +ellps=GRS80 ... +units=m +no_defs"

In cases when a coordinate reference system (CRS) is missing or the wrong CRS is set, the st_set_crs() function can be used:

  1. new_vector = st_set_crs(new_vector, 4326) # set CRS
  2. #> Warning: st_crs<- : replacing crs does not reproject data; use st_transform
  3. #> for that

The warning message informs us that the st_set_crs() function does not transform data from one CRS to another.

Examples of geographic (WGS 84; left) and projected (NAD83 / UTM zone 12N; right) coordinate systems for a vector data type.
Figure 2.13: Examples of geographic (WGS 84; left) and projected (NAD83 / UTM zone 12N; right) coordinate systems for a vector data type.

The projection() function can be used to access CRS information from a Raster* object:

  1. projection(new_raster) # get CRS
  2. #> [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

The same function, projection(), is used to set a CRS for raster objects.The main difference, compared to vector data, is that raster objects only accept proj4 definitions:

  1. projection(new_raster) = "+proj=utm +zone=12 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0
  2. +units=m +no_defs" # set CRS

Examples of geographic (WGS 84; left) and projected (NAD83 / UTM zone 12N; right) coordinate systems for raster data.
Figure 2.14: Examples of geographic (WGS 84; left) and projected (NAD83 / UTM zone 12N; right) coordinate systems for raster data.

We will expand on CRSs and how to project from one CRS to another in much more detail in Chapter 6.