public final class GPX extends Object implements Serializable
final GPX gpx = GPX.builder()
.addTrack(track -> track
.addSegment(segment -> segment
.addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(160))
.addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(161))
.addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(162))))
.build();
final GPX gpx = GPX.read("track.xml");
final boolean lenient = true;
final GPX gpx = GPX.read("track.xml", lenient);
This allows to read otherwise invalid GPX files, like
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="GPSBabel - http://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/0">
<metadata>
<time>2015-11-13T15:22:42.140Z</time>
<bounds minlat="-37050536.000000000" minlon="-0.000000000" maxlat="48.359161377" maxlon="16.448385239"/>
</metadata>
<trk>
<name>track-1</name>
<desc>Log every 3 sec, 0 m</desc>
<trkseg>
<trkpt></trkpt>
<trkpt lat="48.199352264" lon="16.403341293">
<ele>4325376.000000</ele>
<time>2015-10-23T17:07:08Z</time>
<speed>2.650000</speed>
<name>TP000001</name>
</trkpt>
<trkpt lat="6.376383781" lon="-0.000000000">
<ele>147573952589676412928.000000</ele>
<time>1992-07-19T10:10:58Z</time>
<speed>464.010010</speed>
<name>TP000002</name>
</trkpt>
<trkpt lat="-37050536.000000000" lon="0.000475423">
<ele>0.000000</ele>
<time>2025-12-17T05:10:27Z</time>
<speed>56528.671875</speed>
<name>TP000003</name>
</trkpt>
<trkpt></trkpt>
</trkseg>
</trk>
</gpx>
which is read as
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="GPSBabel - http://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/0">
<metadata>
<time>2015-11-13T15:22:42.140Z</time>
</metadata>
<trk>
<name>track-1</name>
<desc>Log every 3 sec, 0 m</desc>
<trkseg>
<trkpt lat="48.199352264" lon="16.403341293">
<ele>4325376.000000</ele>
<time>2015-10-23T17:07:08Z</time>
<speed>2.650000</speed>
<name>TP000001</name>
</trkpt>
<trkpt lat="6.376383781" lon="-0.000000000">
<ele>147573952589676412928.000000</ele>
<time>1992-07-19T10:10:58Z</time>
<speed>464.010010</speed>
<name>TP000002</name>
</trkpt>
</trkseg>
</trk>
</gpx>
Modifier and Type | Class and Description |
---|---|
static class |
GPX.Builder
Builder class for creating immutable
GPX objects. |
Modifier and Type | Field and Description |
---|---|
static String |
CREATOR
The default creator string.
|
static String |
VERSION
The default version number: 1.1.
|
Modifier and Type | Method and Description |
---|---|
static GPX.Builder |
builder()
Create a new GPX builder.
|
static GPX.Builder |
builder(String creator)
Create a new GPX builder with the given GPX creator string.
|
static GPX.Builder |
builder(String version,
String creator)
Create a new GPX builder with the given GPX version and creator string.
|
boolean |
equals(Object obj) |
String |
getCreator()
Return the name or URL of the software that created your GPX document.
|
Optional<Metadata> |
getMetadata()
Return the metadata of the GPX file.
|
List<Route> |
getRoutes()
Return an unmodifiable list of the
GPX routes. |
List<Track> |
getTracks()
Return an unmodifiable list of the
GPX tracks. |
String |
getVersion()
Return the version number of the GPX file.
|
List<WayPoint> |
getWayPoints()
Return an unmodifiable list of the
GPX way-points. |
int |
hashCode() |
static GPX |
of(String creator,
Metadata metadata,
List<WayPoint> wayPoints,
List<Route> routes,
List<Track> tracks)
Create a new
GPX object with the given data. |
static GPX |
of(String version,
String creator,
Metadata metadata,
List<WayPoint> wayPoints,
List<Route> routes,
List<Track> tracks)
Create a new
GPX object with the given data. |
static GPX |
read(InputStream input)
Read an GPX object from the given
input stream. |
static GPX |
read(InputStream input,
boolean lenient)
Read an GPX object from the given
input stream. |
static GPX |
read(Path path)
Read an GPX object from the given
input stream. |
static GPX |
read(Path path,
boolean lenient)
Read an GPX object from the given
input stream. |
static GPX |
read(String path)
Read an GPX object from the given
input stream. |
static GPX |
read(String path,
boolean lenient)
Read an GPX object from the given
input stream. |
Stream<Route> |
routes()
Return a stream of the
GPX routes. |
GPX.Builder |
toBuilder()
Convert the immutable GPX object into a mutable
builder initialized with the current GPX values.
|
String |
toString() |
Stream<Track> |
tracks()
Return a stream of the
GPX tracks. |
Stream<WayPoint> |
wayPoints()
Return a stream with all
WayPoint s of this GPX object. |
static void |
write(GPX gpx,
OutputStream output)
Writes the given
gpx object (in GPX XML format) to the given
output stream. |
static void |
write(GPX gpx,
OutputStream output,
String indent)
Writes the given
gpx object (in GPX XML format) to the given
output stream. |
static void |
write(GPX gpx,
Path path)
Writes the given
gpx object (in GPX XML format) to the given
output stream. |
static void |
write(GPX gpx,
Path path,
String indent)
Writes the given
gpx object (in GPX XML format) to the given
output stream. |
static void |
write(GPX gpx,
String path)
Writes the given
gpx object (in GPX XML format) to the given
output stream. |
static void |
write(GPX gpx,
String path,
String indent)
Writes the given
gpx object (in GPX XML format) to the given
output stream. |
public static final String VERSION
public static final String CREATOR
public String getVersion()
public String getCreator()
public Optional<Metadata> getMetadata()
public List<WayPoint> getWayPoints()
GPX
way-points.GPX
way-points.public Stream<WayPoint> wayPoints()
WayPoint
s of this GPX
object.WayPoint
s of this GPX
objectpublic List<Route> getRoutes()
GPX
routes.GPX
routes.public Stream<Route> routes()
GPX
routes.GPX
routes.public List<Track> getTracks()
GPX
tracks.GPX
tracks.public Stream<Track> tracks()
GPX
tracks.GPX
tracks.public GPX.Builder toBuilder()
this
GPX objectpublic static GPX.Builder builder(String version, String creator)
version
- the GPX version stringcreator
- the GPX creatorNullPointerException
- if one of the arguments is null
public static GPX.Builder builder(String creator)
creator
- the GPX creatorNullPointerException
- if the given arguments is null
public static GPX.Builder builder()
public static GPX of(String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks)
GPX
object with the given data.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 tracksGPX
object with the given dataNullPointerException
- if the creator
, {code wayPoints},
routes
or tracks
is null
public static GPX of(String version, String creator, Metadata metadata, List<WayPoint> wayPoints, List<Route> routes, List<Track> tracks)
GPX
object with the given data.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 tracksGPX
object with the given dataNullPointerException
- if the creator
, {code wayPoints},
routes
or tracks
is null
public static void write(GPX gpx, OutputStream output) throws IOException
gpx
object (in GPX XML format) to the given
output
stream.gpx
- the GPX object to write to the outputoutput
- the output stream where the GPX object is written toIOException
- if the writing of the GPX object failsNullPointerException
- if one of the given arguments is null
public static void write(GPX gpx, Path path) throws IOException
gpx
object (in GPX XML format) to the given
output
stream.gpx
- the GPX object to write to the outputpath
- the output path where the GPX object is written toIOException
- if the writing of the GPX object failsNullPointerException
- if one of the given arguments is null
public static void write(GPX gpx, String path) throws IOException
gpx
object (in GPX XML format) to the given
output
stream.gpx
- the GPX object to write to the outputpath
- the output path where the GPX object is written toIOException
- if the writing of the GPX object failsNullPointerException
- if one of the given arguments is null
public static void write(GPX gpx, OutputStream output, String indent) throws IOException
gpx
object (in GPX XML format) to the given
output
stream.gpx
- the GPX object to write to the outputoutput
- the output stream where the GPX object is written toindent
- the indent string for pretty printing. If the string is
null
, no pretty printing is performed.IOException
- if the writing of the GPX object failsNullPointerException
- if one of the given arguments is null
public static void write(GPX gpx, Path path, String indent) throws IOException
gpx
object (in GPX XML format) to the given
output
stream.gpx
- the GPX object to write to the outputpath
- the output path where the GPX object is written toindent
- the indent string for pretty printing. If the string is
null
, no pretty printing is performed.IOException
- if the writing of the GPX object failsNullPointerException
- if one of the given arguments is null
public static void write(GPX gpx, String path, String indent) throws IOException
gpx
object (in GPX XML format) to the given
output
stream.gpx
- the GPX object to write to the outputpath
- the output path where the GPX object is written toindent
- the indent string for pretty printing. If the string is
null
, no pretty printing is performed.IOException
- if the writing of the GPX object failsNullPointerException
- if one of the given arguments is null
public static GPX read(InputStream input, boolean lenient) throws IOException
input
stream.input
- the input stream from where the GPX date is readlenient
- if true
, out-of-range and syntactical errors are
ignored. E.g. a WayPoint
with lat
values not in
the valid range of [-90..90] are ignored/skipped.IOException
- if the GPX object can't be readNullPointerException
- if the given input
stream is
null
public static GPX read(InputStream input) throws IOException
input
stream.input
- the input stream from where the GPX date is readIOException
- if the GPX object can't be readNullPointerException
- if the given input
stream is
null
public static GPX read(Path path, boolean lenient) throws IOException
input
stream.path
- the input path from where the GPX date is readlenient
- if true
, out-of-range and syntactical errors are
ignored. E.g. a WayPoint
with lat
values not in
the valid range of [-90..90] are ignored/skipped.IOException
- if the GPX object can't be readNullPointerException
- if the given input
stream is
null
public static GPX read(Path path) throws IOException
input
stream.path
- the input path from where the GPX date is readIOException
- if the GPX object can't be readNullPointerException
- if the given input
stream is
null
public static GPX read(String path, boolean lenient) throws IOException
input
stream.path
- the input path from where the GPX date is readlenient
- if true
, out-of-range and syntactical errors are
ignored. E.g. a WayPoint
with lat
values not in
the valid range of [-90..90] are ignored/skipped.IOException
- if the GPX object can't be readNullPointerException
- if the given input
stream is
null
public static GPX read(String path) throws IOException
input
stream.path
- the input path from where the GPX date is readIOException
- if the GPX object can't be readNullPointerException
- if the given input
stream is
null
© 2016-2017 Franz Wilhelmstötter (2017-02-22 21:53)