[英]How to compute the area or number of pixels for selected region in R?
我正在柵格文件上繪制一個區域,但我需要知道此框中覆蓋了多少像素(通過面積表示):柵格文件為1440 pixels*720 lines``(25km*25km)
。
例:
saf <- stack(system.file("external/rlogo.grd", package="raster"))
plotRGB( saf )
e <- drawExtent()
因此,在此之后我將e
繪制為一個框,但是面積為多少像素/多少? 謝謝
嘗試使用raster::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[]) )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.