我想要计算与保护区多边形重叠的物种的栖息地适宜性的百分比面积。我不太了解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
有没有人知道如何计算与保护区多边形重叠的栖息地适宜性的百分比面积?
对不起,我真的不知道如何处理这些数据。我希望我已经给出了所有相关的信息。
我将非常感谢您的任何意见。
发布于 2020-04-10 15:10:27
要回答您的第一个问题,您应该能够使用分区统计信息来计算使用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
https://stackoverflow.com/questions/61138130
复制相似问题