Changeset 36243 in osm


Ignore:
Timestamp:
2024-04-09T09:09:06+02:00 (9 months ago)
Author:
GerdP
Message:

fix #23603: JOSM crashes while opening fit file generated by Suunto app on Android

  • also check if "ele" is stored as instance of Double
File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationHelper.java

    r36239 r36243  
    5959
    6060    /**
    61      * Gets the elevation (Z coordinate) of a GPX way point in meter or feet (for
    62      * US, UK, ZA, AU, NZ and CA).
     61     * Gets the elevation (Z coordinate) of a GPX way point in meter.
    6362     *
    6463     * @param wpt
    6564     *            The way point instance.
    66      * @return The x coordinate or <code>NO_ELEVATION</code>, if the given way point is null or contains
    67      *         not height attribute.
     65     * @return The Z coordinate or <code>NO_ELEVATION</code>, if the given way point is null or contains
     66     *         no height attribute.
    6867     */
    6968    public static double getElevation(WayPoint wpt) {
     
    7877        // no HGT, check for elevation data in GPX
    7978        // Parse elevation from GPX data
    80         String height = wpt.getString(HEIGHT_ATTRIBUTE);
    81         if (height == null) {
    82             // GPX has no elevation data :-(
    83             return NO_ELEVATION;
    84         }
    85 
    86         try {
    87             return Double.parseDouble(height);
    88         } catch (NumberFormatException e) {
    89             Logging.error(String.format("Cannot parse double from '%s': %s", height, e.getMessage()));
    90             return NO_ELEVATION;
    91         }
     79        Object height = wpt.get(HEIGHT_ATTRIBUTE);
     80        if (height instanceof String) {
     81            try {
     82                return Double.parseDouble((String) height);
     83            } catch (NumberFormatException e) {
     84                Logging.error(String.format("Cannot parse double from '%s': %s", height, e.getMessage()));
     85            }
     86        } else if (height instanceof Double) {
     87            eleInt = ((Double) height).doubleValue();
     88            if (isValidElevation(eleInt)) {
     89                return eleInt;
     90            }
     91        }
     92        return NO_ELEVATION;
    9293    }
    9394
Note: See TracChangeset for help on using the changeset viewer.