Package org.openstreetmap.josm.data.gpx
Class GpxData
- java.lang.Object
-
- org.openstreetmap.josm.data.gpx.WithAttributes
-
- org.openstreetmap.josm.data.gpx.GpxData
-
- All Implemented Interfaces:
Data
,GpxConstants
,IGpxLayerPrefs
,IWithAttributes
public class GpxData extends WithAttributes implements Data, IGpxLayerPrefs
Objects of this class represent a gpx file with tracks, waypoints and routes. It uses GPX v1.1, see the spec for details.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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-
Nested classes/interfaces inherited from interface org.openstreetmap.josm.data.gpx.GpxConstants
GpxConstants.ColorFormat
-
-
Field Summary
Fields Modifier and Type Field Description String
creator
Creator metadata for this file (usually software)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.boolean
fromSession
A boolean flag indicating if the data was read from a session file.private boolean
initializing
private Map<String,String>
layerPrefs
The layer specific prefs formerly saved in the preferences, e.g.private ListenerList<GpxData.GpxDataChangeListener>
listeners
private boolean
modified
private List<GpxData.XMLNamespace>
namespaces
All namespaces read from the original fileprivate ArrayList<GpxRoute>
privateRoutes
GPX routes in this fileprivate ArrayList<IGpxTrack>
privateTracks
A list of tracks this file consists ofprivate ArrayList<WayPoint>
privateWaypoints
Additional waypoints for this file.private IGpxTrack.GpxTrackChangeListener
proxy
Collection<GpxRoute>
routes
Routes.private List<GpxData.GpxTrackSegmentSpan>
segSpans
File
storageFile
The disk file this layer is stored in, if it is a local layer.private boolean
suppressedInvalidate
Collection<IGpxTrack>
tracks
Tracks.private boolean
updating
Collection<WayPoint>
waypoints
Waypoints.-
Fields inherited from class org.openstreetmap.josm.data.gpx.WithAttributes
attr
-
Fields inherited from interface org.openstreetmap.josm.data.gpx.GpxConstants
EXTENSION_ABBREVIATIONS, FIX_VALUES, GARMIN_COLORS, GPX_CMT, GPX_DESC, GPX_NAME, GPX_PREFIX, GPX_SRC, JOSM_CREATOR_NAME, 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 Summary
Constructors Constructor Description GpxData()
Constructs a new GpxData.GpxData(boolean initializing)
Constructs a new GpxData that is currently being initialized, so no listeners will be fired untilendUpdate()
is called.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeListener(GpxData.GpxDataChangeListener listener)
Adds a listener that gets called whenever the data changed.void
addRoute(GpxRoute route)
Add a new routevoid
addTrack(IGpxTrack track)
Add a new trackvoid
addWaypoint(WayPoint waypoint)
Add a new waypointvoid
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.void
clear()
Removes all gpx elementsprivate 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, Map<String,Object> attr)
private void
cutOverlapping(IGpxTrack trk, boolean connect)
void
endUpdate()
Finishes updating this GpxData and fires listeners if required.static String
ensureUniqueName(Map<String,Object> attrs, Map<String,Integer> counts, String srcLayerName)
Ensures a unique name among gpx layersboolean
equals(Object obj)
private void
fireInvalidate(boolean setModified)
Collection<DataSource>
getDataSources()
Returns the collection of data sources.Map<String,String>
getLayerPrefs()
The layer specific prefs formerly saved in the preferences, e.g.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.Optional<Interval>
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 methodstatic Optional<Interval>
getMinMaxTimeForTrack(IGpxTrack trk)
returns minimum and maximum timestamps in the trackList<GpxData.XMLNamespace>
getNamespaces()
All XML namespaces read from the original fileList<IGpxTrack>
getOrderedTracks()
Get all tracks contained in this data set, ordered chronologically.Collection<GpxRoute>
getRoutes()
Gets the list of all routes defined in this data set.List<GpxData.GpxTrackSegmentSpan>
getSegmentSpans()
Get a list of SegmentSpans containing the beginning and end of each segmentint
getTrackCount()
Replies the current number of tracks in this GpxDataprivate static OptionalLong
getTrackFirstWaypointMin(IGpxTrack track)
Stream<WayPoint>
getTrackPoints()
Gets a stream of all track points in the segments of the tracks of this data.Collection<IGpxTrack>
getTracks()
Get all tracks contained in this data set, without any guaranteed order.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.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 pointsboolean
hasTrackPoints()
Determines if this GPX data has one or more track pointsvoid
invalidate()
Fires event listeners and sets the modified flag to true.boolean
isEmpty()
Determines if this GPX data is empty (i.e.boolean
isModified()
Determines whether anything has been modified.double
length()
calculates the sum of the lengths of all track segmentsvoid
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 trackvoid
put(String key, 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 routevoid
removeTrack(IGpxTrack track)
Remove a trackvoid
removeWaypoint(WayPoint waypoint)
Remove a waypointvoid
resetEastNorthCache()
Resets the internal caches of east/north coordinates.void
setModified(boolean value)
Sets the modified flag to the value.void
splitTrackSegmentsToTracks(String srcLayerName)
Split tracks so that only single-segment tracks remain.void
splitTracksToLayers(String srcLayerName)
Split tracks into layers, the result is one layer for each track.-
Methods inherited from class org.openstreetmap.josm.data.gpx.WithAttributes
get, getAttributes, getCollection, getExtensions, getString, hasExtensions
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.Data
getDataSourceArea, getDataSourceBounds
-
-
-
-
Field Detail
-
storageFile
public File storageFile
The disk file this layer is stored in, if it is a local layer. May benull
.
-
fromServer
public boolean fromServer
A boolean flag indicating if the data was read from the OSM server.
-
fromSession
public boolean fromSession
A boolean flag indicating if the data was read from a session file.- Since:
- 18287
-
privateTracks
private final ArrayList<IGpxTrack> privateTracks
A list of tracks this file consists of
-
privateRoutes
private final ArrayList<GpxRoute> privateRoutes
GPX routes in this file
-
privateWaypoints
private final ArrayList<WayPoint> privateWaypoints
Additional waypoints for this file.
-
namespaces
private final List<GpxData.XMLNamespace> namespaces
All namespaces read from the original file
-
layerPrefs
private final Map<String,String> layerPrefs
The layer specific prefs formerly saved in the preferences, e.g. drawing options. NOT the track specific settings (e.g. color, width)
-
proxy
private final IGpxTrack.GpxTrackChangeListener proxy
-
modified
private boolean modified
-
updating
private boolean updating
-
initializing
private boolean initializing
-
suppressedInvalidate
private boolean suppressedInvalidate
-
tracks
public final Collection<IGpxTrack> tracks
Tracks. Access is discouraged, usegetTracks()
to read.- See Also:
getTracks()
-
routes
public final Collection<GpxRoute> routes
Routes. Access is discouraged, usegetTracks()
to read.- See Also:
getRoutes()
-
waypoints
public final Collection<WayPoint> waypoints
Waypoints. Access is discouraged, usegetTracks()
to read.- See Also:
getWaypoints()
-
dataSources
public final 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.- Since:
- 7575
-
listeners
private final ListenerList<GpxData.GpxDataChangeListener> listeners
-
segSpans
private List<GpxData.GpxTrackSegmentSpan> segSpans
-
-
Constructor Detail
-
GpxData
public GpxData()
Constructs a new GpxData.
-
GpxData
public GpxData(boolean initializing)
Constructs a new GpxData that is currently being initialized, so no listeners will be fired untilendUpdate()
is called.- Parameters:
initializing
- true- Since:
- 15496
-
-
Method Detail
-
mergeFrom
public void mergeFrom(GpxData other)
Merges data from another object.- Parameters:
other
- existing GPX data
-
mergeFrom
public void mergeFrom(GpxData other, boolean cutOverlapping, boolean connect)
Merges data from another object.- Parameters:
other
- existing GPX datacutOverlapping
- whether overlapping parts of the given track should be removedconnect
- whether the tracks should be connected on cuts- Since:
- 14338
-
cutOverlapping
private void cutOverlapping(IGpxTrack trk, boolean connect)
-
connectTracks
private void connectTracks(WayPoint prevWp, GpxData.GpxTrackSegmentSpan span, Map<String,Object> attr)
-
getSegmentSpans
public List<GpxData.GpxTrackSegmentSpan> getSegmentSpans()
Get a list of SegmentSpans containing the beginning and end of each segment- Returns:
- the list of SegmentSpans
- Since:
- 14338
-
anySegmentOverlapsWith
private boolean anySegmentOverlapsWith(GpxData.GpxTrackSegmentSpan other)
-
getTracks
public Collection<IGpxTrack> getTracks()
Get all tracks contained in this data set, without any guaranteed order.- Returns:
- The tracks.
-
getOrderedTracks
public List<IGpxTrack> getOrderedTracks()
Get all tracks contained in this data set, ordered chronologically.- Returns:
- The tracks in chronological order.
- Since:
- 18207
-
getTrackFirstWaypointMin
private static OptionalLong getTrackFirstWaypointMin(IGpxTrack track)
-
getTrackSegmentsStream
public Stream<IGpxTrackSegment> getTrackSegmentsStream()
Get stream of track segments.- Returns:
Stream<GPXTrack>
-
clearTracks
private void clearTracks()
Clear all tracks, empties the current privateTracks container, helper method for some gpx manipulations.
-
addTrack
public void addTrack(IGpxTrack track)
Add a new track- Parameters:
track
- The new track- Since:
- 12156
-
removeTrack
public void removeTrack(IGpxTrack track)
Remove a track- Parameters:
track
- The old track- Since:
- 12156
-
combineTracksToSegmentedTrack
public void combineTracksToSegmentedTrack()
Combine tracks into a single, segmented track. The attributes of the first track are used, the rest discarded.- Since:
- 13210
-
ensureUniqueName
public static String ensureUniqueName(Map<String,Object> attrs, Map<String,Integer> counts, String srcLayerName)
Ensures a unique name among gpx layers- Parameters:
attrs
- attributes of/for an gpx track, written to if the name appeared previously incounts
.counts
- aHashMap
of previously seen names, associated with their count.srcLayerName
- Source layer name- Returns:
- the unique name for the gpx track.
- Since:
- 15397
-
splitTrackSegmentsToTracks
public void splitTrackSegmentsToTracks(String srcLayerName)
Split tracks so that only single-segment tracks remain. Each segment will make up one individual track after this operation.- Parameters:
srcLayerName
- Source layer name- Since:
- 15397
-
splitTracksToLayers
public void splitTracksToLayers(String srcLayerName)
Split tracks into layers, the result is one layer for each track. If this layer currently has only one GpxTrack this is a no-operation. The new GpxLayers are added to the LayerManager, the original GpxLayer is untouched as to preserve potential route or wpt parts.- Parameters:
srcLayerName
- Source layer name- Since:
- 15397
-
getTrackCount
public int getTrackCount()
Replies the current number of tracks in this GpxData- Returns:
- track count
- Since:
- 13210
-
getTrackSegsCount
public int getTrackSegsCount()
Replies the accumulated total of all track segments, the sum of segment counts for each track present.- Returns:
- track segments count
- Since:
- 13210
-
getRoutes
public Collection<GpxRoute> getRoutes()
Gets the list of all routes defined in this data set.- Returns:
- The routes
- Since:
- 12156
-
addRoute
public void addRoute(GpxRoute route)
Add a new route- Parameters:
route
- The new route- Since:
- 12156
-
removeRoute
public void removeRoute(GpxRoute route)
Remove a route- Parameters:
route
- The old route- Since:
- 12156
-
getWaypoints
public Collection<WayPoint> getWaypoints()
Gets a list of all way points in this data set.- Returns:
- The way points.
- Since:
- 12156
-
addWaypoint
public void addWaypoint(WayPoint waypoint)
Add a new waypoint- Parameters:
waypoint
- The new waypoint- Since:
- 12156
-
removeWaypoint
public void removeWaypoint(WayPoint waypoint)
Remove a waypoint- Parameters:
waypoint
- The old waypoint- Since:
- 12156
-
hasTrackPoints
public boolean hasTrackPoints()
Determines if this GPX data has one or more track points- Returns:
true
if this GPX data has track points,false
otherwise
-
getTrackPoints
public Stream<WayPoint> getTrackPoints()
Gets a stream of all track points in the segments of the tracks of this data.- Returns:
- The stream
- Since:
- 12156
- See Also:
getTracks()
,IGpxTrack.getSegments()
,IGpxTrackSegment.getWayPoints()
-
hasRoutePoints
public boolean hasRoutePoints()
Determines if this GPX data has one or more route points- Returns:
true
if this GPX data has route points,false
otherwise
-
isEmpty
public boolean isEmpty()
Determines if this GPX data is empty (i.e. does not contain any point)- Returns:
true
if this GPX data is empty,false
otherwise
-
getMetaBounds
public Bounds getMetaBounds()
Returns the bounds defining the extend of this data, as read in metadata, if any. If no bounds is defined in metadata,null
is returned. There is no guarantee that data entirely fit in this bounds, as it is not recalculated. To get recalculated bounds, seerecalculateBounds()
. To get downloaded areas, seedataSources
.- Returns:
- the bounds defining the extend of this data, or
null
. - Since:
- 7575
- See Also:
recalculateBounds()
,dataSources
-
recalculateBounds
public Bounds recalculateBounds()
Calculates the bounding box of available data and returns it. The bounds are not stored internally, but recalculated every time this function is called.
To get bounds as read from metadata, seegetMetaBounds()
.
To get downloaded areas, seedataSources
.
FIXME might perhaps use visitor pattern?- Returns:
- the bounds
- See Also:
getMetaBounds()
,dataSources
-
length
public double length()
calculates the sum of the lengths of all track segments- Returns:
- the length in meters
-
getMinMaxTimeForTrack
public static Optional<Interval> getMinMaxTimeForTrack(IGpxTrack trk)
returns minimum and maximum timestamps in the track- Parameters:
trk
- track to analyze- Returns:
- minimum and maximum as interval
-
getMinMaxTimeForAllTracks
public Optional<Interval> 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- Returns:
- minimum and maximum as interval
- Since:
- 7319
-
nearestPointOnTrack
public 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- Parameters:
p
- : the point to determine the projection fortolerance
- : must be no further than this from the track- Returns:
- the closest point on the track to p, which may be the first or last point if off the end of a segment, or may be null if nothing close enough
-
getLinesIterable
public Iterable<Line> getLinesIterable(boolean... trackVisibility)
Iterate over all track segments and over all routes.- Parameters:
trackVisibility
- An array indicating which tracks should be included in the iteration. Can be null, then all tracks are included.- Returns:
- an Iterable object, which iterates over all track segments and over all routes
-
resetEastNorthCache
public void resetEastNorthCache()
Resets the internal caches of east/north coordinates.
-
getDataSources
public Collection<DataSource> getDataSources()
Description copied from interface:Data
Returns the collection of data sources.- Specified by:
getDataSources
in interfaceData
- Returns:
- the collection of data sources.
-
getLayerPrefs
public Map<String,String> getLayerPrefs()
Description copied from interface:IGpxLayerPrefs
The layer specific prefs formerly saved in the preferences, e.g. drawing options. NOT the track specific settings (e.g. color, width)- Specified by:
getLayerPrefs
in interfaceIGpxLayerPrefs
- Returns:
- Modifiable map
-
getNamespaces
public List<GpxData.XMLNamespace> getNamespaces()
All XML namespaces read from the original file- Returns:
- Modifiable list
- Since:
- 15496
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classWithAttributes
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classWithAttributes
-
put
public void put(String key, Object value)
Description copied from class:WithAttributes
Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present).- Specified by:
put
in interfaceIWithAttributes
- Overrides:
put
in classWithAttributes
- Parameters:
key
- the keyvalue
- the value
-
addChangeListener
public void addChangeListener(GpxData.GpxDataChangeListener listener)
Adds a listener that gets called whenever the data changed.- Parameters:
listener
- The listener- Since:
- 12156
-
addWeakChangeListener
public void addWeakChangeListener(GpxData.GpxDataChangeListener listener)
Adds a listener that gets called whenever the data changed. It is added with a weak link- Parameters:
listener
- The listener
-
removeChangeListener
public void removeChangeListener(GpxData.GpxDataChangeListener listener)
Removes a listener that gets called whenever the data changed.- Parameters:
listener
- The listener- Since:
- 12156
-
invalidate
public void invalidate()
Fires event listeners and sets the modified flag to true.
-
fireInvalidate
private void fireInvalidate(boolean setModified)
-
beginUpdate
public void beginUpdate()
Begins updating this GpxData and prevents listeners from being fired.- Since:
- 15496
-
endUpdate
public void endUpdate()
Finishes updating this GpxData and fires listeners if required.- Since:
- 15496
-
isModified
public boolean isModified()
Determines whether anything has been modified.- Returns:
- whether anything has been modified (e.g. colors)
- Since:
- 15496
-
setModified
public void setModified(boolean value)
Sets the modified flag to the value.- Specified by:
setModified
in interfaceIGpxLayerPrefs
- Parameters:
value
- modified flag- Since:
- 15496
-
clear
public void clear()
Removes all gpx elements- Since:
- 17439
-
-