Remember to download and put into data subdirectory:

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("data/NEON-airborne/HARV_dsmCrop.tif")
nbands(dsm_harv)
crs(dsm_harv)
plot(dsm_harv)
hist(dsm_harv)

raster math

dtm_harv <- raster("data/NEON-airborne/HARV_dtmCrop.tif")
chm_harv <- dsm_harv - dtm_harv

Do Tasks 1-2 of Canopy Height from Space.

Import and reproject shapefiles

plots_harv <- readOGR("data/NEON-airborne/plot_locations", "HARV_plots")
plot(chm_harv)
plot(plots_harv, add = TRUE, pch = 4, cex = 1.5)
crs(chm_harv)
crs(plots_harv)
plots_harv_utm <- spTransform(plots_harv, crs(chm_harv))
plot(plots_harv_utm, add = TRUE, pch = 4, cex = 1.5)

Extract raster data

plots_chm <- extract(chm_harv, plots_harv_utm)
plots_harv_utm$plot_id
plots_chm <- data.frame(plot_num = plots_harv_utm$plot_id, plot_value = plots_chm)
plots_chm$plot_buffer_value <- extract(chm_harv, plots_harv_utm, buffer = 10, fun = mean)

Do Tasks 3-4 of Canopy Height from Space.

Stacks of rasters

ndvi_files = list.files("data/HARV_NDVI/",
                         full.names = TRUE,
                         pattern = "HARV_NDVI.*.tif")
ndvi_rasters <- stack(ndvi_files)
plot(ndvi_rasters)
plot(ndvi_rasters, c(1, 3, 5, 7, 9, 11))
avg_ndvi <- cellStats(ndvi_rasters, mean)
avg_ndvi_df <- data.frame(samp_period = 1:length(avg_ndvi), ndvi = avg_ndvi)
library(dplyr)
avg_ndvi_df <- tibble::rownames_to_column(avg_ndvi_df, var = "name")

Do Phenology from Space.

Making your own point data

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

Do Species Occurrences Elevation Histogram.

Map of point data

library(ggmap)
avg_long = mean(points_csv$long)
avg_lat = mean(points_csv$lat)
map = get_map(location = c(lon = avg_long, lat = avg_lat), zoom = 14)
ggmap(map) +
    geom_point(data = points_csv, aes(x = long, y = lat))