Changeset 12778 in osm for applications/editors/josm/plugins/tcxplugin/src/org
- Timestamp:
- 2009-01-01T18:28:53+01:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tcxplugin/src/org/openstreetmap/josm/io/TcxReader.java
r10833 r12778 47 47 public class TcxReader { 48 48 49 private File tcxFile;49 private File tcxFile; 50 50 51 private GpxData gpxData;51 private GpxData gpxData; 52 52 53 /**54 * @param tcxFile55 */56 public TcxReader(File tcxFile) {57 super();58 this.tcxFile = tcxFile;59 parseFile();60 }53 /** 54 * @param tcxFile 55 */ 56 public TcxReader(File tcxFile) { 57 super(); 58 this.tcxFile = tcxFile; 59 parseFile(); 60 } 61 61 62 /**63 *64 */65 @SuppressWarnings("unchecked") private void parseFile() {66 try {67 JAXBContext jc = JAXBContext68 .newInstance(TrainingCenterDatabaseT.class);69 Unmarshaller unmarshaller = jc.createUnmarshaller();70 JAXBElement<TrainingCenterDatabaseT> element = (JAXBElement<TrainingCenterDatabaseT>)unmarshaller71 .unmarshal(tcxFile);62 /** 63 * 64 */ 65 @SuppressWarnings("unchecked") private void parseFile() { 66 try { 67 JAXBContext jc = JAXBContext 68 .newInstance(TrainingCenterDatabaseT.class); 69 Unmarshaller unmarshaller = jc.createUnmarshaller(); 70 JAXBElement<TrainingCenterDatabaseT> element = (JAXBElement<TrainingCenterDatabaseT>)unmarshaller 71 .unmarshal(tcxFile); 72 72 73 TrainingCenterDatabaseT tcd = element.getValue();73 TrainingCenterDatabaseT tcd = element.getValue(); 74 74 75 gpxData = new GpxData();75 gpxData = new GpxData(); 76 76 77 // Usually logged activities are in the activities tag.78 parseDataFromActivities(tcd);79 // GPS tracks in the course tag are generated by the user.80 // Maybe not a good idea to import them.81 parseDataFromCourses(tcd);77 // Usually logged activities are in the activities tag. 78 parseDataFromActivities(tcd); 79 // GPS tracks in the course tag are generated by the user. 80 // Maybe not a good idea to import them. 81 parseDataFromCourses(tcd); 82 82 83 } catch (JAXBException e) {84 throw new RuntimeException(e);85 }86 }83 } catch (JAXBException e) { 84 throw new RuntimeException(e); 85 } 86 } 87 87 88 /**89 * @param tcd90 */91 private void parseDataFromActivities(TrainingCenterDatabaseT tcd) {92 if ((tcd.getActivities() != null)93 && (tcd.getActivities().getActivity() != null)) {94 for (ActivityT activity : tcd.getActivities().getActivity()) {95 if (activity.getLap() != null) {96 for (ActivityLapT activityLap : activity.getLap()) {97 if (activityLap.getTrack() != null) {98 GpxTrack currentTrack = new GpxTrack();99 gpxData.tracks.add(currentTrack);100 for (TrackT track : activityLap.getTrack()) {101 if (track.getTrackpoint() != null) {102 Collection<WayPoint> currentTrackSeg = new ArrayList<WayPoint>();103 currentTrack.trackSegs.add(currentTrackSeg);104 for (TrackpointT trackpoint : track105 .getTrackpoint()) {106 // Some trackspoints don't have a107 // position.108 // Check it109 // first to avoid an NPE!110 if (trackpoint.getPosition() != null) {111 LatLon latLon = new LatLon(112 trackpoint113 .getPosition()114 .getLatitudeDegrees(),115 trackpoint116 .getPosition()117 .getLongitudeDegrees());118 WayPoint currentWayPoint = new WayPoint(119 latLon);120 // We usually have altitude info121 // here122 // (trackpoint.getAltitudeMeters())123 // Don't know how to add it to124 // the GPX125 // Data...126 currentTrackSeg127 .add(currentWayPoint);128 }129 }130 }131 }132 }133 }134 }135 }136 }137 }88 /** 89 * @param tcd 90 */ 91 private void parseDataFromActivities(TrainingCenterDatabaseT tcd) { 92 if ((tcd.getActivities() != null) 93 && (tcd.getActivities().getActivity() != null)) { 94 for (ActivityT activity : tcd.getActivities().getActivity()) { 95 if (activity.getLap() != null) { 96 for (ActivityLapT activityLap : activity.getLap()) { 97 if (activityLap.getTrack() != null) { 98 GpxTrack currentTrack = new GpxTrack(); 99 gpxData.tracks.add(currentTrack); 100 for (TrackT track : activityLap.getTrack()) { 101 if (track.getTrackpoint() != null) { 102 Collection<WayPoint> currentTrackSeg = new ArrayList<WayPoint>(); 103 currentTrack.trackSegs.add(currentTrackSeg); 104 for (TrackpointT trackpoint : track 105 .getTrackpoint()) { 106 // Some trackspoints don't have a 107 // position. 108 // Check it 109 // first to avoid an NPE! 110 if (trackpoint.getPosition() != null) { 111 LatLon latLon = new LatLon( 112 trackpoint 113 .getPosition() 114 .getLatitudeDegrees(), 115 trackpoint 116 .getPosition() 117 .getLongitudeDegrees()); 118 WayPoint currentWayPoint = new WayPoint( 119 latLon); 120 // We usually have altitude info 121 // here 122 // (trackpoint.getAltitudeMeters()) 123 // Don't know how to add it to 124 // the GPX 125 // Data... 126 currentTrackSeg 127 .add(currentWayPoint); 128 } 129 } 130 } 131 } 132 } 133 } 134 } 135 } 136 } 137 } 138 138 139 /**140 * @param tcd141 */142 private void parseDataFromCourses(TrainingCenterDatabaseT tcd) {143 if ((tcd.getCourses() != null)144 && (tcd.getCourses().getCourse() != null)) {145 for (CourseT course : tcd.getCourses().getCourse()) {146 if (course.getTrack() != null) {147 GpxTrack currentTrack = new GpxTrack();148 gpxData.tracks.add(currentTrack);149 for (TrackT track : course.getTrack()) {150 if (track.getTrackpoint() != null) {151 Collection<WayPoint> currentTrackSeg = new ArrayList<WayPoint>();152 currentTrack.trackSegs.add(currentTrackSeg);153 for (TrackpointT trackpoint : track.getTrackpoint()) {154 // Some trackspoints don't have a position.155 // Check it156 // first to avoid an NPE!157 if (trackpoint.getPosition() != null) {158 LatLon latLon = new LatLon(159 trackpoint.getPosition()160 .getLatitudeDegrees(),161 trackpoint.getPosition()162 .getLongitudeDegrees());163 WayPoint currentWayPoint = new WayPoint(164 latLon);165 // We usually have altitude info here166 // (trackpoint.getAltitudeMeters())167 // Don't know how to add it to the GPX168 // Data...169 currentTrackSeg.add(currentWayPoint);170 }171 }172 }173 }174 }175 }176 }177 }139 /** 140 * @param tcd 141 */ 142 private void parseDataFromCourses(TrainingCenterDatabaseT tcd) { 143 if ((tcd.getCourses() != null) 144 && (tcd.getCourses().getCourse() != null)) { 145 for (CourseT course : tcd.getCourses().getCourse()) { 146 if (course.getTrack() != null) { 147 GpxTrack currentTrack = new GpxTrack(); 148 gpxData.tracks.add(currentTrack); 149 for (TrackT track : course.getTrack()) { 150 if (track.getTrackpoint() != null) { 151 Collection<WayPoint> currentTrackSeg = new ArrayList<WayPoint>(); 152 currentTrack.trackSegs.add(currentTrackSeg); 153 for (TrackpointT trackpoint : track.getTrackpoint()) { 154 // Some trackspoints don't have a position. 155 // Check it 156 // first to avoid an NPE! 157 if (trackpoint.getPosition() != null) { 158 LatLon latLon = new LatLon( 159 trackpoint.getPosition() 160 .getLatitudeDegrees(), 161 trackpoint.getPosition() 162 .getLongitudeDegrees()); 163 WayPoint currentWayPoint = new WayPoint( 164 latLon); 165 // We usually have altitude info here 166 // (trackpoint.getAltitudeMeters()) 167 // Don't know how to add it to the GPX 168 // Data... 169 currentTrackSeg.add(currentWayPoint); 170 } 171 } 172 } 173 } 174 } 175 } 176 } 177 } 178 178 179 public GpxData getGpxData() {180 return gpxData;181 }179 public GpxData getGpxData() { 180 return gpxData; 181 } 182 182 }
Note:
See TracChangeset
for help on using the changeset viewer.
