Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


A Coordinate Reference Systems (CRS) is a coordinate-based scheme use to locate entities in geographical space. It is an essential aspect of spatial data.

...

Examples on how to set and change the CRS of raster/polygon objects are provided below. The examples are taken from the “Effects of Cyclone Yasi on Green Cover at Mission Beach” tutorial. It can be beneficial to put the code snippets in context by looking at a broader section of the R script. Code snippets have a  Boxes with grey background contain code snippets, and outputs have a white backgroundboxes with white background containt code (text) outputs. For more details on CRS and CRS operations, see TERN.s DSDP "Using Raster Data in R" tutorial.

...

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
#==================================================================================
# Study Area
#==================================================================================

# Define Spatial 'Extent' of Study Area: Mission Beach backdrop
# --------------------------------------------------------------
StudyArea.extent = extent(146.0333, 146.0833, -17.9333, -17.8583)

# Create a working spatial structure from the spatial 'Extent'
# ------------------------------------------------------------
# Create a 'Spatial Polygon' from Spatial 'Extent'
StudyArea.SP = as(StudyArea.extent, "SpatialPolygons")
StudyArea.SP # Has not CRS


Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## class       : SpatialPolygons 
## features    : 1 
## extent      : 146.0333, 146.0833, -17.9333, -17.8583  (xmin, xmax, ymin, ymax)
## coord. ref. : NA

...

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Add a CRS. Use: EPSG:4326 = 'WGS84' - General Spatial Reference (https://spatialreference.org/ref/epsg/wgs-84/).
proj4string(StudyArea.SP) = CRS("+init=epsg:4326") # Add CRS
StudyArea.SP # Has a EPSG:4326 CRS


Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## class       : SpatialPolygons 
## features    : 1 
## extent      : 146.0333, 146.0833, -17.9333, -17.8583  (xmin, xmax, ymin, ymax)
## coord. ref. : +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0

...

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Reproject Rasters to EPSG:4326 (general spatial CRS with coordinates on the WGS84
# datum on the Stamen Maps)
# -----------------------------------------------------------------------------------
# SPGC Study Area 2010 Winter
SPGC.StudyArea.2010q3.reprj.rl = projectRaster(SPGC.StudyArea.2010q3.rl, crs=CRS("+init=epsg:4326"))
# SPGC Study Area 20101Winter
SPGC.StudyArea.2011q3.reprj.rl = projectRaster(SPGC.StudyArea.2011q3.rl, crs=CRS("+init=epsg:4326"))
# SGGC Study Area 2010 Winter
SGGC.StudyArea.2010q3.reprj.rl = projectRaster(SGGC.StudyArea.2010q3.rl, crs=CRS("+init=epsg:4326"))
# SGGC Study Area 2011 Winter
SGGC.StudyArea.2011q3.reprj.rl = projectRaster(SGGC.StudyArea.2011q3.rl, crs=CRS("+init=epsg:4326"))
# SPGC Study Area Difference between Winters of 2011 and 2010
SPGC.StudyArea.Diffq3.reprj.rl = projectRaster(SPGC.StudyArea.Diffq3.rl, crs=CRS("+init=epsg:4326"))
# SGGC Study Area Difference between Winters of 2011 and 2010
SGGC.StudyArea.Diffq3.reprj.rl = projectRaster(SGGC.StudyArea.Diffq3.rl, crs=CRS("+init=epsg:4326"))