Remember to download and set-up directory:

Load the following into browser window:

  • Projections figure from http://neondataskills.org/R/Introduction-to-Raster-Data-In-R/
  • Canopy Height Model figure from http://neondataskills.org/R/Raster-Calculations-In-R/

Set-up R Console:

library(raster)
library(rgdal)

raster structure, import, and plotting

dsm_harv <- raster("HARV_dsmCrop.tif")
dsm_harv
nbands(dsm_harv)
crs(dsm_harv)
plot(dsm_harv)
hist(dsm_harv)

raster math

dtm_harv <- raster("HARV_dtmCrop.tif")
chm_harv <- dsm_harv - dtm_harv

Do Tasks 1-2 from Exercise 1 - Canopy Height from Space.

Import and reproject shapefiles

plots_harv <- readOGR("plot_locations/", "HARV_plots")
plot(plots_harv, add=TRUE, pch=1, cex=2, lwd=2)
plots_harv
plots_harv_utm <- spTransform(plots_harv, crs(chm_harv))
plot(plots_harv_utm, add=TRUE, pch=1, cex=2, lwd=2)

Extract raster data

extract(chm_harv, plots_harv_utm)
extract(chm_harv, plots_harv_utm, buffer = 10, fun = mean)

Assign remainder of Exercise 1 - Canopy Height from Space.

Making your own point data

plot_latlong_data <- read.csv("data/NEON-airborne/plot_locations/HARV_PlotLocations.csv")
plot_latlong_data
crs_longlat <- crs("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
plot_latlong_data_spat <- SpatialPointsDataFrame(plot_latlong_data[c('long', 'lat')],
                                                    plot_latlong_data,
                                                    proj4string = crs_longlat)
str(plot_latlong_data_spat)
plot(plot_latlong_data_spatial)

Stacks of rasters

library(raster)
ndvi_files = list.files("data/HARV_NDVI/",
                         full.names = TRUE,
                         pattern = "HARV_NDVI.*.tif")
ndvi_files
ndvi_rasters <- stack(ndvi_files)
plot(ndvi_rasters)
plot(ndvi_rasters, seq(1, nlayers(ndvi_rasters), by = 2))
hist(ndvi_rasters)
avg_ndvi <- cellStats(ndvi_rasters, mean)
avg_ndvi_df <- data.frame(samp_period = seq_along(avg_ndvi), ndvi = avg_ndvi)
library(dplyr)
avg_ndvi_df <- tibble::rownames_to_column(avg_ndvi_df)

Exercise 2 - Phenology from Space.