Changeset 35165 in osm for applications/editors
- Timestamp:
- 2019-10-01T00:12:18+02:00 (5 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationHelper.java
r34746 r35165 6 6 import java.util.GregorianCalendar; 7 7 import java.util.List; 8 import java.util.Locale;9 8 10 9 import org.openstreetmap.josm.data.Bounds; 10 import org.openstreetmap.josm.data.SystemOfMeasurement; 11 11 import org.openstreetmap.josm.data.coor.LatLon; 12 12 import org.openstreetmap.josm.data.gpx.WayPoint; 13 13 import org.openstreetmap.josm.plugins.elevation.gpx.GeoidCorrectionKind; 14 import org.openstreetmap.josm.tools.Logging; 14 15 15 16 /** … … 24 25 } 25 26 26 public static double METER_TO_FEET = 3.280948;27 28 /* Countries which use the imperial system instead of the metric system. */29 private static String[] IMPERIAL_SYSTEM_COUNTRIES = {30 "en_US", /* USA */31 "en_CA", /* Canada */32 "en_AU", /* Australia */33 "en_NZ", /* New Zealand */34 // "de_DE", /* for testing only */35 "en_ZA" /* South Africa */36 };37 38 27 /** The 'no elevation' data magic. */ 39 public static double NO_ELEVATION = Double.NaN;28 public static final double NO_ELEVATION = Double.NaN; 40 29 41 30 /** … … 44 33 public static final String HEIGHT_ATTRIBUTE = "ele"; 45 34 46 private static UnitMode unitMode = UnitMode.NotSelected;47 48 35 private static GeoidCorrectionKind geoidKind = GeoidCorrectionKind.None; 49 36 50 37 /** The HGT reader instance. */ 51 private static HgtReader hgt = new HgtReader();38 private static final HgtReader hgt = new HgtReader(); 52 39 53 40 /** … … 60 47 public static void setGeoidKind(GeoidCorrectionKind geoidKind) { 61 48 ElevationHelper.geoidKind = geoidKind; 62 }63 64 /**65 * Gets the current unit mode (metric or imperial).66 */67 public static UnitMode getUnitMode() {68 //TODO: Use this until /JOSM/src/org/openstreetmap/josm/gui/NavigatableComponent.java69 // has a an appropriate method70 71 // unit mode already determined?72 if (unitMode != UnitMode.NotSelected) {73 return unitMode;74 }75 76 // Set default77 unitMode = UnitMode.Metric;78 79 // Check if user could prefer imperial system80 Locale l = Locale.getDefault();81 for (int i = 0; i < IMPERIAL_SYSTEM_COUNTRIES.length; i++) {82 String ctry = l.toString();83 if (IMPERIAL_SYSTEM_COUNTRIES[i].equals(ctry)) {84 unitMode = UnitMode.Imperial;85 }86 }87 88 return unitMode;89 }90 91 /**92 * Gets the unit string for elevation ("m" or "ft").93 */94 public static String getUnit() {95 switch (getUnitMode()) {96 case Metric:97 return "m";98 case Imperial:99 return "ft";100 default:101 throw new RuntimeException("Invalid or unsupported unit mode: " + unitMode);102 }103 49 } 104 50 … … 128 74 double eleInt = getSrtmElevation(wpt.getCoor()); 129 75 if (isValidElevation(eleInt)) { 130 return convert(eleInt);76 return eleInt; 131 77 } 132 78 … … 140 86 String height = wpt.getString(ElevationHelper.HEIGHT_ATTRIBUTE); 141 87 try { 142 double z = Double.parseDouble(height); 143 144 return convert(z); 88 return Double.parseDouble(height); 145 89 } catch (NumberFormatException e) { 146 System.err.println(String.format( 147 "Cannot parse double from '%s': %s", height, e 148 .getMessage())); 90 Logging.error(String.format("Cannot parse double from '%s': %s", height, e.getMessage())); 149 91 return NO_ELEVATION; 150 92 } … … 152 94 153 95 private static double getElevation(LatLon ll) { 154 double ele = getSrtmElevation(ll); 155 //System.out.println("Get elevation " + ll + " => " + ele); 156 return convert(ele); 157 } 158 159 /** 160 * Converts the value to feet, if required. 161 * 162 * @param ele the elevation to convert 163 * @return the double 164 */ 165 private static double convert(double ele) { 166 if (isValidElevation(ele)) { 167 if (getUnitMode() == UnitMode.Imperial) { 168 // translate to feet 169 return meter2Feet(ele); 170 } else { 171 // keep 'as is' 172 return ele; 173 } 174 } 175 return NO_ELEVATION; 96 return getSrtmElevation(ll); 176 97 } 177 98 … … 189 110 190 111 // get distance in meters and divide it by 100 in advance 191 double distInMeter = convert(w1.greatCircleDistance(w2) / 100.0);192 193 // get elevation (difference) - is converted automatically to feet112 double distInMeter = w1.greatCircleDistance(w2) / 100.0; 113 114 // get elevation (difference) 194 115 int ele1 = (int) ElevationHelper.getElevation(w1); 195 116 int ele2 = (int) ElevationHelper.getElevation(w2); … … 201 122 202 123 /** 203 * Converts meter into feet204 *205 * @param meter the meter206 * @return the double207 */208 public static double meter2Feet(double meter) {209 return meter * METER_TO_FEET;210 }211 212 /**213 124 * Gets the elevation string for a given elevation, e. g "300m" or "800ft". 214 125 */ 215 126 public static String getElevationText(int elevation) { 216 return S tring.format("%d %s", elevation, getUnit());127 return SystemOfMeasurement.getSystemOfMeasurement().getDistText(elevation); 217 128 } 218 129 … … 221 132 */ 222 133 public static String getElevationText(double elevation) { 223 return S tring.format("%d %s", (int) Math.round(elevation), getUnit());134 return SystemOfMeasurement.getSystemOfMeasurement().getDistText((int) Math.round(elevation)); 224 135 } 225 136 … … 233 144 if (wpt == null) return "-"; 234 145 235 int elevation = (int) Math.round(ElevationHelper.getElevation(wpt)); 236 return String.format("%d %s", elevation, getUnit()); 146 return getElevationText(ElevationHelper.getElevation(wpt)); 237 147 } 238 148 … … 262 172 double eleHgt = hgt.getElevationFromHgt(ll); 263 173 264 //System.out.println("Get elevation from HGT " + ll + " => " + eleHgt);265 174 if (isValidElevation(eleHgt)) { 266 175 return eleHgt; -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java
r34507 r35165 14 14 import org.openstreetmap.josm.data.coor.LatLon; 15 15 import org.openstreetmap.josm.tools.CheckParameterUtil; 16 import org.openstreetmap.josm.tools.Logging; 16 17 17 18 /** … … 60 61 return readElevation(coor); 61 62 } catch (FileNotFoundException e) { 62 System.err.println("Get elevation from HGT " + coor + " failed: => " + e.getMessage());63 Logging.error("Get elevation from HGT " + coor + " failed: => " + e.getMessage()); 63 64 // no problem... file not there 64 65 return ElevationHelper.NO_ELEVATION; 65 66 } catch (Exception ioe) { 66 67 // oops... 67 ioe.printStackTrace(System.err);68 Logging.error(ioe); 68 69 // fallback 69 70 return ElevationHelper.NO_ELEVATION; … … 86 87 87 88 bb.flip(); 88 //sb = bb.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();89 89 sb = bb.order(ByteOrder.BIG_ENDIAN).asShortBuffer(); 90 90 } finally { … … 122 122 int cell = (HGT_ROW_LENGTH * (row - 1)) + col; 123 123 124 //System.out.println("Read SRTM elevation data from row/col/cell " + row + "," + col + ", " + cell + ", " + sb.limit());125 126 124 // valid position in buffer? 127 125 if (cell < sb.limit()) { 128 126 short ele = sb.get(cell); 129 //System.out.println("==> Read SRTM elevation data from row/col/cell " + row + "," + col + ", " + cell + " = " + ele);130 127 // check for data voids 131 128 if (ele == HGT_VOID) { -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/EleVertex.java
r34133 r35165 59 59 for (int j = i + 1; j < points.length; j++) { 60 60 EleCoordinate c2 = points[j]; 61 62 61 edges[k++] = new TriangleEdge(i, j, c1.greatCircleDistance(c2)); 63 62 } 64 63 } 65 66 /*67 for (int i = 0; i < edges.length; i++) {68 TriangleEdge triangleEdge = edges[i];69 System.out.println("#" + i + ": " +triangleEdge);70 }*/71 64 72 65 // sort by distance … … 75 68 TriangleEdge longest = edges[0]; 76 69 77 78 //System.out.println("Longest " + longest);79 70 EleCoordinate pI = points[longest.getI()]; 80 71 EleCoordinate pJ = points[longest.getJ()]; 81 72 EleCoordinate pK = points[longest.getK()]; 82 73 EleCoordinate newP = getMid(pI, pJ); 83 /* 84 System.out.println(pI); 85 System.out.println(pJ); 86 System.out.println(pK); 87 System.out.println(newP); 88 */ 74 89 75 List<EleVertex> res = new ArrayList<>(); 90 76 res.add(new EleVertex(pI, pK, newP)); -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridLayer.java
r33815 r35165 64 64 tileSet = new TileSet(box.getMin(), box.getMax(), ELE_ZOOM_LEVEL); // we use a vector format with constant zoom level 65 65 lastBounds = box; 66 System.out.println("paint " + tileSet);67 66 } 68 67 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTile.java
r34095 r35165 15 15 16 16 import org.openstreetmap.gui.jmapviewer.Tile; 17 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache;18 17 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 19 18 import org.openstreetmap.josm.data.Bounds; … … 41 40 BufferedImage image) { 42 41 super(source, xtile, ytile, zoom, image); 43 44 45 }46 47 @Override48 public void loadPlaceholderFromCache(TileCache cache) {49 // TODO Auto-generated method stub50 super.loadPlaceholderFromCache(cache);51 52 //System.out.println("loadPlaceholderFromCache");53 }54 55 @Override56 public String getUrl() throws IOException {57 // TODO Auto-generated method stub58 return super.getUrl();59 42 } 60 43 … … 67 50 super.paint(g, x, y); 68 51 69 //g.drawString(String.format("EGT %d/%d ", getXtile(), getYtile()), x, y);70 52 g.drawString(getStatus(), x, y); 71 53 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java
r34507 r35165 26 26 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; 27 27 import org.openstreetmap.josm.tools.CheckParameterUtil; 28 import org.openstreetmap.josm.tools.Logging; 28 29 29 30 /** … … 65 66 66 67 if (wpt == null || profile == null) { 67 System.err.println(String.format( 68 "Cannot determine color: prof=%s, wpt=%s", profile, wpt)); 68 Logging.error(String.format("Cannot determine color: prof=%s, wpt=%s", profile, wpt)); 69 69 return null; 70 70 } … … 113 113 114 114 if (wpt == null) { 115 System.err.println(String.format( 116 "Cannot paint: mv=%s, prof=%s, wpt=%s", mv, profile, wpt)); 115 Logging.error(String.format("Cannot paint: mv=%s, prof=%s, wpt=%s", mv, profile, wpt)); 117 116 return; 118 117 } … … 142 141 143 142 if (wpt1 == null || wpt2 == null) { 144 System.err.println(String.format( 145 "Cannot paint line: mv=%s, prof=%s, kind = %s", mv, profile, kind)); 143 Logging.error(String.format("Cannot paint line: mv=%s, prof=%s, kind = %s", mv, profile, kind)); 146 144 return; 147 145 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java
r33815 r35165 26 26 27 27 import org.openstreetmap.josm.data.SystemOfMeasurement; 28 import org.openstreetmap.josm.data.SystemOfMeasurement.SoMChangeListener; 28 29 import org.openstreetmap.josm.data.gpx.GpxData; 29 30 import org.openstreetmap.josm.gui.MainApplication; … … 49 50 * connection between layer and elevation profile. 50 51 */ 51 public class ElevationProfileDialog extends ToggleDialog implements LayerChangeListener, ActiveLayerChangeListener, ComponentListener { 52 public class ElevationProfileDialog extends ToggleDialog 53 implements LayerChangeListener, ActiveLayerChangeListener, ComponentListener, SoMChangeListener { 52 54 53 55 private static final String EMPTY_DATA_STRING = "-"; … … 198 200 @Override 199 201 public void showNotify() { 202 SystemOfMeasurement.addSoMChangeListener(this); 200 203 MainApplication.getLayerManager().addLayerChangeListener(this); 201 204 MainApplication.getLayerManager().addActiveLayerChangeListener(this); … … 212 215 MainApplication.getLayerManager().removeActiveLayerChangeListener(this); 213 216 MainApplication.getLayerManager().removeLayerChangeListener(this); 217 SystemOfMeasurement.removeSoMChangeListener(this); 214 218 } 215 219 … … 469 473 } 470 474 } 475 476 @Override 477 public void systemOfMeasurementChanged(String oldSoM, String newSoM) { 478 updateView(); 479 } 471 480 }
Note:
See TracChangeset
for help on using the changeset viewer.