GPSBabel/Usage from the command line

From OpenStreetMap Wiki
Jump to navigation Jump to search

GPSBabel is a purely command line software for GPS data conversion. All it's GUIs just construct appropriate text command for the shell, which can be seen during usage.

You can get help by reading official documentation or by running gpsbabel -?.

Basic command

The basic command line looks like this:

gpsbabel [options] -i INTYPE -f INFILE -o OUTTYPE -F OUTFILE

where ‘INTYPE’ and 'OUTTYPE' are formats that GPSBabel understands and 'INFILE' and ‘OUTFILE’ are the locations of that data. That location can be either a file or the name of a physical device. For example a serial port may appear as 'com1' under Windows or '/dev/ttyS0' under Linux.

As an example, let us suppose you have latitude, longitude, and waypoint name in a file 'way.csv'

40.70175, -103.68998, First Waypoint
39.28553, -123.79357, Another point
42.49638, -108.72995, And a third

To convert this CSV file into the GPX format (file way.gpx) we use this command:

gpsbabel -i csv -f way.csv -o gpx -F way.gpx

Deconstructing the command line: '-i csv' using the comma separated value INTYPE. '-f way.csv' (note that is a lower case f) specifies the name of the input file (or the name of the input serial port). '-o gpx' specifies the output is GPX format. '-F way.gpx' (capital F) provides the name of the output file (or output serial port). For a more robust alternative to the three-field format of GPSBabel's strict CSV format, consider using unicsv which lets you specify headers and many more field types. That's generally a better format for interoperating with a database or spreadsheet.

GPS device communication via serial or USB ports

Most of the following subsections' content only is relevant if you do not already have a GPX file (e.g. written by your GPS device or by a smartphone app).

GPSBabel directly supports hundreds of GPS receivers from Garmin, Magellan, Wintec and more. Connect your GPS to your serial port or USB port depending on your device type (for connecting serial receivers to USB ports see GPS Serial to USB). A Garmin serial protocol GPS is specified -i garmin while a Magellan is -i magellan. Use the -f and -F parameters to specify the serial port for your GPS. Use -f when you read from the GPS and -F to write to the GPS. (NB, if the following commands do not appear to work on the Garmin units, check that the Interface Setting on the unit is set to "GARMIN" or "GARMIN DGPS").

Reading waypoints from a GPS

Here are some examples to read waypoints from a Garmin GPS and write them out to the GPX format file named 'waypoint.gpx.'


Under Windows assume the GPS is attached to the first serial port:

gpsbabel -i garmin -f com1 -o gpx -F waypoint.gpx

That sets the input type to the Garmin serial protocol to read data from the serial port and write it to a GPX format file named waypoint.gpx.

If instead the device is connected to the USB port:

gpsbabel -i garmin -f usb: -o gpx -F waypoint.gpx


Assume the GPS receiver is attached to the first serial port. (Need to run as a user who has rights to read the serial port, so some systems may require the program to run as root or with sudo.)

gpsbabel -i garmin -f /dev/ttyS0 -o gpx -F waypoint.gpx

If the device is connected to the USB port, try /dev/ttyUSB0 or usb:

gpsbabel -i garmin -f /dev/ttyUSB0 -o gpx -F waypoint.gpx
# or
gpsbabel -i garmin -f usb: -o gpx -F waypoint.gpx

See also:, USB Garmin on GNU/Linux

If you have problems accessing the USB0 port on your Ubuntu Linux, you might want to read this discussion thread on Ubuntu Forums and remove the packages brltty and brltty-x11 (Braille support apparently breaks USB serial). Don't forget to power on the GPS unit first!

A maybe useful bash script: download track and waypoints

GPSBabel bash script for downloading tracks,waypoints & routes available from: gerkin


Under OSX assume the GPS is attached to a serial to USB adapter

gpsbabel -i garmin -f /dev/cu.usbserial0 -o gpx -F waypoint.gpx

Under OSX 10.8 there was no /dev/cu.usbserial0 but I found that this worked for a USB device:

gpsbabel -i garmin -f usb: -o gpx -F waypoint.gpx

Track logs

To read track logs you add a '-t' in front of the input (-i) specifier. So to get tracklogs under Windows:

gpsbabel -t -i garmin -f com1 -o gpx -F tracklog.gpx


And in the same way, you can read or write routes with the -r parameter:

gpsbabel -r -i garmin -f com1 -o gpx -F route.gpx

Note: When you write a route a waypoint will be generated for each route point. This is annoying. Since waypoints have globally unique names, your route points will be renamed if they collide with another route (a common problem would be numeric names eg. "1" "2" being renamed to "1 1" "2 1" etc.) To prevent this happening use John Dally's patch for gpsbabel.

Writing data to a GPS

You can also write tracklogs, waypoints, and routes back to your gps by swapping the input and output parameters. To write waypoints from waypoint.gpx to a Garmin unit under Windows:

gpsbabel -i gpx -f waypoint.gpx -o garmin -F com1

See also