2

The terrain function in R's raster package calculates slope and aspect from an elevation raster: see http://www.inside-r.org/packages/cran/raster/docs/terrain.

With the unit="degrees" option, the function returns aspect values in [0, 360]. Which way is north? Which way is west? I am not an arcgis user, but arcgis documentation says

Aspect identifies the downslope direction of the maximum rate of change in value from each cell to its neighbors. It can be thought of as the slope direction. The values of each cell in the output raster indicate the compass direction that the surface faces at that location. It is measured clockwise in degrees from 0 (due north) to 360 (again due north), coming full circle. Flat areas having no downslope direction are given a value of -1.

Is that standard? Does raster::terrain in R follow the same convention, i.e. do 0 and 360 both mean north?

Snippet of R code:

> library(raster)
> swiss_elevation <- getData('alt', country='CHE')
> raster_brick <- terrain(swiss_elevation, opt=c('slope', 'aspect'), unit='degrees')
> raster_brick$elevation <- swiss_elevation
> plot(raster_brick)
> summary(raster_brick$aspect[])
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
   0.00   88.58  179.60  183.60  283.70  360.00   81354 

This little example suggests that 0 is indeed north, 90 is east, et cetera:

library(raster)

test <- raster(ncols=100, nrows=100)
test[] <- 1
max_i <- 10
for(i in seq(max_i, 1)) {
    test[seq(50-i, 50+i), seq(50-i, 50+i)] <- max_i - i + 1  # "Mountain" at center of raster
}
plot(test)
plot(terrain(test, opt="aspect", unit="degrees"))  # What causes the bands?
plot(terrain(test, opt="slope"))

Does any of the R raster documentation point that out, or is it so obvious that it doesn't need to be stated?

  • 1
    It's not really north, zero is just "up the page". For some maps you need to correct for north at each pixel – mdsumner Jul 21 '16 at 16:55
  • @mdsumner Would the need for correction depend on the projection? Where is that documented? For a given projection, how can I know whether aspect=0 represents north? – Adrian Jul 21 '16 at 16:57
3

0 (and 360) represents North, as long as a pixel "above" another pixel is indeed north of it --- that is almost always the case. However, if you have a rotated data set (a rare thing) such that N is not up, you would have to apply that rotation to the output to get the true direction. This is not stated in the documentation because it seemed obvious, but apparently it is not, as is often the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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