-----Oorspronkelijk bericht-----
Van: Dylan Beaudette [mailto:dylan.beaudette at gmail.com]
Verzonden: donderdag 4 augustus 2011 0:46
Aan: ONKELINX, Thierry
CC: r-sig-geo at stat.math.ethz.ch
Onderwerp: Re: [R-sig-Geo] cleaning up SpatialLines
On Wed, Aug 3, 2011 at 3:11 PM, ONKELINX, Thierry
<Thierry.ONKELINX at inbo.be> wrote:
Dear all,
I have a SpatialLinesDataFrame containing a lot of short line fragments. Many
of them have exactly one other linefragment at one (or both) of their end
vertices. I would like to merge those linefragments to that each line is at both
end vertices either connected to at least two other lines or to no other line.
Does someone has an effecient solution for this? Via R or via grass?
I managed already to add a grouping variable to the data.frame. But I still
need to find a way to merge the coordinates of the lines from the same Group.
See the example below.
Best regards,
Thierry
library(sp)
Raw <-
SpatialLines(list(Lines(list(Line(cbind(x = c(0, 0, 1), y = c(0, 1,
1)))), ID = 1), Lines(list(Line(cbind(x = c(2, 2, 1), y = c(0, 1,
1)))), ID = 2), Lines(list(Line(cbind(x = c(-2, -2), y = c(0, -1)))),
ID = 3)
))
Raw <- SpatialLinesDataFrame(Raw, data.frame(ID = 1:3, Group =
c(1,1,2)))
Result <-
? ? ? ?SpatialLines(list(Lines(list(Line(cbind(x = c(0, 0, 1, 2, 2), y
= c(0, 1, 1, 1, 0)))), ID = 1),
? ? ? ? ? ? ? ? ? ? ? ?Lines(list(Line(cbind(x = c(-2, -2), y = c(0,
-1)))), ID = 2)
? ? ? ? ? ? ? ?))
Result <- SpatialLinesDataFrame(Result, data.frame(ID = 1:2, Group =
c(1,2)))