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
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 ClassesModifier and TypeClassDescriptionstatic classA data change event in any of the gpx data.static interfaceA listener that listens to GPX data changes.(package private) static classstatic classIterates over all track segments and then over all routes.static classA class containing prefix, URI and location of a namespaceNested classes/interfaces inherited from interface org.openstreetmap.josm.data.gpx.GpxConstants
GpxConstants.ColorFormat -
Field Summary
FieldsModifier and TypeFieldDescriptionCreator metadata for this file (usually software)final Set<DataSource>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.booleanA boolean flag indicating if the data was read from the OSM server.booleanA boolean flag indicating if the data was read from a session file.private booleanThe layer specific prefs formerly saved in the preferences, e.g.private final ListenerList<GpxData.GpxDataChangeListener>private booleanprivate final List<GpxData.XMLNamespace>All namespaces read from the original fileGPX routes in this fileA list of tracks this file consists ofAdditional waypoints for this file.private final IGpxTrack.GpxTrackChangeListenerfinal Collection<GpxRoute>Routes.private List<GpxData.GpxTrackSegmentSpan>The disk file this layer is stored in, if it is a local layer.private booleanfinal Collection<IGpxTrack>Tracks.private booleanfinal Collection<WayPoint>Waypoints.Fields inherited from class org.openstreetmap.josm.data.gpx.WithAttributes
attrFields 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
ConstructorsConstructorDescriptionGpxData()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
Modifier and TypeMethodDescriptionvoidAdds a listener that gets called whenever the data changed.voidAdd a new routevoidAdd a new trackvoidaddWaypoint(WayPoint waypoint) Add a new waypointvoidAdds a listener that gets called whenever the data changed.private booleanvoidBegins updating this GpxData and prevents listeners from being fired.voidclear()Removes all gpx elementsprivate voidClear all tracks, empties the current privateTracks container, helper method for some gpx manipulations.voidCombine tracks into a single, segmented track.private voidconnectTracks(WayPoint prevWp, GpxData.GpxTrackSegmentSpan span, Map<String, Object> attr) private voidcutOverlapping(IGpxTrack trk, boolean connect) voidFinishes updating this GpxData and fires listeners if required.static StringEnsures a unique name among gpx layersbooleanprivate voidfireInvalidate(boolean setModified) Returns the collection of data sources.The layer specific prefs formerly saved in the preferences, e.g.getLinesIterable(boolean... trackVisibility) Iterate over all track segments and over all routes.Returns the bounds defining the extend of this data, as read in metadata, if any.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 methodreturns minimum and maximum timestamps in the trackAll XML namespaces read from the original fileGet all tracks contained in this data set, ordered chronologically.Gets the list of all routes defined in this data set.Get a list of SegmentSpans containing the beginning and end of each segmentintReplies the current number of tracks in this GpxDataprivate static OptionalLongGets a stream of all track points in the segments of the tracks of this data.Get all tracks contained in this data set, without any guaranteed order.Get stream of track segments.intReplies the accumulated total of all track segments, the sum of segment counts for each track present.Gets a list of all way points in this data set.inthashCode()booleanDetermines if this GPX data has one or more route pointsbooleanDetermines if this GPX data has one or more track pointsvoidFires event listeners and sets the modified flag to true.booleanisEmpty()Determines if this GPX data is empty (i.e.booleanDetermines whether anything has been modified.doublelength()calculates the sum of the lengths of all track segmentsvoidMerges data from another object.voidMerges data from another object.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 trackvoidPut a key / value pair as a new attribute.voidPut a key / value pair as a new attribute.Calculates the bounding box of available data and returns it.voidRemoves a listener that gets called whenever the data changed.voidremoveRoute(GpxRoute route) Remove a routevoidremoveTrack(IGpxTrack track) Remove a trackvoidremoveWaypoint(WayPoint waypoint) Remove a waypointvoidResets the internal caches of east/north coordinates.voidsetModified(boolean value) Sets the modified flag to the value.voidsplitTrackSegmentsToTracks(String srcLayerName) Split tracks so that only single-segment tracks remain.voidsplitTracksToLayers(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, hasExtensionsMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openstreetmap.josm.data.Data
getDataSourceArea, getDataSourceBounds
-
Field Details
-
storageFile
The disk file this layer is stored in, if it is a local layer. May benull. -
fromServer
A boolean flag indicating if the data was read from the OSM server. -
fromSession
A boolean flag indicating if the data was read from a session file.- Since:
- 18287
-
creator
Creator metadata for this file (usually software) -
privateTracks
A list of tracks this file consists of -
privateRoutes
GPX routes in this file -
privateWaypoints
Additional waypoints for this file. -
namespaces
All namespaces read from the original file -
layerPrefs
The layer specific prefs formerly saved in the preferences, e.g. drawing options. NOT the track specific settings (e.g. color, width) -
proxy
-
modified
-
updating
-
initializing
-
suppressedInvalidate
-
tracks
Tracks. Access is discouraged, usegetTracks()to read.- See Also:
-
routes
Routes. Access is discouraged, usegetTracks()to read.- See Also:
-
waypoints
Waypoints. Access is discouraged, usegetTracks()to read.- See Also:
-
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
-
segSpans
-
-
Constructor Details
-
GpxData
public GpxData()Constructs a new GpxData. -
GpxData
Constructs a new GpxData that is currently being initialized, so no listeners will be fired untilendUpdate()is called.- Parameters:
initializing- true- Since:
- 15496
-
-
Method Details
-
mergeFrom
Merges data from another object.- Parameters:
other- existing GPX data
-
mergeFrom
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
-
connectTracks
private void connectTracks(WayPoint prevWp, GpxData.GpxTrackSegmentSpan span, Map<String, Object> attr) -
getSegmentSpans
Get a list of SegmentSpans containing the beginning and end of each segment- Returns:
- the list of SegmentSpans
- Since:
- 14338
-
anySegmentOverlapsWith
-
getTracks
Get all tracks contained in this data set, without any guaranteed order.- Returns:
- The tracks.
-
getOrderedTracks
Get all tracks contained in this data set, ordered chronologically.- Returns:
- The tracks in chronological order.
- Since:
- 18207
-
getTrackFirstWaypointMin
-
getTrackSegmentsStream
Get stream of track segments.- Returns:
Stream<GPXTrack>
-
clearTracks
Clear all tracks, empties the current privateTracks container, helper method for some gpx manipulations. -
addTrack
Add a new track- Parameters:
track- The new track- Since:
- 12156
-
removeTrack
Remove a track- Parameters:
track- The old track- Since:
- 12156
-
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- aHashMapof previously seen names, associated with their count.srcLayerName- Source layer name- Returns:
- the unique name for the gpx track.
- Since:
- 15397
-
splitTrackSegmentsToTracks
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
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
Replies the current number of tracks in this GpxData- Returns:
- track count
- Since:
- 13210
-
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
Gets the list of all routes defined in this data set.- Returns:
- The routes
- Since:
- 12156
-
addRoute
Add a new route- Parameters:
route- The new route- Since:
- 12156
-
removeRoute
Remove a route- Parameters:
route- The old route- Since:
- 12156
-
getWaypoints
Gets a list of all way points in this data set.- Returns:
- The way points.
- Since:
- 12156
-
addWaypoint
Add a new waypoint- Parameters:
waypoint- The new waypoint- Since:
- 12156
-
removeWaypoint
Remove a waypoint- Parameters:
waypoint- The old waypoint- Since:
- 12156
-
hasTrackPoints
Determines if this GPX data has one or more track points- Returns:
trueif this GPX data has track points,falseotherwise
-
getTrackPoints
Gets a stream of all track points in the segments of the tracks of this data.- Returns:
- The stream
- Since:
- 12156
- See Also:
-
hasRoutePoints
Determines if this GPX data has one or more route points- Returns:
trueif this GPX data has route points,falseotherwise
-
isEmpty
Determines if this GPX data is empty (i.e. does not contain any point)- Returns:
trueif this GPX data is empty,falseotherwise
-
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
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:
-
length
calculates the sum of the lengths of all track segments- Returns:
- the length in meters
-
getMinMaxTimeForTrack
returns minimum and maximum timestamps in the track- Parameters:
trk- track to analyze- Returns:
- minimum and maximum as 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
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
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
Resets the internal caches of east/north coordinates. -
getDataSources
Description copied from interface:DataReturns the collection of data sources.- Specified by:
getDataSourcesin interfaceData- Returns:
- the collection of data sources.
-
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
All XML namespaces read from the original file- Returns:
- Modifiable list
- Since:
- 15496
-
hashCode
- Overrides:
hashCodein classWithAttributes
-
equals
- Overrides:
equalsin classWithAttributes
-
put
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
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
Adds a listener that gets called whenever the data changed.- Parameters:
listener- The listener- Since:
- 12156
-
addWeakChangeListener
Adds a listener that gets called whenever the data changed. It is added with a weak link- Parameters:
listener- The listener
-
removeChangeListener
Removes a listener that gets called whenever the data changed.- Parameters:
listener- The listener- Since:
- 12156
-
invalidate
Fires event listeners and sets the modified flag to true. -
fireInvalidate
-
beginUpdate
Begins updating this GpxData and prevents listeners from being fired.- Since:
- 15496
-
endUpdate
Finishes updating this GpxData and fires listeners if required.- Since:
- 15496
-
isModified
Determines whether anything has been modified.- Returns:
- whether anything has been modified (e.g. colors)
- Since:
- 15496
-
setModified
Sets the modified flag to the value.- Specified by:
setModifiedin interfaceIGpxLayerPrefs- Parameters:
value- modified flag- Since:
- 15496
-
clear
Removes all gpx elements- Since:
- 17439
-