用PolyPoint拆分PolyLine

问题描述

我正在尝试沿着shp的线对通过点对拆分多段线形状。我已经遵循了this question的答案,但是似乎没有分割多义线的方法。

到目前为止,我已经尝试运行以下代码:

z<-c("sf","rgdal","lwgeom")
lapply(z,library,character.only = TRUE) 

edges<- readOGR(dsn=".",layer="edges") # EPSG:4326
nodes<- readOGR(dsn=".",layer="nodes") # EPSG:4326
edges<- st_as_sf(edges) 
nodes<- st_as_sf(nodes) 

nodes<-st_combine(nodes)
parts_all = st_collection_extract(lwgeom::st_split(edges$geometry,nodes),"LINESTRING")

但是会产生此错误:

Error in CPL_geos_is_empty(st_geometry(x)) : 
  Evaluation error: IllegalArgumentException: point array must contain 0 or >1 elements

据此我了解到,折线(边)必须是单条线,但是将其组合也无效,并且会产生相同的错误。

您可以找到我正在使用的示例数据here

任何想法都值得赞赏!谢谢!

更新

我设法建立了一个有效的代码。我的解决方案是制作一个循环,以创建一个新的空间对象,该空间对象仅包含多行对象的一行,然后st_split该行。

我首先需要在节点周围创建一个小缓冲区(我检查它实际上是否很小),然后尝试拆分它。

z<-c("sf",layer="nodes") # EPSG:4326
edges<- st_as_sf(edges) 
nodes<- st_as_sf(nodes) 

edges$ID_cam <- 1:nrow(edges) #My ID to be able to assign some attributes afterwards. 
nodes$ID_cam <- 1:nrow(nodes)

nodes_buf <- st_buffer(nodes,0.1)
nodi<-st_combine(nodes_buf)

for (i in 1:nrow(edges)){
  edgi<-edges[edges$ID_cam == i,]
  splited =st_collection_extract(lwgeom::st_split(edgi$geometry,nodi),"LINESTRING")
  assign(paste("split",i,sep=""),splited)
}

尽管如此,当我检查创建的新行时,它们并没有被点分开,而是似乎被随机分开了。

有人知道会发生什么吗?

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...