[英]raster extract by attributes in R
I have been trying to create a new raster object that contains only a couple of values from an existing raster. 我一直在尝试创建一个新的栅格对象,它只包含现有栅格中的几个值。 I am using the class raster found here: https://www.ga.gov.au/products/servlet/controller?event=FILE_SELECTION&catno=71071 .
我正在使用此处找到的类栅格: https : //www.ga.gov.au/products/servlet/controller?event = FILE_SELECTION&catno = 71071 。
class : RasterLayer dimensions : 14902, 19161, 285537222 (nrow, ncol, ncell)
resolution : 0.002349, 0.002349 (x, y)
extent : 110, 155.0092, -45.0048, -9.999999 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
values : G:\Spatial data\environmental_layers\Australian data\Land cover\Class\DLCDv1_Class.tif
min value : 1
max value : 34
I have tried: 我努力了:
pr <- rasterToPoints(r) # but the file is to big
and 和
s <- r[r>30 & r<33] # but the file is to big
and 和
rc <- reclass(r, c(-Inf,30,NA, 31,32, 1, 33,Inf,NA))
which produces a raster with properties: 生成具有属性的栅格:
class : RasterLayer
dimensions : 14902, 19161, 285537222 (nrow, ncol, ncell)
resolution : 0.002349, 0.002349 (x, y)
extent : 110, 155.0092, -45.0048, -9.999999 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
values : C:\Users\Adam\AppData\Local\Temp\R_raster_tmp\raster_tmp_61931056968.grd
min value : 1
max value : 33
I thought this would produced a raster layer with values of NA and 1, but it has 33 values. 我认为这会产生一个值为NA和1的栅格图层,但它有33个值。 I have been struggling to find a way to 'extract by attribute' using R on such a large file.
我一直在努力找到一种方法来使用R在这么大的文件上“按属性提取”。 Does anyone have suggestions of how I could do this?
有没有人建议我怎么做?
reclassify()
may work for you with a very large raster, but you need to specify the "is" "becomes" matrix correctly. reclassify()
可能适用于非常大的栅格,但您需要正确指定“是”“变为”矩阵。 Though I am not exactly sure from your question whether this is in fact your goal when you say "raster extract." 虽然我不确定你的问题,当你说“光栅提取”时,这实际上是你的目标。
However, here is how to do the reclassification: 但是,以下是如何进行重新分类:
For example: 例如:
## Create sample raster with values from 0 to 9
r <- raster(nrow=100, ncol=100)
r[] <- trunc(runif(ncell(r))*10)
## Create reclassification table
## Set values 0 to 4 equal to 1
## Set values 5 to 9 equal to NA
isBecomes <- cbind(c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
c(1, 1, 1, 1, 1, NA, NA, NA, NA, NA))
r2 <- reclassify(r, rcl=isBecomes)
I have not tested this in a raster too large to fit in memory, however I believe that reclassify() may be able to handle this. 我没有在一个太大而不适合内存的栅格中测试过这个,但是我相信reclassify()可能能够解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.