bio photo

View All Tutorials

Workshop:
spatial-data-management-series

View ALL Tutorial Series




Github


Blog.Roll

R Bloggers

Overview

About

This lesson covers formats that CRS information may be in including proj4 and EPGS and how to work with them in R.

R Skill Level: Beginner - you’ve got the basics of R down.

Goals / Objectives

After completing this activity, you will:

*

Things You’ll Need To Complete This Lesson

To complete this lesson you will need the most current version of R, and preferably, RStudio loaded on your computer.

Install R Packages

  • NAME: install.packages("NAME")

More on Packages in R - Adapted from Software Carpentry.

Download Data


Set Working Directory: This lesson assumes that you have set your working directory to the location of the downloaded and unzipped data subsets. An overview of setting the working directory in R can be found here..

R Script & Challenge Code: NEON data lessons often contain challenges that reinforce learned skills. If available, the code for challenge solutions is found in the downloadable R script of the entire lesson, available in the footer of each lesson page.

Spatial-Temporal Data & Data Management Lesson Series: This lesson is part of a lesson series introducing spatial data and data management in R . It is also part of a larger spatio-temporal Data Carpentry Workshop that includes working with
raster data in R , vector data in R and
tabular time series in R .


Additional Resources

What is a Coordinate Reference System

To define the location of something we often use a coordinate system. This system consists of an X and a Y value, located within a 2 (or more) -dimensional (as shown below) space.

We use coordinate systems with X, Y (and sometimes Z axes) to define the location of objects in space. Source: http://open.senecac.on.ca

Coordinate Reference System Formats

There are numerous formats that are used to document a CRS. Three common formats include:

  • proj.4
  • EPSG
  • Well-known Text (WKT) formats.

PROJ or PROJ.4 strings

PROJ.4 strings are a compact way to identify a spatial or coordinate reference system. PROJ.4 strings are the primary output from most of the spatial data R packages that we will use (e.g. raster, rgdal).

Using the PROJ.4 syntax, we specify the complete set of parameters (e.g. ellipse, datum, units, etc) that define a particular CRS.

Understanding CRS in Proj4 Format

The CRS for our data are given to us by R in proj4 format. Let’s break down the pieces of proj4 string. The string contains all of the individual CRS elements that R or another GIS might need. Each element is specified with a + sign, similar to how a .csv file is delimited or broken up by a ,. After each + we see the CRS element being defined. For example +proj= and +datum=.

UTM Proj4 String

Our project string for point_HARV specifies the UTM projection as follows:

+proj=utm +zone=18 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0

  • +proj=utm: the projection is UTM, UTM has several zones.
  • +zone=18: the zone is 18
  • datum=WGS84: the datum WGS84 (the datum refers to the 0,0 reference for the coordinate system used in the projection)
  • +units=m: the units for the coordinates are in METERS.
  • +ellps=WGS84: the ellipsoid (how the earth’s roundness is calculated) for the data is WGS84

Note that the zone is unique to the UTM projection. Not all CRS will have a zone.

Geographic (lat / long) Proj4 String

Our project string for State.boundary.US and Country.boundary.US specifies the lat/long projection as follows:

+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0

  • +proj=longlat: the data are in a geographic (latitude and longitude) coordinate system
  • datum=WGS84: the datum WGS84 (the datum refers to the 0,0 reference for the coordinate system used in the projection)
  • +ellps=WGS84: the ellipsoid (how the earth’s roundness is calculated) is WGS84

Note that there are no specified units above. This is because this geographic coordinate reference system is in latitude and longitude which is most often recorded in Decimal Degrees.

Data Tip: the last portion of each proj4 string is +towgs84=0,0,0 . This is a conversion factor that is used if a datum conversion is required. We will not deal with datums in this particular series.

EPSG codes

The EPSG codes are a structured dataset of CRSs that are used around the world. They were originally compiled by the, now defunct, European Petroleum Survey Group, hence the EPSG acronym. Each code is a four digit number.

The codes and more information can be found on these websites:

  • The EPSG registry.
  • Spatialreference.org
  • list of ESPG codes.

    library(‘rgdal’) epsg = make_EPSG() # View(epsg) head(epsg)

    ## code note ## 1 3819 # HD1909 ## 2 3821 # TWD67 ## 3 3824 # TWD97 ## 4 3889 # IGRS ## 5 3906 # MGI 1901 ## 6 4001 # Unknown datum based upon the Airy 1830 ellipsoid ## prj4 ## 1 +proj=longlat +ellps=bessel +towgs84=595.48,121.69,515.35,4.115,-2.9383,0.853,-3.408 +no_defs ## 2 +proj=longlat +ellps=aust_SA +no_defs ## 3 +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs ## 4 +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs ## 5 +proj=longlat +ellps=bessel +towgs84=682,-203,480,0,0,0,0 +no_defs ## 6 +proj=longlat +ellps=airy +no_defs

WKT or Well-known Text

Well-known Text (WKT) allows for compact machine- and human-readable representation of geometric objects as well as to consisely describing the critical elements of coordinate reference system (CRS) definitions.

The codes and more information can be found on these websites:


##Additional Resources ESRI help on CRS QGIS help on CRS NCEAS cheatsheets


Get Lesson Code

(some browsers may require you to right click.)