R GIS: Terrain Analysis for Polygons as Simple as it Gets!

June 18, 2013
By

(This article was first published on theBioBucket*, and kindly contributed to R-bloggers)


library(rgdal)
library(raster)

alt <- getData('alt', country = "AT")
gadm <- getData('GADM', country = "AT", level = 2)
gadm_sub <- gadm[sample(1:length(gadm), 5), ]

plot(alt)
plot(gadm_sub, add=T)

asp <- terrain(alt, opt = "aspect", unit = "degrees", df = F)
slo <- terrain(alt, opt = "slope", unit = "degrees", df = F)

> extract(slo, gadm_sub, fun = mean, na.rm = T, small = T, df = T)
ID slope
1 1 9.959053
2 2 1.047443
3 3 7.456165
4 4 1.673786
5 5 11.946553

> extract(asp, gadm_sub, fun = mean, na.rm = T, small = T, df = T)
ID aspect
1 1 170.8065
2 2 184.0130
3 3 190.7155
4 4 136.8953
5 5 205.2115

To leave a comment for the author, please follow the link and comment on his blog: theBioBucket*.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.