Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Global Positioning System

In some situations in analysing data you may actually be collecting the data directly for analysis by R from some external device, possibly connected through the computer's serial port. One such example is using a global positioning system. On a GNU/Linux system this might be connected to your serial device and in R (after ensuring you have read access to the serial port /dev/ttyS0) you can read your current position.

> gps <- scan(file="/dev/ttyS0", n=1, what="character")
Read 1 items
> gps
[1] "@051226122125S0341825E01500808G006+00350E0000N0000D0000"

> columns <- c("tag", "date", "time", "latitude", "longitude",
               "quality", "level", "movelong", "movelat", "movevert")
> widths <- c(1, 6, 6, 8, 9, 4, 6, 5, 5, 5)
> gps.data <- read.fwf("/dev/ttyS0", widths, col.names=columns, n=1,
                       colClasses="character")
> gps.data
  tag   date   time latitude longitude quality  level movelong movelat movevert
1   @ 050221 122125 S0341825 E01500808    G006 +00350    E0000   N0000    D0000

This tells me that the location is 34degrees, 18.25minutes south, 150degrees, 8.08minutes east. The quality is good with a 6meter positional error. This is 35m above sea level, and not moving.



Copyright © 2004-2006 Graham.Williams@togaware.com
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.