Ignore:
Timestamp:
2010-01-30T20:04:10+01:00 (10 years ago)
Author:
jttt
Message:

Gpx refactoring - GpxTrack and GpxTrackSegment is now interface, implementations for specific use can be provided (currently JOSM supports immutable gpx track, livegps plugin supports append only track).

  • track length and bounds are precalculated
  • GpxLayer paints only currently visible segments
Location:
trunk/src/org/openstreetmap/josm/data/gpx
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r2795 r2907  
    6363    public boolean hasTrackPoints() {
    6464        for (GpxTrack trk : tracks) {
    65             for (Collection<WayPoint> trkseg : trk.trackSegs) {
    66                 if (!trkseg.isEmpty())
     65            for (GpxTrackSegment trkseg : trk.getSegments()) {
     66                if (!trkseg.getWayPoints().isEmpty())
    6767                    return true;
    6868            }
     
    103103        }
    104104        for (GpxTrack trk : tracks) {
    105             for (Collection<WayPoint> trkseg : trk.trackSegs) {
    106                 for (WayPoint wpt : trkseg) {
    107                     if (bounds == null) {
    108                         bounds = new Bounds(wpt.getCoor());
    109                     } else {
    110                         bounds.extend(wpt.getCoor());
    111                     }
     105            Bounds trkBounds = trk.getBounds();
     106            if (trkBounds != null) {
     107                if (bounds == null) {
     108                    bounds = new Bounds(trkBounds);
     109                } else {
     110                    bounds.extend(trkBounds);
    112111                }
    113112            }
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxTrack.java

    r2247 r2907  
    55
    66import java.util.Collection;
    7 import java.util.concurrent.ConcurrentLinkedQueue;
     7import java.util.Map;
    88
    9 public class GpxTrack extends WithAttributes {
    10     public final Collection<Collection<WayPoint>> trackSegs
    11     = new ConcurrentLinkedQueue<Collection<WayPoint>>();
     9import org.openstreetmap.josm.data.Bounds;
    1210
    13     /**
    14      * calculates the length of the track
    15      */
    16     public double length(){
    17         double result = 0.0; // in meters
    18         WayPoint last = null;
    1911
    20         for (Collection<WayPoint> trkseg : trackSegs) {
    21             for (WayPoint tpt : trkseg) {
    22                 if(last != null){
    23                     Double d = last.getCoor().greatCircleDistance(tpt.getCoor());
    24                     if(!d.isNaN() && !d.isInfinite()) {
    25                         result += d;
    26                     }
    27                 }
    28                 last = tpt;
    29             }
    30             last = null; // restart for each track segment
    31         }
    32         return result;
    33     }
     12/**
     13 * Read-only gpx track. Implementations doesn't have to be immutable, but should always be thread safe.
     14 *
     15 */
     16
     17public interface GpxTrack {
     18
     19    Collection<GpxTrackSegment> getSegments();
     20    Map<String, Object> getAttributes();
     21    Bounds getBounds();
     22    double length();
     23
    3424}
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r2874 r2907  
    1010import org.openstreetmap.josm.data.coor.EastNorth;
    1111import org.openstreetmap.josm.data.coor.LatLon;
    12 import org.openstreetmap.josm.tools.DateUtils;
    1312import org.openstreetmap.josm.tools.PrimaryDateParser;
    1413
     
    2019    public int dir;
    2120
    22     private CachedLatLon coor;
     21    private final CachedLatLon coor;
    2322
    2423    public final LatLon getCoor() {
Note: See TracChangeset for help on using the changeset viewer.