我正在使用来自 USGS Earth Explorer 的 SRTM 数据(场景 ID:n03_e036_1arc_v3)。我使用 terra 包中的地形函数在 R 中绘制了海拔、坡度和坡向。前两个看起来很完美,但就方面而言,我更希望它计算西部大型水体的 NA,或某个任意数字,如 0。相反,它会产生奇怪的模式,如图所示:
areaDEM <- raster('DEM/dem.tif')
areaDEM <- projectRaster(areaDEM, crs = crs)
area_dem <- focal(areaDEM, w = matrix(1,15,15), fun = mean, NAonly = TRUE, na.rm = TRUE)
slope <- terrain(area_dem, opt = 'slope', unit = 'degrees') # calculate slope
aspect <- terrain(area_dem, opt = 'aspect', unit = 'degrees') # calculate aspect
我马上想到问题可能出在计算坡度和坡向之前进行投影步骤。这确实大大改变了输出,但是为湖计算的模式仍然非常奇怪:
areaDEM <- raster('DEM/dem.tif')
area_dem <- focal(areaDEM, w = matrix(1,15,15), fun = mean, NAonly = TRUE, na.rm = TRUE)
slope <- terrain(area_dem, opt = 'slope', unit = 'degrees') # calculate slope
aspect <- terrain(area_dem, opt = 'aspect', unit = 'degrees') # calculate aspect
# join elevation, slope and aspect into a single object
dem <- stack(area_dem, slope, aspect)
names(dem) <- c('elevation', 'slope', 'aspect')
dem <- projectRaster(dem, crs = crs)