我希望有人能帮助我。假设我有七条线段,前四条线段是连续的,而后三条线段也是连续的。没有属性可以用来将它们分组。是否有一种方法可以将前四条线段合并为一个特征,同时将最后三条线段合并为一个特征?
提前感谢您的帮助,并注意安全!
提前感谢您的帮助,并注意安全!
library(sf)
s1 <- st_multilinestring(list(rbind(c(0,3), c(0,4))))
s2 <- st_multilinestring(list(rbind(c(0,4), c(1,5))))
s3 <- st_multilinestring(list(rbind(c(1,5), c(2,5))))
s4 <- st_multilinestring(list(rbind(c(2,5), c(2.5,5))))
s5 <- st_multilinestring(list(rbind(c(2.7,5), c(4,5))))
s6 <- st_multilinestring(list(rbind(c(4,5), c(4.5,4))))
s7 <- st_multilinestring(list(rbind(c(4.5,4), c(5,4))))
sf_ml <- st_sf(section = 1 ,geometry=st_sfc(list(s1,s2,s3,s4,s5,s6,s7)))
plot(sf_ml)
我希望得到类似下面这样的结果:
Simple feature collection with 2 features and 1 field
geometry type: MULTILINESTRING
dimension: XY
bbox: xmin: 0 ymin: 3 xmax: 5 ymax: 5
CRS: NA
# A tibble: 2 × 2
section geometry
* <dbl> <MULTILINESTRING>
1 1 ((0 3, 0 4), (0 4, 1 5), (1 5, 2 5), (2 5, 2.5 5))
2 1 ((2.7 5, 4 5), (4 5, 4.5 4), (4.5 4, 5 4))
st_intersects
而不是st_touches
,有什么区别吗?再次感谢,注意安全! - dslrst_intersects
返回 true,如果两个几何体共享任何部分空间,而st_touches
返回 true,如果两个几何体共享边界点 -->st_touches
比st_intersects
更严格。 - agilast_intersects
时,它可以正常工作。无论如何,再次感谢你的帮助。 - dslrst_touches
对于重叠的多边形“无效”(除非它们之间唯一重叠的区域在它们的边界并集中)。请查看 https://postgis.net/docs/ST_Touches.html 和 https://postgis.net/docs/ST_Intersects.html 获取更多示例。 - agila