Session Ready
Exercise

Transform your layers to a common CRS

In the previous exercise, when you ran st_crs() and crs() you may have noticed that the CRS' were different for the different layers. The vector layer's CRS began with +proj=longlat and the raster layer's began with +proj=utm or +proj=aea. In order to use these layers together in spatial analysis we will want them to have the same CRS.

In this exercise you will transform (sometimes this is called "project") the objects so they share a single CRS. It is generally best to perform spatial analysis with layers that have a projected CRS (and some functions require this). To determine if your object has a projected CRS you can look at the first part of the result from st_crs() or crs() -- if it begins with +proj=longlat then your CRS is unprojected.

Note that you will use method = "ngb" in your call to projectRaster() to prevent distortion in the manhattan image.

Instructions
100 XP

sf and raster are loaded in your workspace.

  • Use the crs() function with argument asText = TRUE on the canopy layer to get the CRS as a string and save this as the_crs.
  • Use st_transform() to transform the vector trees object to the CRS in the_crs.
  • Use st_transform() to transform the vector neighborhoods object to the CRS in the_crs.
  • Use projectRaster() to transform the raster manhattan object to the CRS in the_crs. This will take a few seconds.
  • Use st_crs() on trees and neighborhoods, and crs() on manhattan to confirm that they now have the same CRS. They should all have a CRS that starts with +proj=aea.