- Timestamp:
- 2008-06-10T00:16:09+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r627 r647 9 9 10 10 import org.openstreetmap.josm.data.Bounds; 11 import org.openstreetmap.josm.data.coor.LatLon; 11 12 12 13 /** … … 99 100 } 100 101 } 102 103 /** 104 * calculates the sum of the lengths of all track segments 105 */ 106 public double length(){ 107 double result = 0.0; // in meters 108 WayPoint last = null; 109 110 for (GpxTrack trk : tracks) { 111 for (Collection<WayPoint> trkseg : trk.trackSegs) { 112 for (WayPoint tpt : trkseg) { 113 if(last != null){ 114 result += calcDistance(last.latlon, tpt.latlon); 115 } 116 last = tpt; 117 } 118 last = null; // restart for each track segment 119 } 120 } 121 return result; 122 } 123 124 /** 125 * returns the distance in meters between two LatLons 126 */ 127 public static double calcDistance(LatLon p1, LatLon p2){ 128 double lat1, lon1, lat2, lon2; 129 double dlon, dlat; 130 131 lat1 = p1.lat() * Math.PI / 180.0; 132 lon1 = p1.lon() * Math.PI / 180.0; 133 lat2 = p2.lat() * Math.PI / 180.0; 134 lon2 = p2.lon() * Math.PI / 180.0; 135 136 dlon = lon2 - lon1; 137 dlat = lat2 - lat1; 138 139 double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2)); 140 double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 141 return 6367000 * c; 142 } 143 101 144 } -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r646 r647 13 13 import org.openstreetmap.josm.data.coor.LatLon; 14 14 15 public class WayPoint extends WithAttributes {15 public class WayPoint extends WithAttributes implements Comparable{ 16 16 17 17 public final LatLon latlon; … … 50 50 } 51 51 52 public int compareTo(Object other){ 53 if(other instanceof WayPoint){ 54 WayPoint w = (WayPoint)other; 55 return (int)time - (int)w.time; 56 } 57 return 0; 58 } 52 59 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r646 r647 26 26 import java.util.Comparator; 27 27 import java.util.LinkedList; 28 import java.util.Date; 29 import java.text.DateFormat; 30 import java.text.DecimalFormat; 28 31 29 32 import javax.swing.AbstractAction; … … 279 282 .append("<br>"); 280 283 284 if(data.tracks.size() > 0){ 285 boolean first = true; 286 WayPoint earliest = null, latest = null; 287 288 for(GpxTrack trk: data.tracks){ 289 for(Collection<WayPoint> seg:trk.trackSegs){ 290 for(WayPoint pnt:seg){ 291 if(first){ 292 latest = earliest = pnt; 293 first = false; 294 }else{ 295 if(pnt.compareTo(earliest) < 0){ 296 earliest = pnt; 297 }else{ 298 latest = pnt; 299 } 300 } 301 } 302 } 303 } 304 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); 305 info.append(tr("Timespan: ") + df.format(new Date((long)(earliest.time * 1000))) + " - " + df.format(new Date((long)(latest.time * 1000)))); 306 int diff = (int)(latest.time - earliest.time); 307 info.append(" (" + (diff / 3600) + ":" + ((diff % 3600)/60) + ")"); 308 info.append("<br>"); 309 } 310 info.append(tr("Length: ") + new DecimalFormat("#0.00").format(data.length() / 1000) + "km"); 311 info.append("<br>"); 312 281 313 return info.append("</html>").toString(); 282 314 }
Note:
See TracChangeset
for help on using the changeset viewer.