[R-sig-Geo] Import nmea files?

Agustin Lobo alobolistas at gmail.com
Sat Jun 22 09:32:51 CEST 2013


Thanks for your answers, which are shorter that what I ended up doing,
a mireadNMEA() function.
I think that mentioning the rounding problem at importing gps files in
the readOGR() help page would be useful.

"mireadNMEA" <- function(nmeafile,skip=0)
{
  #info http://aprs.gids.nl/nmea/
  #by now I select $GPGGA sentences only.
  require(sp)
  a <- read.csv(nmeafile,skip=skip,header=FALSE,sep=",",stringsAsFactors=FALSE)
  a <- a[a[,1]=="$GPGGA",]
  names(a) <- c("Sentence","UTC","Lat","N/S","Lon","E/W","Fix","NbSat","HDOP","Alt","m/f","HGeoid","TDGPS","DGPSID","Checks")
  for (i in c(7,8,9,10,12))  a[,i] <- as.numeric(a[,i])
  a[,3] <- as.numeric(substr(a[,3],1,2)) + as.numeric(substring(a[,3],3))/60
  a[a[,4]=="S",3] <- -a[a[,4]=="S",3]
  a[,5] <- as.numeric(substr(a[,5],1,3)) + as.numeric(substring(a[,5],4))/60
  a[a[,6]=="W",5] <- -a[a[,6]=="W",5]
  h <- substring(a[,2],1,2)
  m <- substring(a[,2],3,4)
  s <- substring(a[,2],5)
  a[,2] <- paste(h,m,s,sep=":")
  a <- a[,-c(1,4,6,11,13:15)]#useless variables
  a <- a[c(1,3,2,7,8,4:6)]
  coordinates(a) <- cbind(x=gpstracknmea$Lon,y=gpstracknmea$Lat)
  proj4string(a) <- CRS("+proj=longlat +datum=WGS84")#NMEA is always
lonlat WGS84
  a
}

On Fri, Jun 21, 2013 at 6:09 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
> And then I discovered the unicsv format:
>
> $ gpsbabel -t -i nmea -f test.nmea -o unicsv  -F out.csv
> $ more out.csv
> No,Latitude,Longitude,Speed,Course,Date,Time
> 1,41.549754,0.652421,0.0,196.5,2013/06/14,11:04:06.699999
>
> Read that in with read.table or read.csv, parse the date and time, set
> coordinates, set CRS...
>
> Barry
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list