Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 3 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
add comment

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.