Neon canopy height from space (solution)

Exercise
Output solution
Loading required package: abind
Loading required package: sf
Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

1 Map the digital terrain model for SJER using the viridis color ramp.

2 Create and map the canopy height model for SJER using raster math (chm = dsm - dtm) and the viridis color ramp.

3 Create a map that shows the SJER boundary and the plot locations colored by plot type.

  1. Transform the plot data to have the same CRS as the CHM and create a map that shows the canopy height model from (3) with the plot locations on top.

  1. Extract the mean canopy heights at each plot location for SJER and display the values.
[1] 18.913757 23.948151  1.986877  2.183136 28.985016  3.506866  2.201233
  1. Add the canopy height values from (5) to the spatial data frame you created for the plots and display the full data frame.
Simple feature collection with 7 features and 3 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 256238.5 ymin: 4110088 xmax: 257465.5 ymax: 4111372
Projected CRS: WGS 84 / UTM zone 11N
# A tibble: 7 × 4
  plot_id plot_type             geometry canopy_heights
*   <dbl> <chr>              <POINT [m]>          <dbl>
1       1 Tower       (257465.5 4111372)          18.9 
2       2 Tower       (256238.5 4110270)          23.9 
3       3 Tower       (256798.3 4110296)           1.99
4       4 Distributed (256737.7 4110949)           2.18
5       5 Distributed (257358.5 4110450)          29.0 
6       6 Distributed (256254.5 4110088)           3.51
7       7 Distributed (256754.5 4110274)           2.20
  1. Create a map that shows the SJER boundary and the plot locations colored by the canopy height values.

  1. Create a map that shows the canopy height model raster, but in cm rather than m (i.e., multiply the canopy height model by 100).

  1. Create a map that shows the digital terrain model (DTM) raster, the plot locations, and the SJER boundary, using transparency as needed to allow all three layers to be seen. Remember all three layers will need to have the same CRS.

  1. Conduct an analysis of the relationship between elevation and canopy height at the SJER plots. Using a 50m buffter, extract the mean elevations (i.e., the values from the digital terrain model) and the canopy heights at each plot location for SJER and add to the spatial plots data to produce a simple features object that includes both the average elevations (in a 50 m buffer) and the canopy heights (in a 50 m buffer). Then make a scatter plot showing the relationship between elevation and canopy height using this data. Color the points by plot type and fit a single smooth curve through all of the points. Finally, use dplyr to calculate the average canopy height and average elevation for the two different plot types.
`geom_smooth()` using formula = 'y ~ x'

Simple feature collection with 2 features and 3 fields
Geometry type: MULTIPOINT
Dimension:     XY
Bounding box:  xmin: 256238.5 ymin: 4110088 xmax: 257465.5 ymax: 4111372
Projected CRS: WGS 84 / UTM zone 11N
# A tibble: 2 × 4
  plot_type   elevation canopy_height                                   geometry
  <chr>           <dbl>         <dbl>                           <MULTIPOINT [m]>
1 Distributed      383.          2.06 ((256254.5 4110088), (256737.7 4110949), …
2 Tower            386.          2.63 ((256238.5 4110270), (256798.3 4110296), …