Changeset 189 in josm
- Timestamp:
- 2007-01-06T15:10:37+01:00 (18 years ago)
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
CONTRIBUTION
r165 r189 15 15 The jar-file is licensed under LGPL. 16 16 17 Some plugins (hosted elsewhere) are from Nick Whitelegg. 18 Frederik Ramm did some of the actions and the MarkerLayer. 17 19 Several smaller patches are contributed by community members 18 20 of OSM. 19 20 Some plugins are from Nick Whitelegg (currently mappaint and21 landsat).22 21 23 22 Internalisation: -
src/org/openstreetmap/josm/actions/OpenAction.java
r175 r189 18 18 import org.openstreetmap.josm.Main; 19 19 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.gui.layer.MarkerLayer; 20 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 22 import org.openstreetmap.josm.gui.layer.RawGpsLayer; 23 import org.openstreetmap.josm.gui.layer.MarkerLayer.Marker; 22 24 import org.openstreetmap.josm.gui.layer.RawGpsLayer.GpsPoint; 23 25 import org.openstreetmap.josm.io.OsmReader; … … 57 59 try { 58 60 if (asRawData(fn)) { 59 Collection<Collection<GpsPoint>> data; 61 Collection<Collection<GpsPoint>> gpsData = null; 62 Collection<Marker> markerData = null; 60 63 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 61 data = RawGpsReader.parse(new FileInputStream(file)); 64 RawGpsReader r = new RawGpsReader(new FileInputStream(file)); 65 gpsData = r.trackData; 66 markerData = r.markerData; 62 67 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 63 data = new LinkedList<Collection<GpsPoint>>();64 data.add(new RawCsvReader(new FileReader(file)).parse());68 gpsData = new LinkedList<Collection<GpsPoint>>(); 69 gpsData.add(new RawCsvReader(new FileReader(file)).parse()); 65 70 } else 66 71 throw new IllegalStateException(); 67 Main.main.addLayer(new RawGpsLayer(data, file.getName(), file)); 72 if ((gpsData != null) && (!gpsData.isEmpty())) 73 Main.main.addLayer(new RawGpsLayer(gpsData, tr("Tracks from {0}", file.getName()), file)); 74 if ((markerData != null) && (!markerData.isEmpty())) 75 Main.main.addLayer(new MarkerLayer(markerData, tr ("Markers from {0}", file.getName()), file)); 76 68 77 } else { 69 78 DataSet dataSet; -
src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r175 r189 48 48 if (in == null) 49 49 break; 50 Collection<Collection<GpsPoint>> allWays = RawGpsReader.parse(in); 50 // Use only track points, since the server mix everything together 51 Collection<Collection<GpsPoint>> allWays = new RawGpsReader(in).trackData; 52 51 53 boolean foundSomething = false; 52 54 for (Collection<GpsPoint> t : allWays) { -
src/org/openstreetmap/josm/io/RawGpsReader.java
r118 r189 6 6 import java.io.InputStream; 7 7 import java.io.InputStreamReader; 8 import java.util.ArrayList; 8 9 import java.util.Collection; 9 10 import java.util.LinkedList; … … 11 12 12 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.gui.layer.MarkerLayer.Marker; 13 15 import org.openstreetmap.josm.gui.layer.RawGpsLayer.GpsPoint; 14 16 import org.xml.sax.Attributes; … … 24 26 public class RawGpsReader { 25 27 26 private static class Parser extends MinML2 { 28 /** 29 * Hold the resulting gps data (tracks and their track points) 30 */ 31 public Collection<Collection<GpsPoint>> trackData = new LinkedList<Collection<GpsPoint>>(); 32 33 /** 34 * Hold the waypoints of the gps data. 35 */ 36 public Collection<Marker> markerData = new ArrayList<Marker>(); 37 38 private class Parser extends MinML2 { 27 39 /** 28 40 * Current track to be read. The last entry is the current trkpt. … … 30 42 */ 31 43 private Collection<GpsPoint> current = new LinkedList<GpsPoint>(); 32 public Collection<Collection<GpsPoint>> data = new LinkedList<Collection<GpsPoint>>();33 44 private LatLon currentLatLon; 34 45 private String currentTime = ""; 46 private String currentName = ""; 35 47 private Stack<String> tags = new Stack<String>(); 36 48 … … 50 62 } 51 63 currentTime = ""; 64 currentName = ""; 52 65 } 53 66 tags.push(qName); … … 55 68 56 69 @Override public void characters(char[] ch, int start, int length) { 57 if (tags.peek().equals("time")) { 58 String time = tags.pop(); 70 String peek = tags.peek(); 71 if (peek.equals("time") || peek.equals("name")) { 72 String tag = tags.pop(); 59 73 if (tags.empty() || (!tags.peek().equals("wpt") && !tags.peek().equals("trkpt"))) { 60 tags.push(t ime);74 tags.push(tag); 61 75 return; 62 76 } 63 String c t= new String(ch, start, length);64 currentTime += c t;65 tags.push(t ime);77 String contents = new String(ch, start, length); 78 if (peek.equals("time")) currentTime += contents; else currentName += contents; 79 tags.push(tag); 66 80 } 67 81 } 68 82 69 83 @Override public void endElement(String namespaceURI, String localName, String qName) { 70 if (qName.equals(" wpt") || qName.equals("trkpt")) {84 if (qName.equals("trkpt")) { 71 85 current.add(new GpsPoint(currentLatLon, currentTime)); 72 86 currentTime = ""; 87 currentName = ""; 88 } else if (qName.equals("wpt")) { 89 markerData.add(new Marker(currentLatLon, currentName, null)); 90 currentTime = ""; 91 currentName = ""; 73 92 } else if (qName.equals("trkseg") || qName.equals("trk") || qName.equals("gpx")) { 74 93 newTrack(); 75 94 currentTime = ""; 95 currentName = ""; 76 96 } 77 97 tags.pop(); … … 80 100 private void newTrack() { 81 101 if (!current.isEmpty()) { 82 data.add(current);102 trackData.add(current); 83 103 current = new LinkedList<GpsPoint>(); 84 104 } … … 86 106 } 87 107 108 88 109 /** 89 * Parse and returnthe read data110 * Parse the input stream and store the result in trackData and markerData 90 111 */ 91 public static Collection<Collection<GpsPoint>> parse(InputStream source) throws SAXException, IOException {112 public RawGpsReader(InputStream source) throws SAXException, IOException { 92 113 Parser parser = new Parser(); 93 114 parser.parse(new InputStreamReader(source, "UTF-8")); 94 return parser.data;95 115 } 96 116 }
Note:
See TracChangeset
for help on using the changeset viewer.