如何通过将纬度、经度和海拔数据作为输入来计算坡度和纵横比值?

How to calculate slope and aspect ratio values by giving latitude, longitude and elevation data as input?

由于我对坡度的计算不太了解,谁能帮我提供可以计算坡度和纵横比值的代码?

我在文件中有纬度、经度和海拔值。 有什么方法可以得到这些值吗?

查了很多才知道R里面有一个叫"terrain"的函数,可以给出斜率和纵横比。但是我到处都有 nan 值。

使用一些虚拟数据:

library(raster)

long <- rep(rep(seq(12,36,0.5),41))
lat <-rep(seq(32,52,0.5), each=49)
dat <- rnorm(2009, 26.5, 44.0)

data <- data.frame(long, lat, dat)

rast <- rasterFromXYZ(data)
crs(rast) <- "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs "

slope <- terrain(rast,opt = 'slope', unit = 'degrees')
aspect <- terrain(rast, opt = 'aspect', unit = 'degrees')
flowdir <- terrain(rast, opt = 'flowdir')

spplot(stack(rast, slope, aspect, flowdir), scales = list(draw = T)) # the legend is not correct - only for demonstration purposes