堆叠栅格中的最大像元值


9

如何从堆叠栅格中找到最大像元值。

Rmax <- maxValue(RAD1998.all[[1]]) 

工作正常,但

Rmax <- maxValue(RAD1998.all[[2]]) 

给出NA。

当然不是在堆叠的栅格中。

这是我的代码:

RAD1998 <- raster(paste(getwd(), "/1998bil/1998ASC5min_ppt_spas1214_0001_19980202_0810_UTC.asc.bil", sep = ""))
list.ras <- mixedsort(list.files(paste(getwd(), "/1998bil/", sep = ""), full.names = T, pattern = ".asc.bil")) 
RAD1998.all <- stack(list.ras)

您是在寻找所有图层的最大值还是每个图层的最大值?无论如何,您没有使用maxValue正确的方法。根据帮助页面,您最好使用其他参数... Additional argument: layer number (for RasterStack or RasterBrick objects)

我正在寻找所有层的最大值以具有相同的比例,例如my.at <-seq(0,所有层的最大像元值,增量)。谢谢,Nahm
Nahm 2014年

我用cellStats#geostat-course.org/ system/files/ lewis_tutorAM.pdf Rad1998.max <-cellStats(RAD1998.all,'max')Rad1998.all.max <-max(Rad1998.max)Rad1998.all .max
Nahm 2014年

Answers:


9

以下示例显示了两种获取堆栈中最大栅格值的方法。第max()一种方法可以为您提供许多其他有用的信息。第二种方法使用maxValue(),它仅给出堆栈中两个栅格的最大值

library(raster)  

# Generate some georeferenced raster data
x = matrix(rnorm(400),20,20)
rast = raster(x)
extent(rast) = c(36,37,-3,-2)
projection(rast) = CRS("+proj=longlat +datum=WGS84")

y = matrix(rnorm(400),20,20)
rast2 = raster(y)
extent(rast2) = c(36,37,-3,-2)
projection(rast2) = CRS("+proj=longlat +datum=WGS84")

raster = stack(rast, rast2)

# Now run the statistics
max(raster) # Provides min, max and additional details  # Example 1

maxValue(raster)  # Gives both values                   # Example 2...
maxValue(raster)[[1]] # Gives first in stack max value
maxValue(raster)[[2]] # Gives second in stack max value

> maxValue(raster)  # Gives both values
[1] 2.688376 2.971443
> maxValue(raster)[[1]] # Gives first in stack max value
[1] 2.688376
> maxValue(raster)[[2]] # Gives second in stack max value
[1] 2.971443
> 
> max(raster) # Provides min, max and additional details
class       : RasterLayer 
dimensions  : 20, 20, 400  (nrow, ncol, ncell)
resolution  : 0.05, 0.05  (x, y)
extent      : 36, 37, -3, -2  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : layer 
values      : -1.457908, 2.971443  (min, max)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.