Ignore:
Timestamp:
2005-10-09T04:14:40+02:00 (19 years ago)
Author:
imi
Message:
  • added Layer support
  • added support for raw GPS data
  • fixed tooltips
  • added options for loading gpx files
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/io/GpxReader.java

    r16 r17  
    4040         */
    4141        public Reader source;
     42        /**
     43         * If <code>true</code>, only nodes and tracks are imported (but no key/value
     44         * pairs). That is to support background gps information as an hint for
     45         * real OSM data.
     46         */
     47        private final boolean rawGps;
    4248       
    4349        /**
    4450         * Construct a parser from a specific data source.
    4551         * @param source The data source, as example a FileReader to read from a file.
    46          */
    47         public GpxReader(Reader source) {
     52         * @param rawGps Whether the gpx file describes raw gps data. Only very few
     53         *              information (only nodes and line segments) imported for raw gps to
     54         *              save memory.
     55         */
     56        public GpxReader(Reader source, boolean rawGps) {
    4857                this.source = source;
     58                this.rawGps = rawGps;
    4959        }
    5060       
     
    5666                        final SAXBuilder builder = new SAXBuilder();
    5767                        Element root = builder.build(source).getRootElement();
    58                         System.out.println(root.getNamespacePrefix());
    5968                       
    6069                        // HACK, since the osm server seem to not provide a namespace.
     
    8594                        Float.parseFloat(e.getAttributeValue("lat")),
    8695                        Float.parseFloat(e.getAttributeValue("lon")));
     96               
     97                if (rawGps)
     98                        return data;
     99               
    87100                for (Object o : e.getChildren()) {
    88101                        Element child = (Element)o;
     
    126139                for (Object o : e.getChildren()) {
    127140                        Element child = (Element)o;
    128                         if (child.getName().equals("extensions"))
    129                                 parseKeyValueExtensions(track, child);
    130                         else if (child.getName().equals("link"))
    131                                 parseKeyValueLink(track, child);
    132                         else if (child.getName().equals("trkseg")) {
     141
     142                        if (child.getName().equals("trkseg")) {
    133143                                Node start = null;
    134144                                for (Object w : child.getChildren("trkpt", GPX)) {
     
    139149                                        else {
    140150                                                LineSegment lineSegment = new LineSegment(start, node);
    141                                                 parseKeyValueExtensions(lineSegment, ((Element)w).getChild("extensions", GPX));
     151                                                if (!rawGps)
     152                                                        parseKeyValueExtensions(lineSegment, ((Element)w).getChild("extensions", GPX));
    142153                                                track.add(lineSegment);
    143154                                                start = null;
    144155                                        }
    145156                                }
    146                         } else
     157                        }
     158                       
     159                        if (rawGps)
     160                                continue;
     161                       
     162                        if (child.getName().equals("extensions"))
     163                                parseKeyValueExtensions(track, child);
     164                        else if (child.getName().equals("link"))
     165                                parseKeyValueLink(track, child);
     166                        else
    147167                                parseKeyValueTag(track, child);
    148168                }
     
    156176         * to the node in the list (either the new added or the old found).
    157177         *
     178         * If reading raw gps data, mergeNodes are always on (To save memory. You
     179         * can't edit raw gps nodes anyway.)
     180         *
    158181         * @param data The DataSet to add the node to.
    159182         * @param node The node that should be added.
     
    161184         */
    162185        private Node addNode (DataSet data, Node node) {
    163                 if (Main.pref.mergeNodes)
     186                if (Main.pref.mergeNodes || rawGps)
    164187                        for (Node n : data.nodes)
    165                                 if (node.coor.lat == n.coor.lat && node.coor.lon == n.coor.lon)
     188                                if (node.coor.equalsLatLon(n.coor))
    166189                                        return n;
    167190                data.nodes.add(node);
Note: See TracChangeset for help on using the changeset viewer.