[OSM-talk] HOWTO: edit GPX tracks using JOSM
Rory McCann
rory at technomancy.org
Sun May 18 00:50:01 BST 2008
Hi,
I've just got my NaviGPS BGT-31 and I made my first trace today. I got
the data off it with gpsbabel 1.3.5 and got it into GPX format. However
I wanted to clean it up a bit first. I couldn't find any way to edit it.
I was able to convert it to OSM format using gpsbabel with this
command: "gpsbabel -i gpx -f trace.gpx -o osm -F trace.osm", I could
then open it in JOSM and remove some bad points. However coverting that
OSM file back into GPX for upload was troublesome.
I first tried to save it as GPX format in JOSM, but that didn't save the
timestamp data, which broke the import. Then I tried converting the OSM
file to GPX using gpsbabel, but that laid out the file differently from
before, so the importer couldn't see the points in it.
Eventually I wrote this XSLT file for converting from OSM to GPX (both
of which are XML). Apply this template to the OSM file like so:
xmlstarlet tr osm2gpx.xslt trace.osm > trace.gpx
Here's the file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/osm">
<gpx
version="1.0"
creator="gpsbabel - http://www.gpsbabel.org"
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
xmlns="http://www.topografix.com/gpx/1/0"
xsi:schemalocation="http://www.topografix.com/gpx/1/0
http://www.topografix.com/gpx/1/0/gpx.xsd">
<trk>
<trkseg>
<xsl:for-each select="node">
<xsl:sort select="@timestamp" />
<trkpt>
<xsl:attribute name="lat"><xsl:value-of select="@lat"
/></xsl:attribute>
<xsl:attribute name="lon"><xsl:value-of select="@lon"
/></xsl:attribute>
<time><xsl:value-of select="@timestamp" /></time>
</trkpt>
</xsl:for-each>
</trkseg>
</trk>
</gpx>
</xsl:template>
</xsl:stylesheet>
Happy Hacking
Rory
More information about the talk
mailing list