在 ArcMap 和 r 中计算土地覆盖类型缓冲区时出现未知值

问题描述 投票:0回答:1

我正在尝试通过ArcMap和R计算2.5公里缓冲区内土地覆盖类型的百分比。当我使用Landscapemetric计算R中的缓冲区TIF时,计算出一个未知值。这些值为 10、30、40 和 50、60、80,这些都是土地覆盖数据中存在的值,但最后一个值为 128,该值不存在。我相信这可能是一个背景值,但我不确定。如果有人知道如何删除这个值,这样它就不会出现在我的计算中,那就太棒了。

Land cover calculations buffer zone

我使用景观计量学来计算土地覆盖缓冲区,我认为这会给出缓冲区上显示的值。结果给了我一个额外的未知值。

r buffer landscape arcmap
1个回答
0
投票

出现这些值是因为像素的正方形形状导致缓冲区的圆形不完美。圆形缓冲区边界往往会切断边缘像素,从而将其变成 NA 或其他值。

以下是通过缓冲区剪切栅格以显示缺失边界像素的示例。

为了避免这些值,您可以仅计算您对缓冲区感兴趣的有效类的百分比。

仅使用 R,您可以使用缓冲区提取栅格图层的值,并计算每个类相对于总数的像素数,应用简单的三规则来访问其百分比。从这个意义上说,您计算的是您感兴趣的所有类别的百分比,而不是整个景观(或缓冲区)的百分比,因此您不会获得您不感兴趣的值。

我举了一个示例,说明您需要在数据集中执行哪些操作才能实现计算景观栅格图像缓冲区剪切内的景观类别百分比的目标。

#packages
library(raster)
library(rgeos)

#an example of raster file with utm projection (to meters)
r = raster(nrow=10000, ncol=10000)
values(r) = sample(10, ncell(r), replace = TRUE)

#Important adjust the zone to your zone to project correctly
crs(r) = "+proj=utm +zone=20 +datum=WGS84 +units=m +no_defs"

#a point to create a buffer example 
pt <- SpatialPoints(data.frame(xx = 50, yy = 10))

#project the point to utm. Need to be in the same projection of the raster, utm to calculate the buffer in meters
proj4string(pt) = CRS("+proj=utm +zone=20 +datum=WGS84 +units=m +no_defs")

#making a buffer. In your case just read your buffer if already done (terra package is a good choice)
ptb  = gBuffer(pt, width = 25)

plot(r, legend = FALSE)
plot(ptb, add = TRUE)

#extract the raster values inside the buffer boundaries
buf_ex = unlist(extract(r, ptb))
#here we have only the valid classes values of the first buffer figure in this answer.

#now we construct a loop to calculate the percentages for each class (ps: maybe apply family offer a better option)
perc = data.frame(class = sort(unique(buf_ex)))
for(i in 1:nrow(perc)){
  #calculate the percentage of by the number of pixels
  perc[i, "percentage"] = length(buf_ex[buf_ex%in%i])*100/length(buf_ex)
}

data.frame“perc”将在“percentage”列中显示缓冲区中每个类别的百分比。

如果您对类区域或特定类区域感兴趣,只需将像素大小乘以每个类中的像素数量即可。

© www.soinside.com 2019 - 2024. All rights reserved.