Changeset 28689 in osm for applications/editors/josm/plugins/editgpx/src/org/openstreetmap
- Timestamp:
- 2012-09-04T08:49:06+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/data
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/data/EditGpxData.java
r28204 r28689 3 3 import java.util.ArrayList; 4 4 import java.util.List; 5 import java.util.NoSuchElementException; 5 6 6 7 import org.openstreetmap.josm.data.gpx.GpxData; … … 44 45 GpxData result = new GpxData(); 45 46 47 double minTime = 0.0; 48 if (anonTime) { 49 try { 50 minTime = minNonDeletedTime(); 51 } catch (NoSuchElementException e) { 52 // minTime won't be used, so ignore the exception 53 } 54 } 55 46 56 for (EditGpxTrack track: tracks) { 47 57 if (!track.isDeleted()) { 48 GpxTrack newTrack = track.createGpxTrack(anonTime );58 GpxTrack newTrack = track.createGpxTrack(anonTime, minTime); 49 59 if (!newTrack.getSegments().isEmpty()) { 50 60 result.tracks.add(newTrack); … … 58 68 } 59 69 70 /** 71 * time of the oldest waypoint in the set of non-deleted waypoints 72 * in this data (in seconds since Epoch) 73 */ 74 public double minNonDeletedTime() { 75 boolean foundOne = false; 76 double minTime = 0.0; 77 78 for (EditGpxTrack track: tracks) { 79 if (!track.isDeleted()) { 80 try { 81 double t = track.minNonDeletedTime(); 82 if ((!foundOne) || (t < minTime)) { 83 minTime = t; 84 } 85 foundOne = true; 86 } catch (NoSuchElementException e) { 87 continue; 88 } 89 } 90 } 91 92 if (!foundOne) { 93 throw new NoSuchElementException(); 94 } 95 return minTime; 96 } 97 60 98 } -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/data/EditGpxTrack.java
r25486 r28689 1 1 package org.openstreetmap.josm.plugins.editgpx.data; 2 2 3 import java.text.DateFormat; 4 import java.text.SimpleDateFormat; 3 5 import java.util.ArrayList; 4 6 import java.util.Collection; 7 import java.util.Date; 5 8 import java.util.HashMap; 6 9 import java.util.List; 7 10 import java.util.Map; 11 import java.util.NoSuchElementException; 12 import java.util.TimeZone; 8 13 9 14 import org.openstreetmap.josm.data.gpx.GpxTrack; … … 32 37 } 33 38 34 public GpxTrack createGpxTrack(boolean anonTime ) {39 public GpxTrack createGpxTrack(boolean anonTime, double minTime) { 35 40 36 41 Collection<Collection<WayPoint>> wayPoints = new ArrayList<Collection<WayPoint>>(); 42 43 final DateFormat iso8601 = 44 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 45 final TimeZone utc = TimeZone.getTimeZone("UTC"); 46 iso8601.setTimeZone(utc); 37 47 38 48 for (EditGpxTrackSegment segment: segments) { … … 43 53 // convert to anonymous time 44 54 for (WayPoint w : points) { 45 w.attr.put("time", "1970-01-01T00:00:00.000Z"); 55 double t = w.time - minTime; 56 w.attr.put("time", iso8601.format( 57 new Date((long)(t * 1000)))); 46 58 w.setTime(); 59 assert w.time == t; 47 60 if (w.attr.containsKey("name")) { 48 61 w.attr.put("name", "anon"); //time information can also be in "name" field. so delete time information … … 70 83 return isDeleted; 71 84 } 85 86 /** 87 * time of the oldest waypoint in the set of non-deleted waypoints 88 * in this track (in seconds since Epoch) 89 */ 90 public double minNonDeletedTime() { 91 boolean foundOne = false; 92 double minTime = 0.0; 93 94 for (EditGpxTrackSegment segment: segments) { 95 if (!segment.isDeleted()) { 96 try { 97 double t = segment.minNonDeletedTime(); 98 if ((!foundOne) || (t < minTime)) { 99 minTime = t; 100 } 101 foundOne = true; 102 } catch (NoSuchElementException e) { 103 continue; 104 } 105 } 106 } 107 108 if (!foundOne) { 109 throw new NoSuchElementException(); 110 } 111 return minTime; 112 } 72 113 } -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/data/EditGpxTrackSegment.java
r23189 r28689 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collections; 4 5 import java.util.List; 5 6 … … 42 43 } 43 44 45 /** 46 * time of the oldest waypoint in the set of non-deleted waypoints 47 * in this segment (in seconds since Epoch) 48 */ 49 public double minNonDeletedTime() { 50 return Collections.min(getNonDeletedWaypoints()).time; 51 } 52 44 53 } -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/data/EditGpxWayPoint.java
r23189 r28689 7 7 import org.openstreetmap.josm.data.gpx.WayPoint; 8 8 9 public class EditGpxWayPoint {9 public class EditGpxWayPoint implements Comparable<EditGpxWayPoint> { 10 10 private final double time; 11 11 private final CachedLatLon coor; … … 34 34 } 35 35 36 /** 37 * returns this waypoint's time in seconds since Epoch 38 */ 39 public double getTime() { 40 return time; 41 } 42 36 43 public CachedLatLon getCoor() { 37 44 return coor; 38 45 } 46 47 public int compareTo(EditGpxWayPoint o) { 48 return Double.compare(getTime(), o.getTime()); 49 } 39 50 }
Note:
See TracChangeset
for help on using the changeset viewer.