Changeset 29907 in osm for applications/editors/josm/plugins/ElevationProfile
- Timestamp:
- 2013-09-01T21:54:35+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile
- Files:
-
- 27 added
- 10 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfilePlugin.java
r29876 r29907 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.actions.JosmAction; 18 19 import org.openstreetmap.josm.gui.IconToggleButton; 20 import org.openstreetmap.josm.gui.MainMenu; 19 21 import org.openstreetmap.josm.gui.MapFrame; 20 22 import org.openstreetmap.josm.plugins.Plugin; 21 23 import org.openstreetmap.josm.plugins.PluginInformation; 24 import org.openstreetmap.josm.plugins.elevation.actions.AddElevationLayerAction; 22 25 import org.openstreetmap.josm.plugins.elevation.gui.ElevationProfileDialog; 23 26 import org.openstreetmap.josm.plugins.elevation.gui.ElevationProfileLayer; 27 import static org.openstreetmap.josm.tools.I18n.tr; 24 28 25 29 /** … … 44 48 eleMode = new ElevationMapMode("Elevation profile", Main.map); 45 49 eleModeButton = new IconToggleButton(eleMode); 50 51 JosmAction action = new AddElevationLayerAction(); 52 53 MainMenu.add(Main.main.menu.viewMenu, action, false, 0); 54 46 55 } catch (Exception e1) { 47 56 System.err.println("Init of ElevationProfilePlugin failed: " + e1); 48 57 e1.printStackTrace(); 49 58 } 50 51 getPluginDir();52 59 } 53 60 … … 77 84 public static ElevationProfileLayer getCurrentLayer(){ 78 85 if(currentLayer == null){ 79 currentLayer = new ElevationProfileLayer( "Elevation profile");86 currentLayer = new ElevationProfileLayer(tr("Elevation Profile")); 80 87 Main.main.addLayer(currentLayer); 81 88 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java
r29877 r29907 48 48 File f = new File(fullPath); 49 49 if (f.exists()) { 50 // nope: read HGT file...50 // found something: read HGT file... 51 51 ShortBuffer data = readHgtFile(fullPath); 52 System.out.println("Read SRTM data from " + fullPath + ", tag is '" + file + "'"); 52 53 // ... and store result in cache 53 54 cache.put(file, data); … … 55 56 } 56 57 } 57 } 58 } 59 60 System.out.println("Get elevation from HGT file " + file); 58 61 59 62 // read elevation value 60 63 return readElevation(coor); 61 64 } catch (FileNotFoundException e) { 65 System.err.println("Get elevation from HGT " + coor + " failed: => " + e.getMessage()); 62 66 // no problem... file not there 63 return Double.NaN;67 return ElevationHelper.NO_ELEVATION; 64 68 } catch (Exception ioe) { 65 69 // oops... 66 ioe.printStackTrace( );70 ioe.printStackTrace(System.err); 67 71 // fallback 68 return Double.NaN;72 return ElevationHelper.NO_ELEVATION; 69 73 } 70 74 } … … 107 111 108 112 if (sb == null) { 109 return Double.NaN; 113 System.out.println("readElevation: Buffer is null for tag '" + tag + "'"); 114 return ElevationHelper.NO_ELEVATION; 110 115 } 111 116 … … 120 125 row = HGT_ROW_LENGTH - row; 121 126 int cell = (HGT_ROW_LENGTH* (row - 1)) + col; 127 128 //System.out.println("Read SRTM elevation data from row/col/cell " + row + "," + col + ", " + cell + ", " + sb.limit()); 122 129 123 130 // valid position in buffer? 124 131 if (cell < sb.limit()) { 125 132 short ele = sb.get(cell); 133 //System.out.println("==> Read SRTM elevation data from row/col/cell " + row + "," + col + ", " + cell + " = " + ele); 126 134 // check for data voids 127 135 if (ele == HGT_VOID) { 128 return Double.NaN;136 return ElevationHelper.NO_ELEVATION; 129 137 } else { 130 138 return ele; 131 139 } 132 140 } else { 133 return Double.NaN;141 return ElevationHelper.NO_ELEVATION; 134 142 } 135 143 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IElevationModelListener.java
r23795 r29907 15 15 package org.openstreetmap.josm.plugins.elevation; 16 16 17 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel; 18 17 19 /** 18 20 * This interface is intended to allow clients reaction on changes in the elevation model changes (e. g. -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java
r29874 r29907 32 32 import org.openstreetmap.josm.data.gpx.WayPoint; 33 33 import org.openstreetmap.josm.gui.MapView; 34 import org.openstreetmap.josm.plugins.elevation.ElevationWayPointKind;35 34 import org.openstreetmap.josm.plugins.elevation.IElevationProfile; 36 import org.openstreetmap.josm.plugins.elevation.WayPointHelper; 35 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 36 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; 37 37 import org.openstreetmap.josm.tools.CheckParameterUtil; 38 38 … … 88 88 } 89 89 90 int z = (int) WayPointHelper.getElevation(wpt);90 int z = (int) ElevationHelper.getElevation(wpt); 91 91 92 92 switch (kind) { … … 192 192 193 193 Point pnt = mv.getPoint(wpt.getEastNorth()); 194 int ele = ((int) Math.rint( WayPointHelper.getElevation(wpt) / 100.0)) * 100;194 int ele = ((int) Math.rint(ElevationHelper.getElevation(wpt) / 100.0)) * 100; 195 195 196 196 int rad = REGULAR_WPT_RADIUS; … … 200 200 /* Paint full hour label */ 201 201 if (kind == ElevationWayPointKind.FullHour) { 202 int hour = WayPointHelper.getHourOfWayPoint(wpt);202 int hour = ElevationHelper.getHourOfWayPoint(wpt); 203 203 drawLabel(String.format("%02d:00", hour), pnt.x, pnt.y 204 204 + g.getFontMetrics().getHeight(), g); … … 207 207 /* Paint label for elevation levels */ 208 208 if (kind == ElevationWayPointKind.ElevationLevelGain) { 209 drawLabelWithTriangle( WayPointHelper.getElevationText(ele), pnt.x, pnt.y209 drawLabelWithTriangle(ElevationHelper.getElevationText(ele), pnt.x, pnt.y 210 210 + g.getFontMetrics().getHeight(), g, c, 8, 211 211 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationGainHigh), … … 214 214 215 215 if (kind == ElevationWayPointKind.ElevationLevelLoss) { 216 drawLabelWithTriangle( WayPointHelper.getElevationText(ele),216 drawLabelWithTriangle(ElevationHelper.getElevationText(ele), 217 217 pnt.x, pnt.y+ g.getFontMetrics().getHeight(), g, c, 8, 218 218 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationLossHigh), … … 223 223 if (kind == ElevationWayPointKind.Highlighted) { 224 224 drawSphere(g, Color.WHITE, c, pnt.x, pnt.y, BIG_WPT_RADIUS); 225 drawLabel( WayPointHelper.getTimeText(wpt), pnt.x, pnt.y225 drawLabel(ElevationHelper.getTimeText(wpt), pnt.x, pnt.y 226 226 - g.getFontMetrics().getHeight() - 5, g); 227 drawLabel( WayPointHelper.getElevationText(wpt), pnt.x, pnt.y227 drawLabel(ElevationHelper.getElevationText(wpt), pnt.x, pnt.y 228 228 + g.getFontMetrics().getHeight() + 5, g); 229 229 } … … 248 248 249 249 Color c = getColorForWaypoint(profile, wpt, kind); 250 int eleH = (int) WayPointHelper.getElevation(wpt);250 int eleH = (int) ElevationHelper.getElevation(wpt); 251 251 Point pnt = mv.getPoint(wpt.getEastNorth()); 252 252 … … 273 273 DefaultElevationProfileRenderer.TRIANGLE_BASESIZE); 274 274 275 drawLabel( WayPointHelper.getElevationText(eleH), pnt.x, pnt.y275 drawLabel(ElevationHelper.getElevationText(eleH), pnt.x, pnt.y 276 276 + g.getFontMetrics().getHeight(), g, c); 277 277 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationColors.java
r23795 r29907 17 17 import java.awt.Color; 18 18 19 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 20 19 21 /** 20 22 * Contains some extra predefined colors. … … 30 32 public static Color EPLightBeige = new Color(235, 235, 215); 31 33 public static Color EPMidBeige = new Color(227, 222, 215); 34 35 36 static class ColorMapEntry { 37 private int ele; // limit 38 private Color color; 39 public ColorMapEntry(java.awt.Color color, int ele) { 40 super(); 41 this.color = color; 42 this.ele = ele; 43 } 44 45 public int getEle() { 46 return ele; 47 } 48 49 public Color getColor() { 50 return color; 51 } 52 } 53 54 private static ColorMapEntry[] colors = new ColorMapEntry[]{ 55 new ColorMapEntry(new Color(0,128, 0), 0), 56 new ColorMapEntry(new Color(156,187, 105), 1), 57 new ColorMapEntry(new Color(193,208, 107), 100), 58 new ColorMapEntry(new Color(244,224, 100), 200), 59 new ColorMapEntry(new Color(242,216, 149), 500), 60 new ColorMapEntry(new Color(234,191, 104), 1000), 61 new ColorMapEntry(new Color(207,169, 96), 2000), 62 }; 63 64 public static Color interpolate(java.awt.Color c1, java.awt.Color c2) { 65 int r = (c1.getRed() + c2.getRed()) / 2; 66 int g = (c1.getGreen() + c2.getGreen()) / 2; 67 int b = (c1.getBlue() + c2.getBlue()) / 2; 68 return new Color(r, g, b); 69 } 70 71 public static Color getElevationColor(double ele) { 72 if (!ElevationHelper.isValidElevation(ele)) { 73 return Color.white; 74 } 75 76 // TODO: Better color model... 77 Color col = Color.green; 78 79 if (ele < 0) { 80 col = Color.blue; 81 } 82 83 if (ele > 200) { 84 col = colors[1].getColor(); 85 } 86 87 if (ele > 300) { 88 col = colors[2].getColor(); 89 } 90 91 if (ele > 400) { 92 col = colors[3].getColor(); 93 } 94 95 if (ele > 500) { 96 col = Color.yellow; 97 } 98 99 if (ele > 750) { 100 col = Color.orange; 101 } 102 103 if (ele > 1000) { 104 col = Color.lightGray; 105 } 106 107 if (ele > 2000) { 108 col = Color.darkGray; 109 } 110 111 return col; 112 } 32 113 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java
r26941 r29907 40 40 import org.openstreetmap.josm.gui.layer.GpxLayer; 41 41 import org.openstreetmap.josm.gui.layer.Layer; 42 import org.openstreetmap.josm.plugins.elevation.ElevationModel;43 import org.openstreetmap.josm.plugins.elevation.GeoidCorrectionKind;44 42 import org.openstreetmap.josm.plugins.elevation.IElevationModelListener; 45 import org.openstreetmap.josm.plugins.elevation.WayPointHelper; 43 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 44 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel; 45 import org.openstreetmap.josm.plugins.elevation.gpx.GeoidCorrectionKind; 46 46 import org.openstreetmap.josm.tools.Shortcut; 47 47 … … 170 170 geoidNone.addActionListener(new ActionListener() { 171 171 public void actionPerformed(ActionEvent arg0) { 172 WayPointHelper.setGeoidKind(GeoidCorrectionKind.None);172 ElevationHelper.setGeoidKind(GeoidCorrectionKind.None); 173 173 geoidFixedValue.setEnabled(false); 174 174 getModel().updateElevationData(); … … 180 180 geoidAuto.addActionListener(new ActionListener() { 181 181 public void actionPerformed(ActionEvent arg0) { 182 WayPointHelper.setGeoidKind(GeoidCorrectionKind.Auto);182 ElevationHelper.setGeoidKind(GeoidCorrectionKind.Auto); 183 183 geoidFixedValue.setEnabled(false); 184 184 getModel().updateElevationData(); … … 191 191 geoidFixed.addActionListener(new ActionListener() { 192 192 public void actionPerformed(ActionEvent arg0) { 193 WayPointHelper.setGeoidKind(GeoidCorrectionKind.Fixed);193 ElevationHelper.setGeoidKind(GeoidCorrectionKind.Fixed); 194 194 geoidFixedValue.setEnabled(true); 195 195 getModel().updateElevationData(); … … 220 220 profPanel.addComponentListener(this); 221 221 222 if ( WayPointHelper.getGeoidKind() == GeoidCorrectionKind.Auto) {222 if (ElevationHelper.getGeoidKind() == GeoidCorrectionKind.Auto) { 223 223 geoidAuto.setSelected(true); 224 224 } 225 if ( WayPointHelper.getGeoidKind() == GeoidCorrectionKind.Fixed) {225 if (ElevationHelper.getGeoidKind() == GeoidCorrectionKind.Fixed) { 226 226 geoidFixed.setSelected(true); 227 227 } … … 301 301 // Show elevation data 302 302 minHeightLabel.setText( 303 WayPointHelper.getElevationText(profile.getMinHeight()));303 ElevationHelper.getElevationText(profile.getMinHeight())); 304 304 maxHeightLabel.setText( 305 WayPointHelper.getElevationText(profile.getMaxHeight()));305 ElevationHelper.getElevationText(profile.getMaxHeight())); 306 306 avrgHeightLabel.setText( 307 WayPointHelper.getElevationText(profile.getAverageHeight()));307 ElevationHelper.getElevationText(profile.getAverageHeight())); 308 308 elevationGainLabel.setText( 309 WayPointHelper.getElevationText(profile.getGain()));309 ElevationHelper.getElevationText(profile.getGain())); 310 310 } 311 311 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java
r29876 r29907 29 29 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 30 30 import org.openstreetmap.josm.gui.layer.Layer; 31 import org.openstreetmap.josm.plugins.elevation.ElevationWayPointKind;32 31 import org.openstreetmap.josm.plugins.elevation.IElevationProfile; 33 import org.openstreetmap.josm.plugins.elevation.WayPointHelper; 32 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 33 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; 34 34 import org.openstreetmap.josm.tools.ImageProvider; 35 35 … … 173 173 174 174 // remember some things for next iteration 175 lastEle = (int) WayPointHelper.getElevation(wpt);175 lastEle = (int) ElevationHelper.getElevation(wpt); 176 176 lastWpt = wpt; 177 177 } … … 212 212 private ElevationWayPointKind classifyWayPoint(WayPoint lastWpt, WayPoint actWpt) { 213 213 // get elevation values 214 int actEle = (int) WayPointHelper.getElevation(actWpt);215 int lastEle = (int) WayPointHelper.getElevation(lastWpt);214 int actEle = (int) ElevationHelper.getElevation(actWpt); 215 int lastEle = (int) ElevationHelper.getElevation(lastWpt); 216 216 217 217 // normalize elevation to levels 218 218 int actLevel = (int)(actEle / Level_Factor); 219 219 int lastLevel = (int)(lastEle / Level_Factor); 220 double slope = Math.abs( WayPointHelper.computeSlope(lastWpt, actWpt));220 double slope = Math.abs(ElevationHelper.computeSlope(lastWpt.getCoor(), actWpt.getCoor())); 221 221 222 222 // plain way point by default -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java
r23976 r29907 37 37 38 38 import org.openstreetmap.josm.data.gpx.WayPoint; 39 import org.openstreetmap.josm.plugins.elevation.ElevationWayPointKind;40 39 import org.openstreetmap.josm.plugins.elevation.IElevationProfile; 41 import org.openstreetmap.josm.plugins.elevation.WayPointHelper; 40 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 41 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; 42 42 43 43 /** … … 289 289 // check bounds 290 290 if (yLine <= getPlotBottom() && yLine >= getPlotTop()) { 291 String txt = WayPointHelper.getElevationText(i);291 String txt = ElevationHelper.getElevationText(i); 292 292 293 293 Rectangle r = drawAlignedString(txt, getPlotHCenter(), yLine - 2, … … 399 399 for (int i = 0; i < n; i++) { 400 400 WayPoint wpt = profile.getWayPoints().get(i); 401 int eleVal = (int) WayPointHelper.getElevation(wpt);401 int eleVal = (int) ElevationHelper.getElevation(wpt); 402 402 Color c = renderer.getColorForWaypoint(profile, wpt, 403 403 ElevationWayPointKind.Plain); … … 405 405 if (i == this.selectedIndex) { 406 406 g.setColor(Color.BLACK); 407 drawAlignedString( WayPointHelper.getElevationText(eleVal),407 drawAlignedString(ElevationHelper.getElevationText(eleVal), 408 408 (getPlotRight() + getPlotLeft()) / 2, 409 409 getPlotBottom() + 6, … … 420 420 421 421 int geoidVal = 0; 422 switch( WayPointHelper.getGeoidKind()) {423 case Auto: geoidVal = WayPointHelper.getGeoidCorrection(wpt); break;422 switch(ElevationHelper.getGeoidKind()) { 423 case Auto: geoidVal = ElevationHelper.getGeoidCorrection(wpt); break; 424 424 case Fixed: // not impl 425 425 } … … 532 532 WayPoint wpt = getSelectedWayPoint(); 533 533 if (wpt != null) { 534 return String.format("%s: %s", WayPointHelper.getTimeText(wpt), WayPointHelper.getElevationText(wpt));534 return String.format("%s: %s", ElevationHelper.getTimeText(wpt), ElevationHelper.getElevationText(wpt)); 535 535 } 536 536 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/IElevationProfileRenderer.java
r23795 r29907 20 20 import org.openstreetmap.josm.data.gpx.WayPoint; 21 21 import org.openstreetmap.josm.gui.MapView; 22 import org.openstreetmap.josm.plugins.elevation.ElevationWayPointKind;23 22 import org.openstreetmap.josm.plugins.elevation.IElevationProfile; 23 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; 24 24 25 25 /**
Note:
See TracChangeset
for help on using the changeset viewer.