[R] syntax for reading into R

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Jan 2 17:03:00 CET 2012


On Mon, Jan 2, 2012 at 3:54 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:

>  That looks suspiciously like a chunk of a GPX format file - GPS
> tracks, that kind of thing. Am I right?
>
> If so, then get the rgdal package, and read it in. You'll end up with
> a spatial data frame of some kind from which you can get the points
> and times.
>
> http://en.wikipedia.org/wiki/GPS_eXchange_Format

Specifically, if I put that snippet of yours into a GPX file, I can do:

 > trk= readOGR("m.gpx","track_points")

 > trk
         coordinates track_fid track_seg_id track_seg_point_id ele
1   (16.343, 48.272)         0            0                  0 387
2 (16.3436, 48.2719)         0            0                  1 381
                    time magvar geoidheight name  cmt desc  src link1_href
1 2012/01/01 15:32:03+00     NA          NA <NA> <NA> <NA> <NA>       <NA>
2 2012/01/01 15:32:34+00     NA          NA <NA> <NA> <NA> <NA>       <NA>
  link1_text link1_type link2_href link2_text link2_type  sym type  fix sat
1       <NA>       <NA>       <NA>       <NA>       <NA> <NA> <NA> <NA>   9
2       <NA>       <NA>       <NA>       <NA>       <NA> <NA> <NA> <NA>   9
  hdop vdop pdop ageofdgpsdata dgpsid
1   NA   NA   NA            NA     NA
2   NA   NA   NA            NA     NA

 - obviously there's a lot of stuff there you don't need, so you can do:

 > trk at data=trk at data[,c("ele","time","sat")]
 > trk
         coordinates ele                   time sat
1   (16.343, 48.272) 387 2012/01/01 15:32:03+00   9
2 (16.3436, 48.2719) 381 2012/01/01 15:32:34+00   9

Barry



More information about the R-help mailing list