【问题标题】:In R split polyline with polyline在R中用折线分割折线
【发布时间】:2018-10-17 07:05:44
【问题描述】:

我有一条折线,我想将其分割成若干段。并创建一条新的折线。 多段线需要分割的位置是它与另一条多段线相交的位置。

library(sp)
library(maptools)
library(rgeos)

dir_shp     <- paste("g:/.../Stackoverflow_example/")
naam_shp    <- paste("traject_A")

traject_A   <- readShapeLines(paste(dir_shp, layer=naam_shp, sep=""))
Split_loc   <- readShapeLines(paste(dir_shp,"Cross_section" , sep=""))
InterS1     <- gIntersection(traject_A, Split_loc)

shapefile traject_A 如下所示:

> traject_A
An object of class "SpatialLinesDataFrame"
Slot "data":
  Id
0  0

Slot "lines":
[[1]]
An object of class "Lines"
Slot "Lines":
[[1]]
An object of class "Line"
Slot "coords":
          [,1]     [,2]
 [1,] 62706.30 382326.9
 [2,] 63055.55 382049.6
 [3,] 63265.10 382070.7
 [4,] 63483.12 382045.3
 [5,] 63648.22 381797.7
 [6,] 63950.90 381816.7
 [7,] 64158.34 382000.9
 [8,] 64245.12 381886.6
 [9,] 64253.59 381770.2

Slot "ID":
[1] "0"

Slot "bbox":
       min       max
x  62706.3  64253.59
y 381770.2 382326.85

Slot "proj4string":
CRS arguments: NA 

InterS1 给出了线相交的位置。

> InterS1
SpatialPoints:
         x        y
1 62806.00 382247.7
1 62966.51 382120.3
1 63180.03 382062.1
1 63371.13 382058.4
1 63563.55 381924.7
1 63697.28 381800.8
1 63950.98 381816.8
1 64193.49 381954.6
1 64249.98 381819.8
Coordinate Reference System (CRS) arguments: NA

下一步就是我迷路了。

如何使用这些点将我的折线 traject_A 分割成一个新的 shapefile。

感谢您的帮助!

【问题讨论】:

  • 请在提问时提供可重现的示例。
  • 我编辑了这个例子,这样更好吗,亚当?
  • 这是GIS SE上的类似问题

标签: r sp maptools


【解决方案1】:

从其他地方交叉发布。回想一下,您可以简单地将多边形转换为折线。

library(sf)
A <- st_as_sfc("LINESTRING(458.1 768.23, 455.3 413.29, 522.3 325.77, 664.8 282.01, 726.3 121.56)")
B <- st_as_sfc("MULTIPOLYGON(((402.2 893.03, 664.8 800.65, 611.7 666.13, 368.7 623.99, 215.1 692.06, 402.2 893.03)), ((703.9 366.29, 821.2 244.73, 796.1  25.93, 500.0 137.76, 703.9 366.29)))")

## Convert the MULTIPOLYGON to a MULTILINESTRING object
BB <- st_cast(B, "MULTILINESTRING", group_or_split=FALSE)

## Break LINESTRING A into segments by using:
## - st_intersection() to find points at which lines features intersect
## - st_buffer() to convert points to tiny polygons with some width
## - st_difference() to break line up into sections not overlapping tiny polygons
C <- st_difference(A, st_buffer(st_intersection(A,BB), dist=1e-12))

【讨论】:

    猜你喜欢
    • 2017-03-04
    • 1970-01-01
    • 2021-12-26
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多