Here's an example how a Lines object is built from several sets of
points (meuse data, split by soil type):
library(sp)
data(meuse)
Lines(sapply(split(meuse[c("x","y")], meuse$soil), Line))
Note that meuse is used as a data.frame in this example; use
as.data.frame on your SPDF to get it.
I hope this helps,
On 05/25/2010 04:16 PM, Paulo Eduardo Cardoso wrote:
Hi,
How can one coerce spatial point to spatial line?
I'm struggling to find a way of coerce a point SPDF object to Lines
based in a ID [TARGET_ID] field.
Any idea will be very welcome.
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
? ..@ data ? ? ? :'data.frame': 28 obs. of ?8 variables:
? .. ..$ ID ? ? ? ?: int [1:28] 462964 462990 463015 463034 463052 463069
463083 463102 463122 463144 ...
? .. ..$ TIME_STAMP: POSIXlt[1:28], format: "2009-07-26 09:00:07"
"2009-07-26 09:00:13" "2009-07-26 09:00:19" "2009-07-26 09:00:25" ...
? .. ..$ DAY_PERIOD: int [1:28] 1 1 1 1 1 1 1 1 1 1 ...
? .. ..$ SEASON ? ?: int [1:28] 2 2 2 2 2 2 2 2 2 2 ...
? .. ..$ TARGET_ID : int [1:28] 108426 108426 108426 108426 108426 108426
108426 108426 108426 108426 ...
? .. ..$ SPEED ? ? : num [1:28] 0.283 0.6 0.4 0.2 0.2 ...
? .. ..$ HEADING ? : int [1:28] 134 1 179 179 179 271 123 179 179 90 ...
? .. ..$ DISTANCE ?: num [1:28] 1.41 3 2 1 1 ...
? ..@ coords.nrs : int [1:2] 7 6
? ..@ coords ? ? : num [1:28, 1:2] -8.71 -8.71 -8.71 -8.71 -8.71 ...
? .. ..- attr(*, "dimnames")=List of 2
? .. .. ..$ : NULL
? .. .. ..$ : chr [1:2] "LONGITUDE" "LATITUDE"
? ..@ bbox ? ? ? : num [1:2, 1:2] -8.82 38.73 -8.69 38.8
? .. ..- attr(*, "dimnames")=List of 2
? .. .. ..$ : chr [1:2] "LONGITUDE" "LATITUDE"
? .. .. ..$ : chr [1:2] "min" "max"
? ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
? .. .. ..@ projargs: chr " +init=epsg:4326 +proj=longlat +ellps=WGS84
+datum=WGS84 +no_defs +towgs84=0,0,0"
Paulo Eduardo Cardoso