java.lang.Object
io.jenetics.jpx.GPX
- All Implemented Interfaces:
Serializable
GPX documents contain a metadata header, followed by way-points, routes, and
tracks. You can add your own elements to the extensions section of the GPX
document.
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));- Since:
- 1.0
- Version:
- 2.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder class for creating immutableGPXobjects.static final classClass for reading GPX files.static enumRepresents the available GPX versions.static final classClass for writing GPX files. -
Method Summary
Modifier and TypeMethodDescriptionstatic GPX.Builderbuilder()Create a new GPX builder.static GPX.Builderbuilder(GPX.Version version, String creator) Create a new GPX builder with the given GPX version and creator string.static GPX.BuilderCreate a new GPX builder with the given GPX creator string.booleanReturn the name or URL of the software that created your GPX document.Return the (cloned) extensions document.Return the metadata of the GPX file.Return an unmodifiable list of theGPXroutes.Return an unmodifiable list of theGPXtracks.Return the version number of the GPX file.Return an unmodifiable list of theGPXway-points.inthashCode()static GPXof(GPX.Version version, String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks) Create a newGPXobject with the given data.static GPXof(GPX.Version version, String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks, Document extensions) Create a newGPXobject with the given data.static GPXof(String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks) Create a newGPXobject with the given data.static GPXof(String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks, Document extensions) Create a newGPXobject with the given data.static GPXRead an GPX object from the giveninputstream.routes()Return a stream of theGPXroutes.Convert the immutable GPX object into a mutable builder initialized with the current GPX values.toString()tracks()Return a stream of theGPXtracks.Return a stream with allWayPoints of thisGPXobject.static voidWrites the givengpxobject (in GPX XML format) to the givenpath.
-
Method Details
-
getVersion
Return the version number of the GPX file.- Returns:
- the version number of the GPX file
-
getCreator
Return the name or URL of the software that created your GPX document. This allows others to inform the creator of a GPX instance document that fails to validate.- Returns:
- the name or URL of the software that created your GPX document
-
getMetadata
Return the metadata of the GPX file.- Returns:
- the metadata of the GPX file
-
getWayPoints
Return an unmodifiable list of theGPXway-points.- Returns:
- an unmodifiable list of the
GPXway-points.
-
wayPoints
Return a stream with allWayPoints of thisGPXobject.- Returns:
- a stream with all
WayPoints of thisGPXobject
-
getRoutes
Return an unmodifiable list of theGPXroutes.- Returns:
- an unmodifiable list of the
GPXroutes.
-
routes
Return a stream of theGPXroutes.- Returns:
- a stream of the
GPXroutes.
-
getTracks
Return an unmodifiable list of theGPXtracks.- Returns:
- an unmodifiable list of the
GPXtracks.
-
tracks
Return a stream of theGPXtracks.- Returns:
- a stream of the
GPXtracks.
-
getExtensions
Return the (cloned) extensions document. The root element of the returned document has the nameextensions.<extensions> ... </extensions>- Returns:
- the extensions document
- Since:
- 1.5
-
toBuilder
Convert the immutable GPX object into a mutable builder initialized with the current GPX values.- Returns:
- a new track builder initialized with the values of
thisGPX object - Since:
- 1.1
-
toString
-
hashCode
-
equals
-
builder
Create a new GPX builder with the given GPX version and creator string.- Parameters:
version- the GPX versioncreator- the GPX creator- Returns:
- new GPX builder
- Throws:
NullPointerException- if one of the arguments isnull- Since:
- 1.3
-
builder
Create a new GPX builder with the given GPX creator string.- Parameters:
creator- the GPX creator- Returns:
- new GPX builder
- Throws:
NullPointerException- if the given arguments isnull
-
builder
Create a new GPX builder.- Returns:
- new GPX builder
-
of
public static GPX of(GPX.Version version, String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks, Document extensions) Create a newGPXobject with the given data.- Parameters:
creator- the name or URL of the software that created your GPX document. This allows others to inform the creator of a GPX instance document that fails to validate.version- the GPX versionmetadata- the metadata about the GPS filewayPoints- the way-pointsroutes- the routestracks- the tracksextensions- the XML extensions- Returns:
- a new
GPXobject with the given data - Throws:
NullPointerException- if thecreator, {code wayPoints},routesortracksisnull- Since:
- 1.5
-
of
public static GPX of(String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks) Create a newGPXobject with the given data.- Parameters:
creator- the name or URL of the software that created your GPX document. This allows others to inform the creator of a GPX instance document that fails to validate.metadata- the metadata about the GPS filewayPoints- the way-pointsroutes- the routestracks- the tracks- Returns:
- a new
GPXobject with the given data - Throws:
NullPointerException- if thecreator, {code wayPoints},routesortracksisnull
-
of
public static GPX of(String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks, Document extensions) Create a newGPXobject with the given data.- Parameters:
creator- the name or URL of the software that created your GPX document. This allows others to inform the creator of a GPX instance document that fails to validate.metadata- the metadata about the GPS filewayPoints- the way-pointsroutes- the routestracks- the tracksextensions- the XML extensions- Returns:
- a new
GPXobject with the given data - Throws:
NullPointerException- if thecreator, {code wayPoints},routesortracksisnull- Since:
- 1.5
-
of
public static GPX of(GPX.Version version, String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks) Create a newGPXobject with the given data.- Parameters:
creator- the name or URL of the software that created your GPX document. This allows others to inform the creator of a GPX instance document that fails to validate.version- the GPX versionmetadata- the metadata about the GPS filewayPoints- the way-pointsroutes- the routestracks- the tracks- Returns:
- a new
GPXobject with the given data - Throws:
NullPointerException- if thecreator, {code wayPoints},routesortracksisnull
-
write
Writes the givengpxobject (in GPX XML format) to the givenpath. This method is a shortcut forGPX.Writer.DEFAULT.write(gpx, path);- Parameters:
gpx- the GPX object to write to the outputpath- the output path where the GPX object is written to- Throws:
IOException- if the writing of the GPX object failsNullPointerException- if one of the given arguments isnull- Since:
- 1.1
- See Also:
-
read
Read an GPX object from the giveninputstream. This method is a shortcut forGPX.Reader.DEFAULT.read(path);- Parameters:
path- the input path from where the GPX date is read- Returns:
- the GPX object read from the input stream
- Throws:
IOException- if the GPX object can't be readNullPointerException- if the giveninputstream isnull- See Also:
-