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.
  • Field Details

  • Constructor Details

    • 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 until endUpdate() is called.
      Parameters:
      initializing - true
      Since:
      15496
  • Method Details

    • 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 data
      cutOverlapping - whether overlapping parts of the given track should be removed
      connect - 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

      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

      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

      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 in counts.
      counts - a HashMap 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

      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

      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

      Gets a stream of all track points in the segments of the tracks of this data.
      Returns:
      The stream
      Since:
      12156
      See Also:
    • 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

      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, see recalculateBounds(). To get downloaded areas, see dataSources.
      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, see getMetaBounds().
      To get downloaded areas, see dataSources.
      FIXME might perhaps use visitor pattern?
      Returns:
      the bounds
      See Also:
    • length

      public double 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

      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 for
      tolerance - : 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

      Description copied from interface: Data
      Returns the collection of data sources.
      Specified by:
      getDataSources in interface Data
      Returns:
      the collection of data sources.
    • 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 interface IGpxLayerPrefs
      Returns:
      Modifiable map
    • getNamespaces

      All XML namespaces read from the original file
      Returns:
      Modifiable list
      Since:
      15496
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class WithAttributes
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class WithAttributes
    • put

      public void put(String key, Object value)
      Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present).
      Specified by:
      put in interface IWithAttributes
      Overrides:
      put in class WithAttributes
      Parameters:
      key - the key
      value - the value
    • put

      public void put(String key, 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 key
      value - the value
      setModified - 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

      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 interface IGpxLayerPrefs
      Parameters:
      value - modified flag
      Since:
      15496
    • clear

      public void clear()
      Removes all gpx elements
      Since:
      17439