我正在尝试绘制工业区周围的宁静地图。在工业区内,宁静度应为"0“,在距工业区450米的缓冲区内线性增加至"1”。有没有一种简单的方法来映射这种线性减少?
我在工业区周围创建了一个缓冲区(栅格包),并对其进行了栅格化,但我不知道如何计算线性衰减。我的目标是一个分辨率为25米的光栅。
x_coord <- c(16, 17, 24, 22, 16)
y_coord <- c(59, 55, 55, 61, 59)
xym <- cbind(x_coord, y_coord)
library(sp)
sps = SpatialPolygons(list(Polygons(list(Polygon(xym)),1)))
proj4string(sps) = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
plot(sps)
b <- buffer(sps, width = 4)
e <- erase(b,sps)
plot(e, add=T, col="red") # here I choose 4m instead of 450m buffer width
ext <- extent(10,70,10,70)
r <- raster(ext, res=0.25) # here I choose 0.25m instead of 25m resolution
e <- rasterize(e, r)
我希望栅格"e“的值从0线性增加到1(从内部到外部)。感谢您的帮助或建议!
发布于 2019-06-06 12:23:02
也许是这样的
library(raster)
x_coord <- c(16, 17, 24, 22, 16)
y_coord <- c(59, 55, 55, 61, 59)
xym <- cbind(x_coord, y_coord)
sps <- spPolygons(xym, crs="+proj=longlat +datum=WGS84")
b <- buffer(sps, width = 4)
ext <- extent(10,40,40,70)
r <- raster(ext, res=0.25)
e <- rasterize(sps, r)
d <- distance(e)
x <- mask(d, b)
z <- x / maxValue(x)
plot(z)
lines(sps)
lines(b)
https://stackoverflow.com/questions/56457323
复制相似问题