Session Ready
Exercise

Extract raster values by location

Beyond simply masking and cropping you may want to know the actual cell values at locations of interest. You might, for example, want to know the percentage canopy at your landmarks or within the large parks. This is where the extract() function comes in handy.

Usefully, and you'll see this in a later analysis, you can feed extract() a function that will get applied to extracted cells. For example, you can use extract() to extract raster values by neighborhood and with the fun = mean argument it will return an average cell value by neighborhood.

Similar to other raster functions, it is not yet set up to accept sf objects so you'll need to convert to a Spatial object.

Instructions
100 XP
  • Project the landmarks points to match the canopy CRS. Both objects have been preloaded.
  • Convert landmarks_cp to a Spatial object with as and call this landmarks_sp.
  • Use the raster function extract() to determine the percentage tree canopy at each of the three points. Save this as landmarks_ex.
  • Look at the landmarks_cp and landmarks_ex objects in the console. Do the extract() results make sense? The canopy layer values represent percentage tree canopy.