简体   繁体   English

如何从R中的栅格列表中提取具有相同范围的栅格

[英]How to extract rasters with the same extent from a list of rasters in R

I have a list object made up of rasters and there are two types of rasters in it in terms of their extent.我有一个由栅格组成的列表对象,就其范围而言,其中有两种类型的栅格。 How can I extract the ones with the same extent and save them as a new list in R?如何提取具有相同范围的那些并将它们保存为 R 中的新列表? It is not possible to give a reproducible example but the code below can help you understand the question.不可能给出一个可重现的例子,但下面的代码可以帮助你理解这个问题。

A hypothetical example:一个假设的例子:

library(raster)
list_raster # Suppose this is a list having 48 rasters.
names(list_raster) <- paste0("raster", seq(1:48)) # Assigning names makes it possible to use the dollar sign.
lapply(list_raster, extent) # Gives 48 results but only two unique raster extents.
#  I would like to know which of the rasters has == extent(list_rasters$raster1)

You can use sapply :您可以使用sapply

same_as_r1 <- sapply(list_raster, function(x) extent(x) == extent(list_raster$raster1))

And subset your list with it:并用它子集您的列表:

group1 <- list_raster[same_as_r1]
group2 <- list_raster[!same_as_r1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM