Spatial image analysis in R

Given two images containing Hanover from 2012 and 2016. We compare them using the raster package.

Implementation

Load the raster package.

library(raster)

Load the first image (2012) and crop it to hanover.

r = raster("../images/BlackMarble_2012_C1_geo.tif")
r.hanover = crop(r,extent(c(9,10,52,53)))

Load the second image (2016) and crop it to hanover.

r2 = raster("../images/BlackMarble_2016_C1_geo.tif")
r2.hanover = crop(r2,extent(c(9,10,52,53)))

Set the output file (remove this in an interactive session).

pdf("plots.pdf") 

Plot Hanover at night in 2012.

plot(r.hanover, main="Hanover at night in 2012")
points(9.71730046412,52.375993496,pch=23,bg="red",col="red",cex=2) 

Plot Hanover at night in 2016.

plot(r2.hanover, main="Hanover at night in 2016")
points(9.71730046412,52.375993496,pch=23,bg="red",col="red",cex=2) 

Plot the difference.

plot(r.hanover - r2.hanover, main="Difference of Hanover at night")
points(9.71730046412,52.375993496,pch=23,bg="red",col="red",cex=2) 

Close the (current) plot.

dev.off();

Online Resources

Raster package - Geographic Data Analysis and Modeling

Author: Artem Leichter
Last modified: 2019-05-02