Changeset 7319 in josm for trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
- Timestamp:
- 2014-07-20T20:43:53+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r7020 r7319 4 4 import java.io.File; 5 5 import java.util.Collection; 6 import java.util.Date; 6 7 import java.util.Iterator; 7 8 import java.util.LinkedList; … … 82 83 * 83 84 * FIXME might perhaps use visitor pattern? 85 * @return the bounds 84 86 */ 85 87 public Bounds recalculateBounds() { … … 116 118 /** 117 119 * calculates the sum of the lengths of all track segments 120 * @return the length in meters 118 121 */ 119 122 public double length(){ … … 125 128 126 129 return result; 130 } 131 132 /** 133 * returns minimum and maximum timestamps in the track 134 * @param trk track to analyze 135 * @return minimum and maximum dates in array of 2 elements 136 */ 137 public static Date[] getMinMaxTimeForTrack(GpxTrack trk) { 138 WayPoint earliest = null, latest = null; 139 140 for (GpxTrackSegment seg : trk.getSegments()) { 141 for (WayPoint pnt : seg.getWayPoints()) { 142 if (latest == null) { 143 latest = earliest = pnt; 144 } else { 145 if (pnt.compareTo(earliest) < 0) { 146 earliest = pnt; 147 } else { 148 latest = pnt; 149 } 150 } 151 } 152 } 153 if (earliest==null || latest==null) return null; 154 return new Date[]{earliest.getTime(), latest.getTime()}; 155 } 156 157 /** 158 * Returns minimum and maximum timestamps for all tracks 159 * Warning: there are lot of track with broken timestamps, 160 * so we just ingore points from future and from year before 1970 in this method 161 * works correctly @since 5815 162 * @return minimum and maximum dates in array of 2 elements 163 */ 164 public Date[] getMinMaxTimeForAllTracks() { 165 double min=1e100, max=-1e100, t; 166 double now = System.currentTimeMillis()/1000.0; 167 for (GpxTrack trk: tracks) { 168 for (GpxTrackSegment seg : trk.getSegments()) { 169 for (WayPoint pnt : seg.getWayPoints()) { 170 t = pnt.time; 171 if (t>0 && t<=now) { 172 if (t>max) max=t; 173 if (t<min) min=t; 174 } 175 } 176 } 177 } 178 if (min==1e100 || max==-1e100) return null; 179 return new Date[]{new Date((long) (min * 1000)), new Date((long) (max * 1000)), }; 127 180 } 128 181 … … 258 311 } 259 312 313 public void resetEastNorthCache() { 314 if (waypoints != null) { 315 for (WayPoint wp : waypoints){ 316 wp.invalidateEastNorthCache(); 317 } 318 } 319 if (tracks != null){ 320 for (GpxTrack track: tracks) { 321 for (GpxTrackSegment segment: track.getSegments()) { 322 for (WayPoint wp: segment.getWayPoints()) { 323 wp.invalidateEastNorthCache(); 324 } 325 } 326 } 327 } 328 if (routes != null) { 329 for (GpxRoute route: routes) { 330 if (route.routePoints == null) { 331 continue; 332 } 333 for (WayPoint wp: route.routePoints) { 334 wp.invalidateEastNorthCache(); 335 } 336 } 337 } 338 } 339 260 340 /** 261 341 * Iterates over all track segments and then over all routes. … … 266 346 private int idxTracks; 267 347 private Iterator<GpxTrackSegment> itTrackSegments; 268 private Iterator<GpxRoute> itRoutes;348 private final Iterator<GpxRoute> itRoutes; 269 349 270 350 private Collection<WayPoint> next; 271 private boolean[] trackVisibility;351 private final boolean[] trackVisibility; 272 352 273 353 public LinesIterator(GpxData data, boolean[] trackVisibility) {
Note:
See TracChangeset
for help on using the changeset viewer.