【发布时间】:2020-11-06 02:42:20
【问题描述】:
我有一个高度聚集的点 shapefile(“search_effort.shp”)和一个 NDVI 栅格(分辨率以 m 为单位:30.94948、30.77829)。我想通过为每个栅格网格单元选择 1 个点来对我的 search_effort.shp 进行子集化,并创建一个新的 search_effort shapefile。我正在使用 R 版本 4.0.3
我想我可以使用包“gridsample”(在“raster”v1.3-1 中),但它已从 CRAN 存储库中删除,我不想使用存档版本。在 R 中还有其他方法可以做到这一点吗?
我也尝试过 sample.grid 但我不知道如何将我的栅格指定为网格,并尝试了以下方法:
# NDVI raster to be used as the reference extent
NDVI_extent <-readGDAL('C:/Model_layers/NDVI.tif')
# Load the file names
layername <- "SearchEffort"
# Read in the shapefile
search_effort <- readOGR(dsn= ".", layer = layername)
plot(search_effort)
# Set the reference extent
r <- raster(NDVI_extent)
# Extract coordinates from the shapefile
search_effort@coords <- search_effort@coords[, 1:2]
#Subset points
sample.grid(search_effort, cell.size = c(30.94948, 30.77829), n = 1)
我收到以下错误: “validObject(.Object) 中的错误:无效的类“GridTopology”对象:cellsize 的尺寸不正确。” 无论我指定的 cell.size 是什么,我都会收到相同的错误。
【问题讨论】: