Changeset 512 in josm for trunk


Ignore:
Timestamp:
2008-01-04T01:25:43+01:00 (16 years ago)
Author:
gebner
Message:

Add support for two non-standard GPX variants:

  • <link>URL</link> (gets silently translated to <link href="URL"/>)
  • <... lat="nan" lon="nan"> (we parse "nan" as Double.NaN and skip these points when rendering)
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r494 r512  
    254254                        for (Collection<WayPoint> segment : trk.trackSegs) {
    255255                                for (WayPoint trkPnt : segment) {
     256                                        if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon()))
     257                                                continue;
    256258                                        Point screen = mv.getPoint(trkPnt.eastNorth);
    257259                                        if (lines && old != null) {
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r449 r512  
    6666                }               
    6767
     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(Attributes atts) {
     77                        return new LatLon(
     78                                parseCoord(atts.getValue("lat")),
     79                                parseCoord(atts.getValue("lon")));
     80                }
     81
    6882                @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    6983                        switch(currentState) {
     
    7387                                        currentState = state.metadata;
    7488                                } else if (qName.equals("wpt")) {
    75                                         LatLon ll = new LatLon(Double.parseDouble(atts.getValue("lat")), Double.parseDouble(atts.getValue("lon")));
    7689                                        states.push(currentState);
    7790                                        currentState = state.wpt;
    78                                         currentWayPoint = new WayPoint(ll);
     91                                        currentWayPoint = new WayPoint(parseLatLon(atts));
    7992                                } else if (qName.equals("rte")) {
    8093                                        states.push(currentState);
     
    122135                        case trkseg:
    123136                                if (qName.equals("trkpt")) {
    124                                         LatLon ll = new LatLon(Double.parseDouble(atts.getValue("lat")), Double.parseDouble(atts.getValue("lon")));
    125137                                        states.push(currentState);
    126138                                        currentState = state.wpt;
    127                                         currentWayPoint = new WayPoint(ll);
     139                                        currentWayPoint = new WayPoint(parseLatLon(atts));
    128140                                }
    129141                                break;
     
    144156                                        currentLink = new GpxLink(atts.getValue("href"));
    145157                                } else if (qName.equals("rtept")) {
    146                                         LatLon ll = new LatLon(Double.parseDouble(atts.getValue("lat")), Double.parseDouble(atts.getValue("lon")));
    147158                                        states.push(currentState);
    148159                                        currentState = state.wpt;
    149                                         currentWayPoint = new WayPoint(ll);
     160                                        currentWayPoint = new WayPoint(parseLatLon(atts));
    150161                                } else if (qName.equals("extensions")) {
    151162                                        states.push(currentState);
     
    198209                                        currentLink.type = accumulator.toString();
    199210                                } else if (qName.equals("link")) {
     211                                        // <link>URL</link>
     212                                        if (currentLink.uri == null)
     213                                                currentLink.uri = accumulator.toString();
     214
    200215                                        currentState = states.pop();
    201216                                }
Note: See TracChangeset for help on using the changeset viewer.