Skip to content

Extracting coordinates from SpatialLinesDataFrame object

2 messages · Agustin Lobo, Roger Bivand

#
I  want to extract the coordinates of each line
in a SpatialLinesDataFrame object as a 2D matrix (not as a list). I'm using
as.matrix(coordinates(fl1[1,])[[1]][[1]])
for the first line,
which works fine but it's really odd and difficult to remember.

Is there an easier way of doing it?
Also, perhaps we could have something like
coordinates(fl1[1,], matrix=T)
in the future ?

Thanks!

Agus
#
On Mon, 6 Jul 2009, Agustin Lobo wrote:

            
No, because a SpatialLines object contains one or more Lines objects, each 
of which contains one or more Line objects. You are choosing the first 
Lines object, which may consist of multiple Line objects. So lists are the 
best way to represent them, and:

res <- lapply(slot(fl1, "lines"), function(x) lapply(slot(x, "Lines"),
   function(y) slot(y, "coords")))

gets everything out tidily. Isn't reality "really odd and difficult to 
remember"? Other users have richer Lines objects, so doing what you 
request would be simplifying too far.

Roger