Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to do zonal statistics / terrain analysis with polygon overlays - I achieved to get min / max like so:

library(raster)
library(rgdal)

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

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

extract(alt, gadm_sub, fun = max, na.rm = T, small = T, df = T)

But for slope / aspect I get this error which I don't grasp how to prevent:

extract(alt, gadm_sub, fun = function(x) terrain(x, opt = "aspect"), na.rm = T, small = T, df = T)
# > Fehler in FUN(X[[1L]], ...) : unbenutzte(s) Argument(e) (na.rm = TRUE)
share|improve this question
up vote 6 down vote accepted

Sry - that one was too easy.. For the record I'll post it here:

    library(raster)
    library(rgdal)

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

    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)
    extract(asp, gadm_sub, fun = mean, na.rm = T, small = T, df = T)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.