r - 如何在 R 中的空间多边形内创建线性距离衰减(1-0)?
问题描述
我正在尝试绘制工业区周围的宁静地图。工业区内的安宁度应为“0”,在距工业区450m的缓冲区内线性增加至“1”。有没有一种简单的方法来映射这种线性减少?
我在工业区周围创建了一个缓冲区(光栅包)并将其光栅化,但我不知道如何计算线性衰减。我的目标是分辨率为 25m 的光栅。
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(从内到外)。感谢您提供任何帮助或建议!
解决方案
也许像这样
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)
推荐阅读
- google-apps-script - 如何在谷歌脚本中编写换行符
- css - 重命名 p-tabview 中的选项卡
- javascript - 通过编辑一个常见的 .JS 文件将 DialogFlow 标记动态添加到站点
- elasticsearch - elasticsearch helm chart 上的 HTTPS
- java - java.lang.IllegalArgumentException:没有为 id 0x7f0901d1 找到视图
- php - 检查当前行php
- java - 将多态对象列表反序列化为对象字段
- javascript - API 在未发送 /api/users/create 响应的情况下解析,这可能会导致请求停止。下一个
- python-3.x - 如何在具有多个参数的熊猫数据帧上调用函数
- flutter - 小部件是在应该使用之前创建的 => 导致错误