如何计算R中选定区域的面积或像素数?
我正在光栅文件上绘制一个区域,但我需要知道此框中覆盖了多少像素(通过区域): 光栅文件是如何计算R中选定区域的面积或像素数?,r,raster,R,Raster,我正在光栅文件上绘制一个区域,但我需要知道此框中覆盖了多少像素(通过区域): 光栅文件是1440像素*720行``(25km*25km) 例如: saf <- stack(system.file("external/rlogo.grd", package="raster")) plotRGB( saf ) e <- drawExtent() saf尝试使用graster::crop crop(saf , e ) #class : RasterBr
1440像素*720行``(25km*25km)
例如:
saf <- stack(system.file("external/rlogo.grd", package="raster"))
plotRGB( saf )
e <- drawExtent()
saf尝试使用graster::crop
crop(saf , e )
#class : RasterBrick
#dimensions : 40, 50, 2000, 3 (nrow, ncol, ncell, nlayers)
#resolution : 1, 1 (x, y)
#extent : 23, 73, 26, 66 (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=merc
#data source : in memory
#names : red, green, blue
#min values : 0, 0, 0
#max values : 255, 255, 255
如果你只想知道细胞的数量
ncell( crop(saf , e ) )
#[1] 2000
为了消除NA
x <- crop( saf , e )
ncell( ! is.na(x[]) )
x我想另一种选择是ecrop@ZadSim对如果这不起作用,我希望能解释一下原因。我不喜欢留下未回答的问题。