Changeset 647 in josm for trunk/src/org/openstreetmap/josm/data/gpx
 Timestamp:
 20080610T00:16:09+02:00 (11 years ago)
 Location:
 trunk/src/org/openstreetmap/josm/data/gpx
 Files:

 2 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(1a)); 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 }
Note: See TracChangeset
for help on using the changeset viewer.