计算保护区多边形与预测的最大栖息地适宜性的重叠



我想计算与保护区多边形重叠的物种的栖息地适宜性百分比。我不太懂R语言,但这是我迄今为止所掌握的。

这些是根据最大预测得出的栖息地适宜性区域的属性:

class      : RasterLayer 
dimensions : 6480, 8520, 55209600  (nrow, ncol, ncell)
resolution : 0.008333333, 0.008333333  (x, y)
extent     : -103, -32, -36, 18  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +ellps=WGS84

保护区:

Simple feature collection with 5667 features and 2 fields (with 8 geometries empty)
geometry type:  GEOMETRY
dimension:      XY
bbox:           xmin: -118.6344 ymin: -59.85538 xmax: -25.29094 ymax: 32.48333
CRS:            +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0

有人知道如何计算与保护区多边形重叠的栖息地适宜性百分比吗?

对不起,我真的不太了解如何处理这些数据。我希望我提供了所有相关信息。

如有任何意见,我将不胜感激。

要回答您的第一个问题,您应该能够使用区域统计数据来计算使用spatialEco软件包在保护区内发现的潜在栖息地面积:

zonal.stats(x, y, stats = c("min", "mean", "max"))
#x = Polygon object of class SpatialPolygonsDataFrame
#y = rasterLayer object of class raster

https://www.rdocumentation.org/packages/spatialEco/versions/1.3-0/topics/zonal.stats

这里是来自spatialEco包的可再现示例,该示例首先计算每个多边形中像素的百分比>=阈值,其次计算每个多边形的像素的总和>=用于重新分类输入光栅的阈值。你可能对这两种工作方式都感兴趣。

library(spatialEco)    
library(raster)
library(sp)                                                                          
# here the fxn will calculate the percentage of cells >= 0.5
# percent x >= p function
pct <- function(x, p=0.50, na.rm = FALSE) {
if ( length(x[x >= p]) < 1 )  return(0) 
if ( length(x[x >= p]) == length(x) ) return(1) 
else return( length(x[x >= p]) / length(x) ) 
}
# create some example data
p <- raster(nrow=10, ncol=10)
p[] <- runif(ncell(p)) * 10
p <- rasterToPolygons(p, fun=function(x){x > 9})
r <- raster(nrow=100, ncol=100)
r[] <- runif(ncell(r)) 
plot(r)
plot(p, add=TRUE, lwd=4) 
# run zonal statistics using pct functions  
z.pct <- zonal.stats(x=p, y=r, stats = "pct")
z.pct
#Alternatively, reclassify the raster based on a threshold
r.c<-reclassify(r, c(-Inf, 0.5, 0, 0.5, Inf, 1)) #all values >0.5 reclassified to 1
plot(r.c)
plot(p, add=TRUE, lwd=4) #add poly to the plot
# run zonal stats and calculate sum of cells in each poly
z.sum <- zonal.stats(x=p, y=r.c, stats = "sum")
z.sum

最新更新