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 classGpxData.GpxDataChangeEventA data change event in any of the gpx data.static interfaceGpxData.GpxDataChangeListenerA listener that listens to GPX data changes.(package private) static classGpxData.GpxTrackSegmentSpanstatic classGpxData.LinesIteratorIterates over all track segments and then over all routes.static classGpxData.XMLNamespaceA 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 java.lang.StringcreatorCreator metadata for this file (usually software)java.util.Set<DataSource>dataSourcesAll 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.booleanfromServerA boolean flag indicating if the data was read from the OSM server.booleanfromSessionA boolean flag indicating if the data was read from a session file.private booleaninitializingprivate java.util.Map<java.lang.String,java.lang.String>layerPrefsThe layer specific prefs formerly saved in the preferences, e.g.private ListenerList<GpxData.GpxDataChangeListener>listenersprivate booleanmodifiedprivate java.util.List<GpxData.XMLNamespace>namespacesAll namespaces read from the original fileprivate java.util.ArrayList<GpxRoute>privateRoutesGPX routes in this fileprivate java.util.ArrayList<IGpxTrack>privateTracksA list of tracks this file consists ofprivate java.util.ArrayList<WayPoint>privateWaypointsAdditional waypoints for this file.private IGpxTrack.GpxTrackChangeListenerproxyjava.util.Collection<GpxRoute>routesRoutes.private java.util.List<GpxData.GpxTrackSegmentSpan>segSpansjava.io.FilestorageFileThe disk file this layer is stored in, if it is a local layer.private booleansuppressedInvalidatejava.util.Collection<IGpxTrack>tracksTracks.private booleanupdatingjava.util.Collection<WayPoint>waypointsWaypoints.-
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_COURSE, PT_DGPSID, PT_ELE, PT_FIX, PT_GEOIDHEIGHT, PT_HDOP, PT_MAGVAR, PT_PDOP, PT_SAT, PT_STD_HDEV, PT_STD_VDEV, 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 voidaddChangeListener(GpxData.GpxDataChangeListener listener)Adds a listener that gets called whenever the data changed.voidaddRoute(GpxRoute route)Add a new routevoidaddTrack(IGpxTrack track)Add a new trackvoidaddWaypoint(WayPoint waypoint)Add a new waypointvoidaddWeakChangeListener(GpxData.GpxDataChangeListener listener)Adds a listener that gets called whenever the data changed.private booleananySegmentOverlapsWith(GpxData.GpxTrackSegmentSpan other)voidbeginUpdate()Begins updating this GpxData and prevents listeners from being fired.voidclear()Removes all gpx elementsprivate voidclearTracks()Clear all tracks, empties the current privateTracks container, helper method for some gpx manipulations.voidcombineTracksToSegmentedTrack()Combine tracks into a single, segmented track.private voidconnectTracks(WayPoint prevWp, GpxData.GpxTrackSegmentSpan span, java.util.Map<java.lang.String,java.lang.Object> attr)private voidcutOverlapping(IGpxTrack trk, boolean connect)voidendUpdate()Finishes updating this GpxData and fires listeners if required.static java.lang.StringensureUniqueName(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 layersbooleanequals(java.lang.Object obj)private voidfireInvalidate(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.BoundsgetMetaBounds()Returns the bounds defining the extend of this data, as read in metadata, if any.java.util.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 java.util.Optional<Interval>getMinMaxTimeForTrack(IGpxTrack trk)returns minimum and maximum timestamps in the trackjava.util.List<GpxData.XMLNamespace>getNamespaces()All XML namespaces read from the original filejava.util.List<IGpxTrack>getOrderedTracks()Get all tracks contained in this data set, ordered chronologically.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 segmentintgetTrackCount()Replies the current number of tracks in this GpxDataprivate static java.util.OptionalLonggetTrackFirstWaypointMin(IGpxTrack track)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, without any guaranteed order.java.util.stream.Stream<IGpxTrackSegment>getTrackSegmentsStream()Get stream of track segments.intgetTrackSegsCount()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.inthashCode()booleanhasRoutePoints()Determines if this GPX data has one or more route pointsbooleanhasTrackPoints()Determines if this GPX data has one or more track pointsvoidinvalidate()Fires event listeners and sets the modified flag to true.booleanisEmpty()Determines if this GPX data is empty (i.e.booleanisModified()Determines whether anything has been modified.doublelength()calculates the sum of the lengths of all track segmentsvoidmergeFrom(GpxData other)Merges data from another object.voidmergeFrom(GpxData other, boolean cutOverlapping, boolean connect)Merges data from another object.WayPointnearestPointOnTrack(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 trackvoidput(java.lang.String key, java.lang.Object value)Put a key / value pair as a new attribute.voidput(java.lang.String key, java.lang.Object value, boolean setModified)Put a key / value pair as a new attribute.BoundsrecalculateBounds()Calculates the bounding box of available data and returns it.voidremoveChangeListener(GpxData.GpxDataChangeListener listener)Removes a listener that gets called whenever the data changed.voidremoveRoute(GpxRoute route)Remove a routevoidremoveTrack(IGpxTrack track)Remove a trackvoidremoveWaypoint(WayPoint waypoint)Remove a waypointvoidresetEastNorthCache()Resets the internal caches of east/north coordinates.voidsetModified(boolean value)Sets the modified flag to the value.voidsplitTrackSegmentsToTracks(java.lang.String srcLayerName)Split tracks so that only single-segment tracks remain.voidsplitTracksToLayers(java.lang.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 java.io.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
-
creator
public java.lang.String creator
Creator metadata for this file (usually software)
-
privateTracks
private final java.util.ArrayList<IGpxTrack> privateTracks
A list of tracks this file consists of
-
privateRoutes
private final java.util.ArrayList<GpxRoute> privateRoutes
GPX routes in this file
-
privateWaypoints
private final java.util.ArrayList<WayPoint> privateWaypoints
Additional waypoints for this file.
-
namespaces
private final java.util.List<GpxData.XMLNamespace> namespaces
All namespaces read from the original file
-
layerPrefs
private final java.util.Map<java.lang.String,java.lang.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 java.util.Collection<IGpxTrack> tracks
Tracks. Access is discouraged, usegetTracks()to read.- See Also:
getTracks()
-
routes
public final java.util.Collection<GpxRoute> routes
Routes. Access is discouraged, usegetTracks()to read.- See Also:
getRoutes()
-
waypoints
public final java.util.Collection<WayPoint> waypoints
Waypoints. Access is discouraged, usegetTracks()to read.- See Also:
getWaypoints()
-
dataSources
public final 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.- Since:
- 7575
-
listeners
private final ListenerList<GpxData.GpxDataChangeListener> listeners
-
segSpans
private java.util.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, java.util.Map<java.lang.String,java.lang.Object> attr)
-
getSegmentSpans
public java.util.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 java.util.Collection<IGpxTrack> getTracks()
Get all tracks contained in this data set, without any guaranteed order.- Returns:
- The tracks.
-
getOrderedTracks
public java.util.List<IGpxTrack> getOrderedTracks()
Get all tracks contained in this data set, ordered chronologically.- Returns:
- The tracks in chronological order.
- Since:
- 18207
-
getTrackFirstWaypointMin
private static java.util.OptionalLong getTrackFirstWaypointMin(IGpxTrack track)
-
getTrackSegmentsStream
public java.util.stream.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 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- Parameters:
attrs- attributes of/for an gpx track, written to if the name appeared previously incounts.counts- aHashMapof 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(java.lang.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(java.lang.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 java.util.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 java.util.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:
trueif this GPX data has track points,falseotherwise
-
getTrackPoints
public java.util.stream.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:
trueif this GPX data has route points,falseotherwise
-
isEmpty
public boolean isEmpty()
Determines if this GPX data is empty (i.e. does not contain any point)- Returns:
trueif this GPX data is empty,falseotherwise
-
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,nullis 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 java.util.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 java.util.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 java.lang.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 java.util.Collection<DataSource> getDataSources()
Description copied from interface:DataReturns the collection of data sources.- Specified by:
getDataSourcesin interfaceData- Returns:
- the collection of data sources.
-
getLayerPrefs
public java.util.Map<java.lang.String,java.lang.String> getLayerPrefs()
Description copied from interface:IGpxLayerPrefsThe layer specific prefs formerly saved in the preferences, e.g. drawing options. NOT the track specific settings (e.g. color, width)- Specified by:
getLayerPrefsin interfaceIGpxLayerPrefs- Returns:
- Modifiable map
-
getNamespaces
public java.util.List<GpxData.XMLNamespace> getNamespaces()
All XML namespaces read from the original file- Returns:
- Modifiable list
- Since:
- 15496
-
hashCode
public int hashCode()
- Overrides:
hashCodein classWithAttributes
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classWithAttributes
-
put
public void put(java.lang.String key, java.lang.Object value)
Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present).- Specified by:
putin interfaceIWithAttributes- Overrides:
putin classWithAttributes- Parameters:
key- the keyvalue- the value
-
put
public void put(java.lang.String key, java.lang.Object value, boolean setModified)
Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present). Only sets the modified state when setModified is true.- Parameters:
key- the keyvalue- the valuesetModified- whether to change the modified state- Since:
- 18399
-
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:
setModifiedin interfaceIGpxLayerPrefs- Parameters:
value- modified flag- Since:
- 15496
-
clear
public void clear()
Removes all gpx elements- Since:
- 17439
-
-