NEON EDUCATION bio photo

NEON EDUCATION

Devoted to open data and open source in science and education.

View All Tutorials

This tutorial is a part of a series!

Click below to view all lessons in the series!

Tags

LiDAR (9)
R programming (70)
Remote Sensing (12)
Data Visualization (4)
Hyperspectral Remote Sensing (7)
Hierarchical Data Formats (HDF5) (24)
Spatial Data & GIS (18)
Time Series (15)
Phenology (7)
Raster Data (8)
Vector Data (6)
Metadata (1)
Git & GitHub (6)
(1) (1) (1)

Tutorial by R Package

dplyr (8)
ggplot2 (17)
h5py (1)
lubridate (time series) (6)
maps (1)
maptools (3)
plyr (2)
raster (32)
rasterVis (raster time series) (3)
rgdal (GIS) (23)
rgeos (5)
rhdf5 (21)
sp (7)
scales (4)
gridExtra (4)
ggtheme (0)
grid (2)
reshape2 (3)
plotly (6)

View ALL Tutorial Series




Twitter Youtube Github


Blog.Roll

R Bloggers

About

In this tutorial, we will walk through how to create a hillshade from terrain rasters in R.

First, let’s load the required libraries.

# load libraries
library(raster)
library(rgdal)

# be sure to set your working directory
# setwd("~/Documents/data/NEONDI-2016") # Mac
# setwd("~/data/NEONDI-2016")  # Windows


## import functions
# install devtools (only if you have not previously intalled it)
#install.packages("devtools")
# call devtools library
#library(devtools)

# install from github
#install_github("lwasser/neon-aop-package/neonAOP")
# call library
library(neonAOP)


#source("/Users/lwasser/Documents/GitHub/neon-aop-package/neonAOP/R/aop-data.R")

Import LiDAR data

To begin, we will open the NEON LiDAR Digital Surface and Digital Terrain Models (DSM and DTM) which are in GeoTIFF format.

# read LiDAR data
# dsm = digital surface model == top of canopy
dsm <- raster("NEONdata/D17-California/TEAK/2013/lidar/TEAK_lidarDSM.tif")
# dtm = digital terrain model = elevation
dtm <- raster("NEONdata/D17-California/TEAK/2013/lidar/TEAK_lidarDTM.tif") 

# lets also import the canopy height model (CHM).
chm <- raster("NEONdata/D17-California/TEAK/2013/lidar/TEAK_lidarCHM.tif")



slope <- terrain(dsm, opt='slope')
aspect <- terrain(dsm, opt='aspect')
# create hillshade
# numbers 
dsm.hill <- hillShade(slope, aspect, 
                      angle=40, 
                      direction=270)

plot(dsm.hill,
     col=grey.colors(100, start=0, end=1),
     legend=F)
# overlay CHM on top of hillshade
plot(chm,
     add=T,
     alpha=.4)

Export Classified Raster

Now we can export the hillshade raster as a GeoTIFF.

# export geotiff 
writeRaster(dsm.hill,
            filename="outputs/TEAK/TEAK_dsm_hill.tif",
            format="GTiff",
            options="COMPRESS=LZW",
            overwrite = TRUE,
            NAflag = -9999)

Get Lesson Code

(some browsers may require you to right click.)