Skip to content
Prev 23761 / 29559 Next

Extract points from SpatialLines objects along with the corresponding Lines' ID

Dear all,

I am trying to extract the points that compose a SpatialLines object along
with the Line's ID (provided when Lines() is called).

Hoping it makes my question clearer this is what I am currently able to get
(using the SpatialLines example):
function(y) slot(y, "coords")))
[[1]]
     [,1] [,2]
[1,]    1    3
[2,]    2    2
[3,]    3    2

[[2]]
     [,1] [,2]
[1,]    1  3.0
[2,]    2  1.5
[3,]    3  1.0

But I would rather like to obtain something like this:

[[1]]
     [,1] [,2] [,3]
[1,] "1"  "3"  "a"
[2,] "2"  "2"  "a"
[3,] "3"  "2"  "a"

[[2]]
     [,1] [,2]  [,3]
[1,] "1"  "3"   "b"
[2,] "2"  "1.5" "b"
[3,] "3"  "1"   "b"

If possible I would like to avoid type conversions and get a data.frame
directly though I could indeed recreate one with these matrices, without
information loss I assume.

Thank you in advance for any tips.

Best regards,
Bastien