public class GpxData extends WithAttributes implements Data
Modifier and Type | Class and Description |
---|---|
static class |
GpxData.GpxDataChangeEvent
A data change event in any of the gpx data.
|
static interface |
GpxData.GpxDataChangeListener
A listener that listens to GPX data changes.
|
(package private) static class |
GpxData.GpxTrackSegmentSpan |
static class |
GpxData.LinesIterator
Iterates over all track segments and then over all routes.
|
static class |
GpxData.XMLNamespace
A class containing prefix, URI and location of a namespace
|
GpxConstants.ColorFormat
Modifier and Type | Field and Description |
---|---|
java.lang.String |
creator
Creator metadata for this file (usually software)
|
java.util.Set<DataSource> |
dataSources
All data sources (bounds of downloaded bounds) of this GpxData.
Not part of GPX standard but rather a JOSM extension, needed by the fact that OSM API does not provide <bounds> element in its GPX reply. |
boolean |
fromServer
A boolean flag indicating if the data was read from the OSM server.
|
private boolean |
initializing |
private java.util.Map<java.lang.String,java.lang.String> |
layerPrefs
The layer specific prefs formerly saved in the preferences, e.g.
|
private ListenerList<GpxData.GpxDataChangeListener> |
listeners |
private boolean |
modified |
private java.util.List<GpxData.XMLNamespace> |
namespaces
All namespaces read from the original file
|
private java.util.ArrayList<GpxRoute> |
privateRoutes
GPX routes in this file
|
private java.util.ArrayList<IGpxTrack> |
privateTracks
A list of tracks this file consists of
|
private java.util.ArrayList<WayPoint> |
privateWaypoints
Addidionaly waypoints for this file.
|
private IGpxTrack.GpxTrackChangeListener |
proxy |
java.util.Collection<GpxRoute> |
routes
Routes.
|
private java.util.List<GpxData.GpxTrackSegmentSpan> |
segSpans |
java.io.File |
storageFile
The disk file this layer is stored in, if it is a local layer.
|
private boolean |
suppressedInvalidate |
java.util.Collection<IGpxTrack> |
tracks
Tracks.
|
private boolean |
updating |
java.util.Collection<WayPoint> |
waypoints
Waypoints.
|
attr
EXTENSION_ABBREVIATIONS, FIX_VALUES, GARMIN_COLORS, GPX_CMT, GPX_DESC, GPX_NAME, GPX_PREFIX, GPX_SRC, META_AUTHOR_EMAIL, META_AUTHOR_LINK, META_AUTHOR_NAME, META_BOUNDS, META_COPYRIGHT_AUTHOR, META_COPYRIGHT_LICENSE, META_COPYRIGHT_YEAR, META_DESC, META_KEYWORDS, META_LINKS, META_NAME, META_PREFIX, META_TIME, PT_AGEOFDGPSDATA, PT_DGPSID, PT_ELE, PT_FIX, PT_GEOIDHEIGHT, PT_HDOP, PT_MAGVAR, PT_PDOP, PT_SAT, PT_SYM, PT_TIME, PT_TYPE, PT_VDOP, RTE_TRK_KEYS, RTKLIB_AGE, RTKLIB_Q, RTKLIB_RATIO, RTKLIB_SDE, RTKLIB_SDEU, RTKLIB_SDN, RTKLIB_SDNE, RTKLIB_SDU, RTKLIB_SDUN, WPT_KEYS, XML_URI_EXTENSIONS_DRAWING, XML_URI_EXTENSIONS_GARMIN, XML_URI_EXTENSIONS_JOSM, XML_URI_XSD, XML_XSD_EXTENSIONS_DRAWING, XML_XSD_EXTENSIONS_GARMIN, XML_XSD_EXTENSIONS_JOSM
Constructor and Description |
---|
GpxData()
Constructs a new GpxData.
|
GpxData(boolean initializing)
Constructs a new GpxData that is currently being initialized, so no listeners will be fired until
endUpdate() is called. |
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(GpxData.GpxDataChangeListener listener)
Adds a listener that gets called whenever the data changed.
|
void |
addRoute(GpxRoute route)
Add a new route
|
void |
addTrack(IGpxTrack track)
Add a new track
|
void |
addWaypoint(WayPoint waypoint)
Add a new waypoint
|
void |
addWeakChangeListener(GpxData.GpxDataChangeListener listener)
Adds a listener that gets called whenever the data changed.
|
private boolean |
anySegmentOverlapsWith(GpxData.GpxTrackSegmentSpan other) |
void |
beginUpdate()
Begins updating this GpxData and prevents listeners from being fired.
|
private void |
clearTracks()
Clear all tracks, empties the current privateTracks container,
helper method for some gpx manipulations.
|
void |
combineTracksToSegmentedTrack()
Combine tracks into a single, segmented track.
|
private void |
connectTracks(WayPoint prevWp,
GpxData.GpxTrackSegmentSpan span,
java.util.Map<java.lang.String,java.lang.Object> attr) |
private void |
cutOverlapping(IGpxTrack trk,
boolean connect) |
void |
endUpdate()
Finishes updating this GpxData and fires listeners if required.
|
static java.lang.String |
ensureUniqueName(java.util.Map<java.lang.String,java.lang.Object> attrs,
java.util.Map<java.lang.String,java.lang.Integer> counts,
java.lang.String srcLayerName)
Ensures a unique name among gpx layers
|
boolean |
equals(java.lang.Object obj) |
private void |
fireInvalidate(boolean setModified) |
java.util.Collection<DataSource> |
getDataSources()
Returns the collection of data sources.
|
java.util.Map<java.lang.String,java.lang.String> |
getLayerPrefs()
The layer specific prefs formerly saved in the preferences, e.g.
|
java.lang.Iterable<Line> |
getLinesIterable(boolean... trackVisibility)
Iterate over all track segments and over all routes.
|
Bounds |
getMetaBounds()
Returns the bounds defining the extend of this data, as read in metadata, if any.
|
java.util.Date[] |
getMinMaxTimeForAllTracks()
Returns minimum and maximum timestamps for all tracks
Warning: there are lot of track with broken timestamps,
so we just ignore points from future and from year before 1970 in this method
|
static java.util.Date[] |
getMinMaxTimeForTrack(IGpxTrack trk)
returns minimum and maximum timestamps in the track
|
java.util.List<GpxData.XMLNamespace> |
getNamespaces()
All XML namespaces read from the original file
|
java.util.Collection<GpxRoute> |
getRoutes()
Gets the list of all routes defined in this data set.
|
java.util.List<GpxData.GpxTrackSegmentSpan> |
getSegmentSpans()
Get a list of SegmentSpans containing the beginning and end of each segment
|
int |
getTrackCount()
Replies the current number of tracks in this GpxData
|
java.util.stream.Stream<WayPoint> |
getTrackPoints()
Gets a stream of all track points in the segments of the tracks of this data.
|
java.util.Collection<IGpxTrack> |
getTracks()
Get all tracks contained in this data set.
|
java.util.stream.Stream<IGpxTrackSegment> |
getTrackSegmentsStream()
Get stream of track segments.
|
int |
getTrackSegsCount()
Replies the accumulated total of all track segments,
the sum of segment counts for each track present.
|
java.util.Collection<WayPoint> |
getWaypoints()
Gets a list of all way points in this data set.
|
int |
hashCode() |
boolean |
hasRoutePoints()
Determines if this GPX data has one or more route points
|
boolean |
hasTrackPoints()
Determines if this GPX data has one or more track points
|
void |
invalidate()
Fires event listeners and sets the modified flag to true.
|
boolean |
isEmpty()
Determines if this GPX data is empty (i.e.
|
boolean |
isModified() |
double |
length()
calculates the sum of the lengths of all track segments
|
void |
mergeFrom(GpxData other)
Merges data from another object.
|
void |
mergeFrom(GpxData other,
boolean cutOverlapping,
boolean connect)
Merges data from another object.
|
WayPoint |
nearestPointOnTrack(EastNorth p,
double tolerance)
Makes a WayPoint at the projection of point p onto the track providing p is less than
tolerance away from the track
|
void |
put(java.lang.String key,
java.lang.Object value)
Put a key / value pair as a new attribute.
|
Bounds |
recalculateBounds()
Calculates the bounding box of available data and returns it.
|
void |
removeChangeListener(GpxData.GpxDataChangeListener listener)
Removes a listener that gets called whenever the data changed.
|
void |
removeRoute(GpxRoute route)
Remove a route
|
void |
removeTrack(IGpxTrack track)
Remove a track
|
void |
removeWaypoint(WayPoint waypoint)
Remove a waypoint
|
void |
resetEastNorthCache()
Resets the internal caches of east/north coordinates.
|
void |
setModified(boolean value)
Sets the modified flag to the value.
|
void |
splitTrackSegmentsToTracks(java.lang.String srcLayerName)
Split tracks so that only single-segment tracks remain.
|
void |
splitTracksToLayers(java.lang.String srcLayerName)
Split tracks into layers, the result is one layer for each track.
|
get, getAttributes, getCollection, getExtensions, getString
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getDataSourceArea, getDataSourceBounds
getExtensionAbbreviations, getGarminColors
public java.io.File storageFile
null
.public boolean fromServer
public java.lang.String creator
private final java.util.ArrayList<IGpxTrack> privateTracks
private final java.util.ArrayList<GpxRoute> privateRoutes
private final java.util.ArrayList<WayPoint> privateWaypoints
private final java.util.List<GpxData.XMLNamespace> namespaces
private final java.util.Map<java.lang.String,java.lang.String> layerPrefs
private final IGpxTrack.GpxTrackChangeListener proxy
private boolean modified
private boolean updating
private boolean initializing
private boolean suppressedInvalidate
public final java.util.Collection<IGpxTrack> tracks
getTracks()
to read.getTracks()
public final java.util.Collection<GpxRoute> routes
getTracks()
to read.getRoutes()
public final java.util.Collection<WayPoint> waypoints
getTracks()
to read.getWaypoints()
public final java.util.Set<DataSource> dataSources
<bounds>
element in its GPX reply.private final ListenerList<GpxData.GpxDataChangeListener> listeners
private java.util.List<GpxData.GpxTrackSegmentSpan> segSpans
public GpxData()
public GpxData(boolean initializing)
endUpdate()
is called.initializing
- truepublic void mergeFrom(GpxData other)
other
- existing GPX datapublic void mergeFrom(GpxData other, boolean cutOverlapping, boolean connect)
other
- existing GPX datacutOverlapping
- whether overlapping parts of the given track should be removedconnect
- whether the tracks should be connected on cutsprivate void cutOverlapping(IGpxTrack trk, boolean connect)
private void connectTracks(WayPoint prevWp, GpxData.GpxTrackSegmentSpan span, java.util.Map<java.lang.String,java.lang.Object> attr)
public java.util.List<GpxData.GpxTrackSegmentSpan> getSegmentSpans()
private boolean anySegmentOverlapsWith(GpxData.GpxTrackSegmentSpan other)
public java.util.Collection<IGpxTrack> getTracks()
public java.util.stream.Stream<IGpxTrackSegment> getTrackSegmentsStream()
Stream<GPXTrack>
private void clearTracks()
public void addTrack(IGpxTrack track)
track
- The new trackpublic void removeTrack(IGpxTrack track)
track
- The old trackpublic void combineTracksToSegmentedTrack()
public static java.lang.String ensureUniqueName(java.util.Map<java.lang.String,java.lang.Object> attrs, java.util.Map<java.lang.String,java.lang.Integer> counts, java.lang.String srcLayerName)
attrs
- attributes of/for an gpx track, written to if the name appeared previously in counts
.counts
- a HashMap
of previously seen names, associated with their count.srcLayerName
- Source layer namepublic void splitTrackSegmentsToTracks(java.lang.String srcLayerName)
srcLayerName
- Source layer namepublic void splitTracksToLayers(java.lang.String srcLayerName)
srcLayerName
- Source layer namepublic int getTrackCount()
public int getTrackSegsCount()
public java.util.Collection<GpxRoute> getRoutes()
public void addRoute(GpxRoute route)
route
- The new routepublic void removeRoute(GpxRoute route)
route
- The old routepublic java.util.Collection<WayPoint> getWaypoints()
public void addWaypoint(WayPoint waypoint)
waypoint
- The new waypointpublic void removeWaypoint(WayPoint waypoint)
waypoint
- The old waypointpublic boolean hasTrackPoints()
true
if this GPX data has track points, false
otherwisepublic java.util.stream.Stream<WayPoint> getTrackPoints()
getTracks()
,
IGpxTrack.getSegments()
,
IGpxTrackSegment.getWayPoints()
public boolean hasRoutePoints()
true
if this GPX data has route points, false
otherwisepublic boolean isEmpty()
true
if this GPX data is empty, false
otherwisepublic Bounds getMetaBounds()
null
is returned. There is no guarantee
that data entirely fit in this bounds, as it is not recalculated. To get recalculated bounds,
see recalculateBounds()
. To get downloaded areas, see dataSources
.null
.recalculateBounds()
,
dataSources
public Bounds recalculateBounds()
getMetaBounds()
.dataSources
.getMetaBounds()
,
dataSources
public double length()
public static java.util.Date[] getMinMaxTimeForTrack(IGpxTrack trk)
trk
- track to analyzepublic java.util.Date[] getMinMaxTimeForAllTracks()
public WayPoint nearestPointOnTrack(EastNorth p, double tolerance)
p
- : the point to determine the projection fortolerance
- : must be no further than this from the trackpublic java.lang.Iterable<Line> getLinesIterable(boolean... trackVisibility)
trackVisibility
- An array indicating which tracks should be
included in the iteration. Can be null, then all tracks are included.public void resetEastNorthCache()
public java.util.Collection<DataSource> getDataSources()
Data
getDataSources
in interface Data
public java.util.Map<java.lang.String,java.lang.String> getLayerPrefs()
public java.util.List<GpxData.XMLNamespace> getNamespaces()
public int hashCode()
hashCode
in class WithAttributes
public boolean equals(java.lang.Object obj)
equals
in class WithAttributes
public void put(java.lang.String key, java.lang.Object value)
WithAttributes
put
in interface IWithAttributes
put
in class WithAttributes
key
- the keyvalue
- the valuepublic void addChangeListener(GpxData.GpxDataChangeListener listener)
listener
- The listenerpublic void addWeakChangeListener(GpxData.GpxDataChangeListener listener)
listener
- The listenerpublic void removeChangeListener(GpxData.GpxDataChangeListener listener)
listener
- The listenerpublic void invalidate()
private void fireInvalidate(boolean setModified)
public void beginUpdate()
public void endUpdate()
public boolean isModified()
public void setModified(boolean value)
value
- modified flag