source: josm/trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java@ 627

Last change on this file since 627 was 627, checked in by framm, 16 years ago
  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1//License: GPLv2 or later. Copyright 2007 by Raphael Mack and others
2
3package org.openstreetmap.josm.data.gpx;
4
5import java.io.File;
6import java.util.Collection;
7import java.util.LinkedList;
8import java.util.Map;
9
10import org.openstreetmap.josm.data.Bounds;
11
12/**
13 * objects of this class represent a gpx file with tracks, waypoints and routes
14 * it uses GPX1.1 see http://www.topografix.com/GPX/1/1/ for details
15 *
16 * @author Raphael Mack <ramack@raphael-mack.de>
17 */
18public class GpxData extends WithAttributes {
19 public File storageFile;
20 public boolean fromServer;
21
22 public Collection<GpxTrack> tracks = new LinkedList<GpxTrack>();
23 public Collection<GpxRoute> routes = new LinkedList<GpxRoute>();
24 public Collection<WayPoint> waypoints = new LinkedList<WayPoint>();
25
26 public Bounds bounds;
27
28 public void mergeFrom(GpxData other) {
29 if (storageFile == null && other.storageFile != null) {
30 storageFile = other.storageFile;
31 }
32 fromServer = fromServer && other.fromServer;
33
34 for (Map.Entry<String, Object> ent : other.attr.entrySet()) {
35 // TODO: Detect conflicts.
36 String k = ent.getKey();
37 if (k.equals("link") && attr.containsKey("link")) {
38 ((Collection<GpxLink>) attr.get("link")).addAll(
39 (Collection<GpxLink>) ent.getValue());
40 } else {
41 attr.put(k, ent.getValue());
42 }
43 }
44 tracks.addAll(other.tracks);
45 routes.addAll(other.routes);
46 waypoints.addAll(other.waypoints);
47 }
48
49 public boolean hasTrackPoints() {
50 for (GpxTrack trk : tracks) {
51 for (Collection<WayPoint> trkseg : trk.trackSegs) {
52 if (!trkseg.isEmpty())
53 return true;
54 }
55 }
56 return false;
57 }
58
59 public boolean hasRoutePoints() {
60 for (GpxRoute rte : routes) {
61 if (!rte.routePoints.isEmpty())
62 return true;
63 }
64 return false;
65 }
66
67 // FIXME might perhaps use visitor pattern?
68 public void recalculateBounds() {
69 bounds = null;
70 for (WayPoint wpt : waypoints) {
71 if (bounds == null) {
72 bounds = new Bounds(wpt.latlon, wpt.latlon);
73 } else {
74 bounds.extend(wpt.latlon);
75 }
76 }
77 for (GpxRoute rte : routes) {
78 for (WayPoint wpt : rte.routePoints) {
79 if (bounds == null) {
80 bounds = new Bounds(wpt.latlon, wpt.latlon);
81 } else {
82 bounds.extend(wpt.latlon);
83 }
84 }
85 }
86 for (GpxTrack trk : tracks) {
87 for (Collection<WayPoint> trkseg : trk.trackSegs) {
88 for (WayPoint wpt : trkseg) {
89 if (bounds == null) {
90 bounds = new Bounds(wpt.latlon, wpt.latlon);
91 } else {
92 bounds.extend(wpt.latlon);
93 }
94 }
95 }
96 }
97 if (bounds == null) {
98 bounds = new Bounds();
99 }
100 }
101}
Note: See TracBrowser for help on using the repository browser.