有没有一种方法可以计算空间线周围缓冲区内的道路密度(km/km²)?这些道路由光栅中的像素表示(1像素=625平方米)。因此,我开始使用函数rasterToContour
(包raster)
将道路像素转换为折线。然后,我考虑计算缓冲区内线段的总长度(以公里为单位)和缓冲区面积(以平方公里为单位)。
r <- raster(rast_path)
x <- rasterToContour(r)
这是一个可重现的例子:
## To create raster:
library(raster)
library(rgeos)
r <- raster(ncols=90, nrows=50)
values(r) <- sample(1:10, ncell(r), replace=TRUE)
## Road raster
r[r[] < 10] <- 0
r[r[] >= 10] <- 1
plot(r)
## To create spatial lines
line1 <- rbind(c(-125,0), c(0,60))
line2 <- rbind(c(0,60), c(40,5))
line3 <- rbind(c(40,5), c(15,-45))
line1_sp <- spLines(line1)
line2_sp <- spLines(line2)
line3_sp <- spLines(line3)
## To create buffer around lines
line2_buff <- gBuffer(line2_sp, width=20)
plot(line2_sp,add=T)
plot(line2_buff,add=T)