Wednesday, August 19, 2009

Converting GPX tracks to Google's kml format

Earlier this year I bought a neat GPS tracker for recording hiking trips and geotag my photos. With the software provided I can export these tracks to the GPX format which is an XML format for describing waypoint, tracks and routes. But for displaying my tracks in Google Earth, I need the kml format, which is also an XML format. For the transformation I use the free tool GPSBabel and a small batch script for convenient conversion.


@echo off
setlocal
if "%2"=="" (set out="%~n1.kml") else (set out=%2)
echo gpsbabel -i gpx -f %1 -o kml -F %out%
gpsbabel -i gpx -f %1 -o kml -F %out%
endlocal


The script could easily modified for the backward conversion (kml to gpx)

7 comments:

DUKKHA said...

hi,
i ve been trying to convert GPX files to KML files for my web site with Google Earth plugin.

Basically the scenario is
1) User uploads a GPX file to my web site
2) Server machine converts the GPX to KML and sends it to GE
3) Simulation of the track starts in GE Plugin.

so i dont know how to do the conversion in Java.
any help would be appreciated

G.Muecke said...

I never did this using Java before, but basically GPX and KML are both XML formats, so the approach I'd follow would be to use and XSLT transformation. I think there are examples in the web which XSLT to use and also there should be examples for doing an XSL transformation in Java. (as far as I remember, transformation is just a couple lines of code)... does this help? Try googling for "XSLT GPX KML" and "Java XSLT"

DUKKHA said...

Thanx a lot. It was very helful. I found a XSLT and it worked well.

Ares said...

Do you mind sharing that XSLT file that you found?

G.Muecke said...

I found this one, but never tried it myself:
http://members.home.nl/cybarber/geomatters/GPX2KML.xslt

at the moment i use a free tool from Anthony Dunk "GPX to KML", but I can't find a working link to it as his page is down

mke said...

You could give a try to this free tool: http://gpx2kml.com
Light and fast, does the conversion both ways.

Sinziana Armencea said...

Hi...maybe this will help... kml2gpx.com I am using it for quite a time and I am pleased with it...let me know what you think. :)