首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在R中的空间多边形内创建线性距离衰减(1-0)?

如何在R中的空间多边形内创建线性距离衰减(1-0)?
EN

Stack Overflow用户
提问于 2019-06-05 17:01:08
回答 1查看 95关注 0票数 1

我正在尝试绘制工业区周围的宁静地图。在工业区内,宁静度应为"0“,在距工业区450米的缓冲区内线性增加至"1”。有没有一种简单的方法来映射这种线性减少?

我在工业区周围创建了一个缓冲区(栅格包),并对其进行了栅格化,但我不知道如何计算线性衰减。我的目标是一个分辨率为25米的光栅。

代码语言:javascript
运行
复制
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(从内部到外部)。感谢您的帮助或建议!

EN

回答 1

Stack Overflow用户

发布于 2019-06-06 12:23:02

也许是这样的

代码语言:javascript
运行
复制
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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56457323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档