Changeset 36243 in osm
- Timestamp:
- 2024-04-09T09:09:06+02:00 (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationHelper.java
r36239 r36243 59 59 60 60 /** 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. 63 62 * 64 63 * @param wpt 65 64 * The way point instance. 66 * @return The xcoordinate or <code>NO_ELEVATION</code>, if the given way point is null or contains67 * no theight attribute.65 * @return The Z coordinate or <code>NO_ELEVATION</code>, if the given way point is null or contains 66 * no height attribute. 68 67 */ 69 68 public static double getElevation(WayPoint wpt) { … … 78 77 // no HGT, check for elevation data in GPX 79 78 // 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; 92 93 } 93 94
Note:
See TracChangeset
for help on using the changeset viewer.