Changeset 1169 in josm for trunk/src/org/openstreetmap/josm/data/gpx
- Timestamp:
- 2008-12-23T15:07:05+01:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/gpx
- Files:
-
- 6 edited
-
GpxData.java (modified) (3 diffs)
-
GpxLink.java (modified) (1 diff)
-
GpxRoute.java (modified) (1 diff)
-
GpxTrack.java (modified) (1 diff)
-
WayPoint.java (modified) (1 diff)
-
WithAttributes.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r655 r1169 15 15 * It uses GPX v1.1, see {@link <a href="http://www.topografix.com/GPX/1/1/">the spec</a>} 16 16 * for details. 17 * 17 * 18 18 * @author Raphael Mack <ramack@raphael-mack.de> 19 19 */ 20 20 public class GpxData extends WithAttributes { 21 public File storageFile;22 public boolean fromServer;21 public File storageFile; 22 public boolean fromServer; 23 23 24 public Collection<GpxTrack> tracks = new LinkedList<GpxTrack>();25 public Collection<GpxRoute> routes = new LinkedList<GpxRoute>();26 public Collection<WayPoint> waypoints = new LinkedList<WayPoint>();24 public Collection<GpxTrack> tracks = new LinkedList<GpxTrack>(); 25 public Collection<GpxRoute> routes = new LinkedList<GpxRoute>(); 26 public Collection<WayPoint> waypoints = new LinkedList<WayPoint>(); 27 27 28 public Bounds bounds;28 public Bounds bounds; 29 29 30 public void mergeFrom(GpxData other) {31 if (storageFile == null && other.storageFile != null) {32 storageFile = other.storageFile;33 }34 fromServer = fromServer && other.fromServer;30 public void mergeFrom(GpxData other) { 31 if (storageFile == null && other.storageFile != null) { 32 storageFile = other.storageFile; 33 } 34 fromServer = fromServer && other.fromServer; 35 35 36 for (Map.Entry<String, Object> ent : other.attr.entrySet()) {37 // TODO: Detect conflicts.38 String k = ent.getKey();39 if (k.equals("link") && attr.containsKey("link")) {40 ((Collection<GpxLink>) attr.get("link")).addAll(41 (Collection<GpxLink>) ent.getValue());42 } else {43 attr.put(k, ent.getValue());44 }45 }46 tracks.addAll(other.tracks);47 routes.addAll(other.routes);48 waypoints.addAll(other.waypoints);49 }36 for (Map.Entry<String, Object> ent : other.attr.entrySet()) { 37 // TODO: Detect conflicts. 38 String k = ent.getKey(); 39 if (k.equals("link") && attr.containsKey("link")) { 40 ((Collection<GpxLink>) attr.get("link")).addAll( 41 (Collection<GpxLink>) ent.getValue()); 42 } else { 43 attr.put(k, ent.getValue()); 44 } 45 } 46 tracks.addAll(other.tracks); 47 routes.addAll(other.routes); 48 waypoints.addAll(other.waypoints); 49 } 50 50 51 public boolean hasTrackPoints() {52 for (GpxTrack trk : tracks) {53 for (Collection<WayPoint> trkseg : trk.trackSegs) {54 if (!trkseg.isEmpty())55 return true;56 }57 }58 return false;59 }51 public boolean hasTrackPoints() { 52 for (GpxTrack trk : tracks) { 53 for (Collection<WayPoint> trkseg : trk.trackSegs) { 54 if (!trkseg.isEmpty()) 55 return true; 56 } 57 } 58 return false; 59 } 60 60 61 public boolean hasRoutePoints() {62 for (GpxRoute rte : routes) {63 if (!rte.routePoints.isEmpty())64 return true;65 }66 return false;67 }61 public boolean hasRoutePoints() { 62 for (GpxRoute rte : routes) { 63 if (!rte.routePoints.isEmpty()) 64 return true; 65 } 66 return false; 67 } 68 68 69 // FIXME might perhaps use visitor pattern?70 public void recalculateBounds() {71 bounds = null;72 for (WayPoint wpt : waypoints) {73 if (bounds == null) {74 bounds = new Bounds(wpt.latlon, wpt.latlon);75 } else {76 bounds.extend(wpt.latlon);77 }78 }79 for (GpxRoute rte : routes) {80 for (WayPoint wpt : rte.routePoints) {81 if (bounds == null) {82 bounds = new Bounds(wpt.latlon, wpt.latlon);83 } else {84 bounds.extend(wpt.latlon);85 }86 }87 }88 for (GpxTrack trk : tracks) {89 for (Collection<WayPoint> trkseg : trk.trackSegs) {90 for (WayPoint wpt : trkseg) {91 if (bounds == null) {92 bounds = new Bounds(wpt.latlon, wpt.latlon);93 } else {94 bounds.extend(wpt.latlon);95 }96 }97 }98 }99 if (bounds == null) {100 bounds = new Bounds();101 }102 }103 69 // FIXME might perhaps use visitor pattern? 70 public void recalculateBounds() { 71 bounds = null; 72 for (WayPoint wpt : waypoints) { 73 if (bounds == null) { 74 bounds = new Bounds(wpt.latlon, wpt.latlon); 75 } else { 76 bounds.extend(wpt.latlon); 77 } 78 } 79 for (GpxRoute rte : routes) { 80 for (WayPoint wpt : rte.routePoints) { 81 if (bounds == null) { 82 bounds = new Bounds(wpt.latlon, wpt.latlon); 83 } else { 84 bounds.extend(wpt.latlon); 85 } 86 } 87 } 88 for (GpxTrack trk : tracks) { 89 for (Collection<WayPoint> trkseg : trk.trackSegs) { 90 for (WayPoint wpt : trkseg) { 91 if (bounds == null) { 92 bounds = new Bounds(wpt.latlon, wpt.latlon); 93 } else { 94 bounds.extend(wpt.latlon); 95 } 96 } 97 } 98 } 99 if (bounds == null) { 100 bounds = new Bounds(); 101 } 102 } 103 104 104 /** 105 105 * calculates the sum of the lengths of all track segments … … 108 108 double result = 0.0; // in meters 109 109 WayPoint last = null; 110 110 111 111 for (GpxTrack trk : tracks) { 112 112 for (Collection<WayPoint> trkseg : trk.trackSegs) { … … 129 129 double lat1, lon1, lat2, lon2; 130 130 double dlon, dlat; 131 131 132 132 lat1 = p1.lat() * Math.PI / 180.0; 133 133 lon1 = p1.lon() * Math.PI / 180.0; -
trunk/src/org/openstreetmap/josm/data/gpx/GpxLink.java
r627 r1169 5 5 6 6 public class GpxLink { 7 public String uri;8 public String text;9 public String type;7 public String uri; 8 public String text; 9 public String type; 10 10 11 public GpxLink(String uri) {12 this.uri = uri;13 }11 public GpxLink(String uri) { 12 this.uri = uri; 13 } 14 14 } -
trunk/src/org/openstreetmap/josm/data/gpx/GpxRoute.java
r627 r1169 8 8 9 9 public class GpxRoute extends WithAttributes { 10 public Collection<WayPoint> routePoints = new LinkedList<WayPoint>();10 public Collection<WayPoint> routePoints = new LinkedList<WayPoint>(); 11 11 } -
trunk/src/org/openstreetmap/josm/data/gpx/GpxTrack.java
r627 r1169 8 8 9 9 public class GpxTrack extends WithAttributes { 10 public Collection<Collection<WayPoint>> trackSegs11 = new LinkedList<Collection<WayPoint>>();10 public Collection<Collection<WayPoint>> trackSegs 11 = new LinkedList<Collection<WayPoint>>(); 12 12 } -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r1167 r1169 15 15 public class WayPoint extends WithAttributes implements Comparable<WayPoint> 16 16 { 17 public final LatLon latlon;18 public final EastNorth eastNorth;19 public double time;20 public Color speedLineColor;21 public boolean drawLine;22 public int dir;17 public final LatLon latlon; 18 public final EastNorth eastNorth; 19 public double time; 20 public Color speedLineColor; 21 public boolean drawLine; 22 public int dir; 23 23 24 public WayPoint(LatLon ll) {25 latlon = ll;26 eastNorth = Main.proj.latlon2eastNorth(ll);27 }24 public WayPoint(LatLon ll) { 25 latlon = ll; 26 eastNorth = Main.proj.latlon2eastNorth(ll); 27 } 28 28 29 @Override 30 public String toString() { 31 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + latlon.toString() + ", " + attr + ")"; 32 } 33 34 /** 35 * Convert the time stamp of the waypoint into seconds from the epoch 36 */ 37 public final static SimpleDateFormat GPXTIMEFMT = 38 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); // ignore timezone 39 40 public void setTime() { 41 if (! attr.containsKey("time")) { 42 return; 43 } 44 Date d = GPXTIMEFMT.parse(attr.get("time").toString(), new ParsePosition(0)); 45 if (d != null /* parsing ok */) { 46 time = d.getTime() / 1000.0; /* ms => seconds */ 47 } 48 } 29 @Override 30 public String toString() { 31 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + latlon.toString() + ", " + attr + ")"; 32 } 49 33 50 /** 51 * Convert a time stamp of the waypoint from the <cmt> or <desc> field 52 * into seconds from the epoch. Handles the date format as it is used by 53 * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0). 54 * A value of <time> fields overwrites values set with by method. 55 * Does nothing if specified key does not exist or text cannot be parsed. 56 * 57 * @param key The key that contains the text to convert. 58 */ 59 public void setGarminCommentTime(String key) { 60 // do not overwrite time if already set 61 if (time != 0.0) { 62 return; 63 } 64 if (! attr.containsKey(key)) { 65 return; 66 } 67 // example date format "18-AUG-08 13:33:03" 68 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone 69 Date d = f.parse(attr.get(key).toString(), new ParsePosition(0)); 70 if (d != null /* parsing OK */) { 71 time = d.getTime() / 1000.0; /* ms => seconds */ 72 } 73 } 34 /** 35 * Convert the time stamp of the waypoint into seconds from the epoch 36 */ 37 public final static SimpleDateFormat GPXTIMEFMT = 38 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); // ignore timezone 74 39 75 public int compareTo(WayPoint w) 76 { 77 return Double.compare(time, w.time); 78 } 40 public void setTime() { 41 if (! attr.containsKey("time")) { 42 return; 43 } 44 Date d = GPXTIMEFMT.parse(attr.get("time").toString(), new ParsePosition(0)); 45 if (d != null /* parsing ok */) { 46 time = d.getTime() / 1000.0; /* ms => seconds */ 47 } 48 } 49 50 /** 51 * Convert a time stamp of the waypoint from the <cmt> or <desc> field 52 * into seconds from the epoch. Handles the date format as it is used by 53 * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0). 54 * A value of <time> fields overwrites values set with by method. 55 * Does nothing if specified key does not exist or text cannot be parsed. 56 * 57 * @param key The key that contains the text to convert. 58 */ 59 public void setGarminCommentTime(String key) { 60 // do not overwrite time if already set 61 if (time != 0.0) { 62 return; 63 } 64 if (! attr.containsKey(key)) { 65 return; 66 } 67 // example date format "18-AUG-08 13:33:03" 68 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone 69 Date d = f.parse(attr.get(key).toString(), new ParsePosition(0)); 70 if (d != null /* parsing OK */) { 71 time = d.getTime() / 1000.0; /* ms => seconds */ 72 } 73 } 74 75 public int compareTo(WayPoint w) 76 { 77 return Double.compare(time, w.time); 78 } 79 79 } -
trunk/src/org/openstreetmap/josm/data/gpx/WithAttributes.java
r627 r1169 1 // License: GPL. 1 // License: GPL. 2 2 package org.openstreetmap.josm.data.gpx; 3 3 … … 9 9 * The "attr" hash is used to store the XML payload 10 10 * (not only XML attributes!) 11 * 11 * 12 12 * @author Frederik Ramm <frederik@remote.org> 13 13 * 14 14 */ 15 15 public class WithAttributes { 16 17 public Map<String, Object> attr = new HashMap<String, Object>(0);18 19 public String getString(String key) {20 Object value = attr.get(key);21 return (value instanceof String) ? (String)value : null;22 }16 17 public Map<String, Object> attr = new HashMap<String, Object>(0); 18 19 public String getString(String key) { 20 Object value = attr.get(key); 21 return (value instanceof String) ? (String)value : null; 22 } 23 23 }
Note:
See TracChangeset
for help on using the changeset viewer.
