Module io.jenetics.jpx
module io.jenetics.jpx
JPX is a library for creating, reading and writing
GPS
data in GPX
format. It is a full implementation of version
1.1 and version
1.0 of the GPX format.
The data classes are completely immutable and allows a functional programming
style. It is also possible to convert the location information into strings
which are compatible to the
ISO 6709 standard.
Writing a GPX file
This will produce the following output.
Reading a GPX file
Reading erroneous GPX files
This allows to read otherwise invalid GPX files, like
which is read as (if you write it again)
Converting a GPX object to an XML
Examples:
Creating a GPX object with one track-segment and 3 track-points
final GPX gpx = GPX.builder()
.addTrack(track -> track
.addSegment(segment -> segment
.addPoint(p -> p.lat(48.20100).lon(16.31651).ele(283))
.addPoint(p -> p.lat(48.20112).lon(16.31639).ele(278))
.addPoint(p -> p.lat(48.20126).lon(16.31601).ele(274))))
.build();
final var indent = new GPX.Writer.Indent(" ");
GPX.Writer.of(indent).write(gpx, Path.of("points.gpx"));
<gpx version="1.1" creator="JPX - https://github.com/jenetics/jpx" xmlns="http://www.topografix.com/GPX/1/1">
<trk>
<trkseg>
<trkpt lat="48.201" lon="16.31651">
<ele>283</ele>
</trkpt>
<trkpt lat="48.20112" lon="16.31639">
<ele>278</ele>
</trkpt>
<trkpt lat="48.20126" lon="16.31601">
<ele>274</ele>
</trkpt>
</trkseg>
</trk>
</gpx>
final GPX gpx = GPX.read("points.xml");
final GPX gpx = GPX.Reader.of(GPX.Reader.Mode.LENIENT).read("track.xml");
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="GPSBabel - http://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/1">
<metadata>
<time>2019-12-31T21:36:04.134Z</time>
<bounds minlat="48.175186667" minlon="16.299580000" maxlat="48.199555000" maxlon="16.416933333"/>
</metadata>
<trk>
<trkseg>
<trkpt lat="48.184298333" lon="16.299580000">
<ele>0.000</ele>
<time>2011-03-20T09:47:16Z</time>
<geoidheight>43.5</geoidheight>
<fix>2d</fix>
<sat>3</sat>
<hdop>4.200000</hdop>
<vdop>1.000000</vdop>
<pdop>4.300000</pdop>
</trkpt>
<trkpt lat="48.175186667" lon="16.303916667">
<ele>0.000</ele>
<time>2011-03-20T09:51:31Z</time>
<geoidheight>43.5</geoidheight>
<fix>2d</fix>
<sat>3</sat>
<hdop>16.600000</hdop>
<vdop>0.900000</vdop>
<pdop>16.600000</pdop>
</trkpt>
</trkseg>
</trk>
</gpx>
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="GPSBabel - http://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/1">
<metadata>
<time>2019-12-31T21:36:04.134Z</time>
<bounds minlat="48.175187" minlon="16.29958" maxlat="48.199555" maxlon="16.416933"></bounds>
</metadata>
<trk>
<trkseg>
<trkpt lat="48.184298" lon="16.29958">
<ele>0</ele>
<time>2011-03-20T09:47:16Z</time>
<geoidheight>43.5</geoidheight>
<fix>2d</fix>
<sat>3</sat>
<hdop>4.2</hdop>
<vdop>1</vdop>
<pdop>4.3</pdop>
</trkpt>
<trkpt lat="48.175187" lon="16.303917">
<ele>0</ele>
<time>2011-03-20T09:51:31Z</time>
<geoidheight>43.5</geoidheight>
<fix>2d</fix>
<sat>3</sat>
<hdop>16.6</hdop>
<vdop>0.9</vdop>
<pdop>16.6</pdop>
</trkpt>
</trkseg>
</trk>
</gpx>
Document
final GPX gpx = ...;
final Document doc = XMLProvider.provider()
.documentBuilderFactory()
.newDocumentBuilder()
.newDocument();
// The GPX data are written to the empty `doc` object.
GPX.Writer.DEFAULT.write(gpx, new DOMResult(doc));