reading a gps from R
Patrick: A simplified version of your readGPS() interfacing gpsbabel is included in maptools 0.6-9. It turned out that even using the NMEA interface to different Garmin receivers seems to give different data in different columns. In addition, my trials have shown that some data frame rows may be corrupted, so at least the first time a given receiver is interfaced, the data read will need to be looked at carefully. From there on, one can write a wrapper with the general readGPS() function inside to check for erroneous rows and select required columns, as sketched in the example for my Garmin etrex Legend Cx. Under non-Windows OS, reading from USB or serial may need special permissions too - see the gpsbabel website, and Vista may also require special treatment (untried). Thanks for a useful contribution! Roger
On Sun, 18 Feb 2007, Patrick Giraudoux wrote:
On the thread and in case it may help somebody, find below this function that can read Garmin Etrex Summit from R (whatever the plateform - tested on Windows XP and Ubuntu 6.10 Edgy eft) if gpsbabel is installed. Packaged in pgirbric at http://perso.orange.fr/giraudoux/SiteGiraudoux.html. readGPS<-function(type="w",wcom=4){ if (!(type=="w" | type=="t")) stop("type must be 'w' (waypoints) or 't' (tracks)") if (Sys.info()["sysname"]!="Windows") {# OK sous linux Ubuntu 6.10 gpsdata<-system(paste("gpsbabel -",type," -i garmin -f /dev/ttyUSB0 -o tabsep -F -",sep=""), intern=TRUE) if (any(grep("Can't init",gpsdata))) stop("Cannot read GPS: check connexion") } else {# OK sous Windows if (any(grep(wcom,0:9))){ gpsdata <- system(paste("gpsbabel -",type," -i garmin -f com",wcom,": -o tabsep -F -",sep=""), intern=TRUE) if (any(grep("Can't init",gpsdata))) stop("Cannot read GPS: check connexion and com port number 'wcom'") } else stop("Windows com port number 'wcom' must be one of 0:9") } gpsdata<-read.table(textConnection(gpsdata), fill=TRUE) if (type=="w"){ gpsdata<-gpsdata[,c(2,6,7,17)] names(gpsdata)<-c("ident","long","lat","altitude") gpsdata$altitude<-as.numeric(substr(as.character(gpsdata$altitude),1,nchar(as.character(gpsdata$altitude))-1)) attributes(gpsdata)$type<-"Waypoints" } if (type=="t"){ gpsdata<-gpsdata[,c(3,4,14)] names(gpsdata)<-c("long","lat","altitude") ident<-1:length(gpsdata[,1]) gpsdata<-data.frame(ident=ident,gpsdata) gpsdata$altitude<-as.numeric(substr(as.character(gpsdata$altitude),1,nchar(as.character(gpsdata$altitude))-1)) attributes(gpsdata)$type<-"Track" } attributes(gpsdata)$sysTime<-Sys.time() gpsdata }
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no