Converting/NMEA to GPX

From OpenStreetMap Wiki
Jump to navigation Jump to search

Easy to use

The easiest way to convert or modify NMEA-files is to use applications like

Online Tools

Converting NMEA text dumps with gpsbabel

GPSBabel is a commonly used program to convert from one GPS format to another, and can convert from NMEA to GPX. You can use GPSBabel either as a GUI, via Gebabbel or a command-line program. If you set up GPSBabel as a command-line program using one of the following scripts, you will avoid wasting a lot of time clicking the graphical user interface.

GPSBabel can be used on the command line like:

gpsbabel -i nmea -f "nmeafilename" -o gpx,gpxver=1.1 -F "outputfilename.gpx"

NMEA sentences normally store all the data output by the gps including data which is poor. However this can easily be cleaned out by setting filtering options with GPSBabel. The most common need is to filter data which has poor horizontal accuracy due to a lack of satellite visibility or other signal performance issues. The hdop value in the NMEA sentence is used for this. Filtering for data better than 10 is a good compromise between filtering for accuracy but keeping sufficient points where the general quality of the log was poor. Adding the filter to the above command line entry gives:

gpsbabel -i nmea -f "nmeafilename" -x discard,hdop=10 -o gpx -F "outputfilename.gpx"

NMEA_to_XML wrapper for gpsbabel

This simple script will convert all NMEA log files in a directory to GPX (or KML) files. It will also optionally join them together into a single output file.

Download from github

Example converting all .log files in directory (./input) to GPX and KML format and storing in another directory (./output):

python nmea_to_xml.py -gk -i input -o output

Example joining all .log files to a single KML file in ./output/complete.kml:

python nmea_to_xml.py -kj -i input -o output/complete

Richard wrote to scratch-own-itch but welcomes any ideas for improvement. Just submit a new issue.

On GNU/Linux or other posix systems

Use the following bash script to convert multiple files from NMEA to GPX in one operation. Save it as gpxconvert then run it as ./gpxconvert *.TXT for batch mode or ./gpxconvert mynmeafile.TXT for single file mode.

#!/bin/bash
unext ()
{
 declare -a nameparts
 num=0
 nameparts=($(echo "$1" | sed 's/\./\t/g'))
 num=$((${#nameparts[*]}-1))
 ext="\\$(eval echo ".\${nameparts[$num]}")"
 seder="s/$ext//g"
 echo "$1" | sed -e $seder
}

if [ -z "$1" ]; then
 echo "Takes a list of inout NMEA files, converts to GPX files."
 echo  "usage: $0 <nmea_input_files>"
 exit 0
fi
echo ""
for file in "$@"; do
 fileNoExt=$(unext "$file")
 if [ ! -e "$file" ]; then
  echo "$file input file doesn't exist, Skipping."
 elif [ -e "$fileNoExt.gpx" ]; then
  echo "$fileNoExt.gpx already exists. Skipping"
 else
  echo "$fileNoExt.gpx - converting"
  gpsbabel -i nmea -f "$file" -o gpx -F "$fileNoExt.gpx"
 fi
done


The script will skip files where the output file already exists. If you have a folder where you upload your nmea files, you can just drag your new nmea files into the folder then run ./gpxconvert *.nmea (assuming .nmea is your file extension). It will only convert those which haven't yet been converted. You could also run this command as a desktop icon on GNU/Linux or windows. Drag your NMEA files to a folder, click a button then all your NMEA files have a GPX equivalent.

On Windows

Using navi-convert

I have made a batch conversion program which bundles the above script with the Free Software GPSbabel and Bash. Grab the bundle and follow step by step instructions from navi-convert NickH

Using nmea2gpx.cmd

nmea2gpx.cmd is a simple DOS/CMD script that does a similar task to navi-convert. It converts NMEA to GPX using GPSbabel. Copy and paste it into a file called nmea2gpx.cmd, create folders 'NMEA' and 'GPX' on the same level, and create folder 'done' within NMEA. All you need do is copy your NMEA logs into the NMEA folder, and run nmea2gpx.cmd

For each filename.nmea in the folder NMEA, it checks if filename.gpx exists in the folder GPX. If it doesn't, it converts it, then moves filename.nmea to NMEA\done

@echo off
setlocal
FOR /f "delims=" %%f in ('dir /a-d /b NMEA\*.nmea') do (call :main "%%f")
GOTO end

:main
IF exist "GPX\%~n1.gpx" GOTO:EOF
"c:\program files\GPSbabel\gpsbabel.exe" -i nmea -f "NMEA\%~1" -o gpx -F "GPX\%~n1.gpx"
move "NMEA\%~1" "NMEA\done\"
GOTO:EOF

:END

--LeedsTracker 17:35, 18 August 2008 (UTC)

Using the DOS CLI

Another easy solution is to put all your .nmea files in one single directory. You will need GPSBabel as well. Once this is done, open a DOS prompt, the go in this directory using cd and run the following command:

for %i in (*.TXT) do "<PATH_TO_GPABABEL>\gpsbabel.exe" -i nmea -f %i -o gpx -F %~ni.gpx

For me, <PATH_TO_GPSBABEL> is F:\Mac\GPSBabel\.

Using GPSBabel's GUI

Alternatively, you can use gpsbabel for windows, which provides a GUI. The GUI will likely be much slower to use if you have a number of files to convert. (hint: use the .zip file for windows).

If it doesn't work post some of the data to the mailing list and we will help you out.

Converting NMEA text dumps (with osmtrackfilter.pl)

osmtrackfilter.pl is one of the OSM perl scripts in svn and can convert from several common formats, including nmea and gpsdrive track files to gpx. It also has several helpful features including file reduction to remove duplicate points and date replacement.

Typical usage to remove date information, for privacy:

perl osmtrackfilter.pl --fake-gpx-date mytextfile.nmea

See the built-in help file for further information:

perl osmtrackfilter.pl -h

Gosmore NMEA to GPX conversion

Gosmore may just do a better job than other utilities when the data is damaged e.g. by communication errors. To do it you must create a 'fake' gpsd server :

nc -l -p 2947 <mytextfile.nmea &
./gosmore 
# Close the application and look for GPX file(s)

BT747 NMEA to GPX conversion

BT747 is written in JAVA and runs on most platforms and can convert NMEA to GPX. It is permissive and can cope with errors in the source file.

File recognition is extension based, and the source file should end in .nme, .nmea, .txt or .log .

CLI

When using the CLI (using BT747cmd on windows, but run_j2se.sh on Linux, bt747_macosX_j2se.command on mac):

BT747cmd mytextfile.nmea -f outputbasename --outtype gpx

GUI

Just put your source file in the 'input file box' or drag and drop multiple files to the GUI, then click on GPX.