Incidentally I think your answer made me understand what
SpatialLinesDataFrame are (I used to think it was a different way to
store the shape's geometry but it is more about linking
attributes/variables to shapes ID's if I am correct). It will serve
my purpose quite aptly.
Thanks a lot again, I already had more answers than I asked for.
Best regards,
Bastien
2015-12-09 17:40 GMT+01:00 Roger Bivand <Roger.Bivand at nhh.no>:
On Wed, 9 Dec 2015, Bastien Tran wrote:
Dear all,
I intend to make "copies" of SpatialLines object meaning I would like
to get the same geometry but with different IDs for the Lines.
Please use row.names(), so here:
row.names(L1) <- c("c", "d")
If L1 was a SpatialLinesDataFrame, the row.names of the data slot would also
be updated.
Roger
For instance using L1 from the SpatialLines example I would like to go
from:
Formal class 'SpatialLines' [package "sp"] with 3 slots
..@ lines :List of 2
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1 2 3 3 2 2
.. .. .. ..@ ID : chr "a"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1 2 3 3 1.5 1
.. .. .. ..@ ID : chr "b"
..@ bbox : num [1:2, 1:2] 1 1 3 3
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr NA
to
Formal class 'SpatialLines' [package "sp"] with 3 slots
..@ lines :List of 2
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1 2 3 3 2 2
.. .. .. ..@ ID : chr "c"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1 2 3 3 1.5 1
.. .. .. ..@ ID : chr "d"
..@ bbox : num [1:2, 1:2] 1 1 3 3
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr NA
Is there a way to do so without rebuilding the SpatialLine object with
updated Lines objects (same Lines new IDs)? I assume it is possible to
update each ID slot directly in L1 somehow.
I expected something like
sapply(slot(L1, "lines"), function(x) assign(slot(x, "ID"),
paste0("copyof",slot(x, "ID")))
to do so but I am certainly missing something about assignments in S4
objects.
Thank you for any help.
Best regards,
Bastien Tran