[R-sig-Geo] SpatialPointDataFrame to SpatialLinesDataFrame

Paulo Eduardo Cardoso paulo.mailing.list at gmail.com
Wed May 26 11:37:54 CEST 2010


Sory but I'm not getting this correctly.

a data.frame

> print(traj_subam, row.names =F)
      ID          TIME_STAMP DAY_PERIOD SEASON TARGET_ID LATITUDE
LONGITUDE     SPEED HEADING DISTANCE
 7127128 2010-03-12 06:26:45          2      4   1712762 38.79497
-8.756062 0.5656855      46 2.828427
 7127143 2010-03-12 06:26:50          2      4   1712762 38.79539
-8.755520 0.2000000       1 1.000000
 7127156 2010-03-12 06:26:55          2      4   1712762 38.79560
-8.755520 0.7211103      34 3.605551
 7127175 2010-03-12 06:27:00          2      4   1712762 38.79624
-8.754979 0.0000000       0 0.000000
 7422814 2010-03-14 15:04:34          1      4   1782729 38.82139
-8.738729 0.4472136     153 2.236068
 7422841 2010-03-14 15:04:39          1      4   1782729 38.82096
-8.738460 0.4472136     334 2.236068
 7422865 2010-03-14 15:04:45          1      4   1782729 38.82139
-8.738729 0.0000000       0 0.000000
>

Then
#!Lines
ltraj <- Lines(sapply(split(traj_subam[c("LONGITUDE","LATITUDE")],
traj_subam$TARGET_ID), Line), ID =
as.character(unique(traj_subam$TARGET_ID)))

#! SpatialLines
ltraj <- SpatialLines(list(ltraj))

SLDF cannot be created with

ltraj <- SpatialLinesDataFrame(ltraj, data.frame("TARGET_ID" =
unique(traj_subam$TARGET_ID)), match.ID = T)

neither with match.ID = T or F

Paulo

2010/5/26 Paulo Eduardo Cardoso <paulo.mailing.list at gmail.com>:
> When I try to coerce Lnes to SLDF with
>
> ltraj <- Lines(sapply(split(traj_subam[c("LONGITUDE","LATITUDE")],
> traj_subam$TARGET_ID), Line))
> ltraj <- SpatialLinesDataFrame(ltraj, traj_subam, match.ID = TRUE)
>
> I get
>
> Error in slot(sl, "lines") :
>  no slot of name "lines" for this object of class "Lines"
>
> Any idea?
>
> 2010/5/26 Paulo Eduardo Cardoso <paulo.mailing.list at gmail.com>:
>> Thanks!
>>
>> But by doing this
>>
>> ltraj <- Lines(sapply(split(traj_subam[c("LONGITUDE","LATITUDE")],
>> traj_subam$TARGET_ID), Line))
>>
>> we get
>>
>> Slot "ID":
>> [1] NA
>>
>>
>> We are not holding the [Target_ID] column as ID ?
>>
>> 2010/5/25 Edzer Pebesma <edzer.pebesma at uni-muenster.de>:
>>> 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
>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> R-sig-Geo at stat.math.ethz.ch
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>> --
>>> Edzer Pebesma
>>> Institute for Geoinformatics (ifgi), University of Münster
>>> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
>>> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
>>> http://www.52north.org/geostatistics      e.pebesma at wwu.de
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>



More information about the R-sig-Geo mailing list