【问题标题】:Polygon and line input for point output (in R)点输出的多边形和线输入(在 R 中)
【发布时间】:2017-01-29 19:27:02
【问题描述】:

我想创建一个 .shp 文件或坐标数据表,其中输出点要素是线端点在多边形边界上的某个点接触的位置以及线与多边形边界相交的位置。输出中不会生成线直接沿着多边形边界的点。

这可以在 R 中完成吗?

Like the intersect tool in Esri?

我有两个类(在 R 中)...

  1. 空间线
  2. 空间多边形

我似乎根本找不到执行此操作的工具/包...

(我是初学者)

【问题讨论】:

标签: r gis spatial spatstat


【解决方案1】:


您可以使用 spatstat 包执行此操作,但您需要转换 从SpatialLinesSpatialPolygonspsp(平面段 模式)和owin(观察窗口——平面中的一个多边形)使用 maptools 包。

由于您没有提供示例数据,我将首先构建 看起来像您的图形的 SpatialPolygons 和 SpatialLines 对象:

library(maptools)
#> Loading required package: sp
#> Checking rgeos availability: TRUE
library(spatstat)
#> Loading required package: nlme
#> Loading required package: rpart
#> 
#> spatstat 1.48-0.029       (nickname: 'Alternative Facts') 
#> For an introduction to spatstat, type 'beginner'
A <- owin(c(1,3), c(2,5))
B <- owin(c(4,7), c(1,5))
p <- union.owin(A,B)
p <- as(p, "SpatialPolygons")
l <- psp(c(0.5, 0.5), c(2, 4), c(4, 6), c(2, 4), window = owin(c(0,7), c(0,5)))
l <- as(l, "SpatialLines")
plot(p)
plot(l, col = "green", add = TRUE, lwd = 3)

现在按照您的要求将多边形的边缘转换为psp 并找到线穿过这些边缘的位置(作为平面点返回 模式ppp):

l <- as(l, "psp")
p <- as(p, "owin")
e <- edges(p)
x <- crossing.psp(l, e)
x
#> Planar point pattern: 4 points
#> window: rectangle = [1, 6] x [2, 4] units

将点添加到图中显示了我们的发现:

plot(p, main = "")
plot(l, col = "green", add = TRUE, lwd = 3)
plot(x, add = TRUE, col = "red", pch = 20, cex = 3)

【讨论】:

  • 这是一种享受和很好的解释!非常感谢!
猜你喜欢
  • 2018-07-21
  • 2018-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-08
  • 2021-11-12
  • 1970-01-01
相关资源
最近更新 更多