Ticket #2064: josm-tangogps.patch
File josm-tangogps.patch, 5.8 KB (added by , 16 years ago) |
---|
-
src/org/openstreetmap/josm/actions/OpenFileAction.java
23 23 import org.openstreetmap.josm.io.GpxReader; 24 24 import org.openstreetmap.josm.io.NmeaReader; 25 25 import org.openstreetmap.josm.io.OsmReader; 26 import org.openstreetmap.josm.io.TangoReader; 26 27 import org.xml.sax.SAXException; 27 28 import org.openstreetmap.josm.tools.Shortcut; 28 29 … … 61 62 openFileAsGpx(file); 62 63 else if (asNmeaData(file.getName())) 63 64 openFileAsNmea(file); 65 else if (asTangoData(file.getName())) 66 openFileAsTango(file); 64 67 else 65 68 openAsData(file); 66 69 } catch (SAXException x) { … … 169 172 } 170 173 } 171 174 175 private void openFileAsTango(File file) throws IOException, FileNotFoundException { 176 String fn = file.getName(); 177 if (ExtensionFileFilter.filters[ExtensionFileFilter.TANGO].acceptName(fn)) { 178 TangoReader r = null; 179 InputStream is = new FileInputStream(file); 180 r = new TangoReader(is,file.getAbsoluteFile().getParentFile()); 181 r.data.storageFile = file; 182 GpxLayer gpxLayer = new GpxLayer(r.data, fn); 183 Main.main.addLayer(gpxLayer); 184 if (Main.pref.getBoolean("marker.makeautomarkers", true)) { 185 MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), file, gpxLayer); 186 if (ml.data.size() > 0) { 187 Main.main.addLayer(ml); 188 } 189 } 190 191 } else { 192 throw new IllegalStateException(); 193 } 194 } 195 172 196 private boolean asGpxData(String fn) { 173 197 return ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn); 174 198 } … … 177 201 return ExtensionFileFilter.filters[ExtensionFileFilter.NMEA].acceptName(fn); 178 202 } 179 203 204 private boolean asTangoData(String fn) { 205 return ExtensionFileFilter.filters[ExtensionFileFilter.TANGO].acceptName(fn); 206 } 180 207 181 208 } -
src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
21 21 public static final int OSM = 0; 22 22 public static final int GPX = 1; 23 23 public static final int NMEA = 2; 24 public static final int TANGO = 3; 24 25 25 26 public static ExtensionFileFilter[] filters = { 26 27 new ExtensionFileFilter("osm,xml", "osm", tr("OSM Server Files (*.osm *.xml)")), 27 28 new ExtensionFileFilter("gpx,gpx.gz", "gpx", tr("GPX Files (*.gpx *.gpx.gz)")), 28 29 new ExtensionFileFilter("nmea,txt", "nmea", tr("NMEA-0183 Files (*.nmea *.txt)")), 30 new ExtensionFileFilter("log", "log", tr("TangoGPS Files (*.log)")), 29 31 }; 30 32 31 33 /** -
src/org/openstreetmap/josm/io/TangoReader.java
1 //License: GPL. Copyright 2008 by Christoph Brill 2 3 package org.openstreetmap.josm.io; 4 5 import java.io.BufferedReader; 6 import java.io.File; 7 import java.io.FileReader; 8 import java.io.IOException; 9 import java.io.InputStream; 10 import java.io.InputStreamReader; 11 import java.util.ArrayList; 12 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.gpx.GpxData; 15 import org.openstreetmap.josm.data.gpx.GpxTrack; 16 import org.openstreetmap.josm.data.gpx.WayPoint; 17 18 /** 19 * Read a log file from TangoGPS. These are simple text files in the 20 * form: <lat>,<lon>,<elevation>,<speed>,<course>,<hdop>,<datetime> 21 * 22 * @author cbrill 23 */ 24 public class TangoReader { 25 26 public GpxData data; 27 28 public TangoReader(InputStream source, File relativeMarkerPath) { 29 30 // create the data tree 31 data = new GpxData(); 32 GpxTrack currentTrack = new GpxTrack(); 33 data.tracks.add(currentTrack); 34 ArrayList<WayPoint> currentTrackSeg = new ArrayList<WayPoint>(); 35 36 BufferedReader rd = null; 37 try { 38 39 rd = new BufferedReader(new InputStreamReader(source)); 40 41 String line; 42 while ((line = rd.readLine()) != null) { 43 String[] lineElements = line.split(","); 44 if (lineElements.length == 7) { 45 WayPoint currentWayPoint = new WayPoint(parseLatLon(lineElements)); 46 currentWayPoint.attr.put("ele", lineElements[2]); 47 currentWayPoint.attr.put("time", lineElements[6]); 48 currentWayPoint.setTime(); 49 currentTrackSeg.add(currentWayPoint); 50 } 51 } 52 currentTrack.trackSegs.add(currentTrackSeg); 53 data.recalculateBounds(); 54 } catch (final IOException e) { 55 // TODO tell user about the problem? 56 e.printStackTrace(); 57 } finally { 58 if (rd != null) { 59 try { 60 rd.close(); 61 } catch (IOException e) { 62 // Don't care 63 } 64 } 65 } 66 } 67 68 private double parseCoord(String s) { 69 try { 70 return Double.parseDouble(s); 71 } catch (NumberFormatException ex) { 72 return Double.NaN; 73 } 74 } 75 76 private LatLon parseLatLon(String[] lineElements) { 77 if (lineElements.length < 2) { 78 return null; 79 } 80 return new LatLon(parseCoord(lineElements[0]), parseCoord(lineElements[1])); 81 } 82 }