Changeset 29907 in osm


Ignore:
Timestamp:
2013-09-01T21:54:35+02:00 (11 years ago)
Author:
oliverw
Message:

Begun elevation grid layer (see #1729).

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  
    1616
    1717import org.openstreetmap.josm.Main;
     18import org.openstreetmap.josm.actions.JosmAction;
    1819import org.openstreetmap.josm.gui.IconToggleButton;
     20import org.openstreetmap.josm.gui.MainMenu;
    1921import org.openstreetmap.josm.gui.MapFrame;
    2022import org.openstreetmap.josm.plugins.Plugin;
    2123import org.openstreetmap.josm.plugins.PluginInformation;
     24import org.openstreetmap.josm.plugins.elevation.actions.AddElevationLayerAction;
    2225import org.openstreetmap.josm.plugins.elevation.gui.ElevationProfileDialog;
    2326import org.openstreetmap.josm.plugins.elevation.gui.ElevationProfileLayer;
     27import static org.openstreetmap.josm.tools.I18n.tr;
    2428
    2529/**
     
    4448            eleMode = new ElevationMapMode("Elevation profile", Main.map);
    4549            eleModeButton = new IconToggleButton(eleMode);
     50           
     51            JosmAction action = new AddElevationLayerAction();
     52           
     53            MainMenu.add(Main.main.menu.viewMenu, action, false, 0);
     54           
    4655        } catch (Exception e1) {
    4756            System.err.println("Init of ElevationProfilePlugin failed: " + e1);
    4857            e1.printStackTrace();
    4958        }
    50        
    51         getPluginDir();
    5259    }
    5360
     
    7784    public static ElevationProfileLayer getCurrentLayer(){
    7885        if(currentLayer == null){
    79             currentLayer = new ElevationProfileLayer("Elevation profile");
     86            currentLayer = new ElevationProfileLayer(tr("Elevation Profile"));
    8087            Main.main.addLayer(currentLayer);                   
    8188        }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java

    r29877 r29907  
    4848                        File f = new File(fullPath);
    4949                        if (f.exists()) {
    50                             // nope: read HGT file...
     50                            // found something: read HGT file...
    5151                            ShortBuffer data = readHgtFile(fullPath);
     52                            System.out.println("Read SRTM data from " + fullPath + ", tag is '" + file + "'");
    5253                            // ... and store result in cache
    5354                            cache.put(file, data);
     
    5556                        }
    5657                }
    57             }
     58            }
     59           
     60            System.out.println("Get elevation from HGT file " + file);
    5861           
    5962            // read elevation value
    6063            return readElevation(coor);
    6164        } catch (FileNotFoundException e) {
     65            System.err.println("Get elevation from HGT " + coor + " failed: => " + e.getMessage());
    6266            // no problem... file not there
    63             return Double.NaN;
     67            return ElevationHelper.NO_ELEVATION;
    6468        } catch (Exception ioe) {
    6569            // oops...
    66             ioe.printStackTrace();         
     70            ioe.printStackTrace(System.err);       
    6771            // fallback
    68             return Double.NaN;     
     72            return ElevationHelper.NO_ELEVATION;           
    6973        }
    7074    }
     
    107111       
    108112        if (sb == null) {
    109             return Double.NaN;
     113            System.out.println("readElevation: Buffer is null for tag '" + tag + "'");
     114            return ElevationHelper.NO_ELEVATION;
    110115        }
    111116       
     
    120125        row = HGT_ROW_LENGTH - row;
    121126        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());
    122129
    123130        // valid position in buffer?
    124131        if (cell < sb.limit()) {
    125132            short ele = sb.get(cell);
     133            //System.out.println("==> Read SRTM elevation data from row/col/cell " + row + "," + col + ", " + cell + " = " + ele);
    126134            // check for data voids
    127135            if (ele == HGT_VOID) {
    128                 return Double.NaN;
     136                return ElevationHelper.NO_ELEVATION;
    129137            } else {
    130138                return ele;
    131139            }
    132140        } else {
    133             return Double.NaN;
     141            return ElevationHelper.NO_ELEVATION;
    134142        }
    135143    }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IElevationModelListener.java

    r23795 r29907  
    1515package org.openstreetmap.josm.plugins.elevation;
    1616
     17import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel;
     18
    1719/**
    1820 * 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  
    3232import org.openstreetmap.josm.data.gpx.WayPoint;
    3333import org.openstreetmap.josm.gui.MapView;
    34 import org.openstreetmap.josm.plugins.elevation.ElevationWayPointKind;
    3534import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    36 import org.openstreetmap.josm.plugins.elevation.WayPointHelper;
     35import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     36import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
    3737import org.openstreetmap.josm.tools.CheckParameterUtil;
    3838
     
    8888                }
    8989
    90                 int z = (int) WayPointHelper.getElevation(wpt);
     90                int z = (int) ElevationHelper.getElevation(wpt);
    9191
    9292                switch (kind) {
     
    192192
    193193                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;
    195195               
    196196                int rad = REGULAR_WPT_RADIUS;
     
    200200                /* Paint full hour label */
    201201                if (kind == ElevationWayPointKind.FullHour) {
    202                         int hour = WayPointHelper.getHourOfWayPoint(wpt);
     202                        int hour = ElevationHelper.getHourOfWayPoint(wpt);
    203203                        drawLabel(String.format("%02d:00", hour), pnt.x, pnt.y
    204204                                        + g.getFontMetrics().getHeight(), g);
     
    207207                /* Paint label for elevation levels */
    208208                if (kind == ElevationWayPointKind.ElevationLevelGain) {
    209                         drawLabelWithTriangle(WayPointHelper.getElevationText(ele), pnt.x, pnt.y
     209                        drawLabelWithTriangle(ElevationHelper.getElevationText(ele), pnt.x, pnt.y
    210210                                        + g.getFontMetrics().getHeight(), g, c, 8,
    211211                                        getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationGainHigh),
     
    214214               
    215215                if (kind == ElevationWayPointKind.ElevationLevelLoss) {
    216                         drawLabelWithTriangle(WayPointHelper.getElevationText(ele),
     216                        drawLabelWithTriangle(ElevationHelper.getElevationText(ele),
    217217                                        pnt.x, pnt.y+ g.getFontMetrics().getHeight(), g, c, 8,
    218218                                        getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationLossHigh),
     
    223223                if (kind == ElevationWayPointKind.Highlighted) {
    224224                        drawSphere(g, Color.WHITE, c, pnt.x, pnt.y, BIG_WPT_RADIUS);
    225                         drawLabel(WayPointHelper.getTimeText(wpt), pnt.x, pnt.y
     225                        drawLabel(ElevationHelper.getTimeText(wpt), pnt.x, pnt.y
    226226                                        - g.getFontMetrics().getHeight() - 5, g);
    227                         drawLabel(WayPointHelper.getElevationText(wpt), pnt.x, pnt.y
     227                        drawLabel(ElevationHelper.getElevationText(wpt), pnt.x, pnt.y
    228228                                        + g.getFontMetrics().getHeight() + 5, g);
    229229                }
     
    248248
    249249                Color c = getColorForWaypoint(profile, wpt, kind);
    250                 int eleH = (int) WayPointHelper.getElevation(wpt);
     250                int eleH = (int) ElevationHelper.getElevation(wpt);
    251251                Point pnt = mv.getPoint(wpt.getEastNorth());
    252252
     
    273273                                DefaultElevationProfileRenderer.TRIANGLE_BASESIZE);
    274274
    275                 drawLabel(WayPointHelper.getElevationText(eleH), pnt.x, pnt.y
     275                drawLabel(ElevationHelper.getElevationText(eleH), pnt.x, pnt.y
    276276                                + g.getFontMetrics().getHeight(), g, c);
    277277        }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationColors.java

    r23795 r29907  
    1717import java.awt.Color;
    1818
     19import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     20
    1921/**
    2022 * Contains some extra predefined colors.
     
    3032        public static Color EPLightBeige = new Color(235, 235, 215);
    3133        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        }
    32113}
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java

    r26941 r29907  
    4040import org.openstreetmap.josm.gui.layer.GpxLayer;
    4141import org.openstreetmap.josm.gui.layer.Layer;
    42 import org.openstreetmap.josm.plugins.elevation.ElevationModel;
    43 import org.openstreetmap.josm.plugins.elevation.GeoidCorrectionKind;
    4442import org.openstreetmap.josm.plugins.elevation.IElevationModelListener;
    45 import org.openstreetmap.josm.plugins.elevation.WayPointHelper;
     43import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     44import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel;
     45import org.openstreetmap.josm.plugins.elevation.gpx.GeoidCorrectionKind;
    4646import org.openstreetmap.josm.tools.Shortcut;
    4747
     
    170170                geoidNone.addActionListener(new ActionListener() {
    171171                        public void actionPerformed(ActionEvent arg0) {
    172                                 WayPointHelper.setGeoidKind(GeoidCorrectionKind.None);
     172                                ElevationHelper.setGeoidKind(GeoidCorrectionKind.None);
    173173                                geoidFixedValue.setEnabled(false);
    174174                                getModel().updateElevationData();
     
    180180                geoidAuto.addActionListener(new ActionListener() {
    181181                        public void actionPerformed(ActionEvent arg0) {
    182                                 WayPointHelper.setGeoidKind(GeoidCorrectionKind.Auto);
     182                                ElevationHelper.setGeoidKind(GeoidCorrectionKind.Auto);
    183183                                geoidFixedValue.setEnabled(false);
    184184                                getModel().updateElevationData();
     
    191191                geoidFixed.addActionListener(new ActionListener() {
    192192                        public void actionPerformed(ActionEvent arg0) {
    193                                 WayPointHelper.setGeoidKind(GeoidCorrectionKind.Fixed);
     193                                ElevationHelper.setGeoidKind(GeoidCorrectionKind.Fixed);
    194194                                geoidFixedValue.setEnabled(true);
    195195                                getModel().updateElevationData();
     
    220220                profPanel.addComponentListener(this);
    221221
    222                 if (WayPointHelper.getGeoidKind() == GeoidCorrectionKind.Auto) {
     222                if (ElevationHelper.getGeoidKind() == GeoidCorrectionKind.Auto) {
    223223                        geoidAuto.setSelected(true);
    224224                }
    225                 if (WayPointHelper.getGeoidKind() == GeoidCorrectionKind.Fixed) {
     225                if (ElevationHelper.getGeoidKind() == GeoidCorrectionKind.Fixed) {
    226226                        geoidFixed.setSelected(true);
    227227                }
     
    301301                                // Show elevation data
    302302                                minHeightLabel.setText(
    303                                                 WayPointHelper.getElevationText(profile.getMinHeight()));
     303                                                ElevationHelper.getElevationText(profile.getMinHeight()));
    304304                                maxHeightLabel.setText(
    305                                                 WayPointHelper.getElevationText(profile.getMaxHeight()));
     305                                                ElevationHelper.getElevationText(profile.getMaxHeight()));
    306306                                avrgHeightLabel.setText(
    307                                                 WayPointHelper.getElevationText(profile.getAverageHeight()));
     307                                                ElevationHelper.getElevationText(profile.getAverageHeight()));
    308308                                elevationGainLabel.setText(
    309                                                 WayPointHelper.getElevationText(profile.getGain()));
     309                                                ElevationHelper.getElevationText(profile.getGain()));
    310310                        }
    311311                       
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java

    r29876 r29907  
    2929import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    3030import org.openstreetmap.josm.gui.layer.Layer;
    31 import org.openstreetmap.josm.plugins.elevation.ElevationWayPointKind;
    3231import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    33 import org.openstreetmap.josm.plugins.elevation.WayPointHelper;
     32import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     33import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
    3434import org.openstreetmap.josm.tools.ImageProvider;
    3535
     
    173173
    174174                // remember some things for next iteration
    175                 lastEle = (int) WayPointHelper.getElevation(wpt);
     175                lastEle = (int) ElevationHelper.getElevation(wpt);
    176176                lastWpt = wpt;
    177177            }
     
    212212    private ElevationWayPointKind classifyWayPoint(WayPoint lastWpt, WayPoint actWpt) {
    213213        // 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);
    216216       
    217217        // normalize elevation to levels
    218218        int actLevel = (int)(actEle / Level_Factor);
    219219        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()));
    221221
    222222        // plain way point by default
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java

    r23976 r29907  
    3737
    3838import org.openstreetmap.josm.data.gpx.WayPoint;
    39 import org.openstreetmap.josm.plugins.elevation.ElevationWayPointKind;
    4039import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    41 import org.openstreetmap.josm.plugins.elevation.WayPointHelper;
     40import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     41import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
    4242
    4343/**
     
    289289                        // check bounds
    290290                        if (yLine <= getPlotBottom() && yLine >= getPlotTop()) {
    291                                 String txt = WayPointHelper.getElevationText(i);
     291                                String txt = ElevationHelper.getElevationText(i);
    292292                               
    293293                                Rectangle r = drawAlignedString(txt, getPlotHCenter(), yLine - 2,
     
    399399                for (int i = 0; i < n; i++) {
    400400                        WayPoint wpt = profile.getWayPoints().get(i);
    401                         int eleVal = (int) WayPointHelper.getElevation(wpt);
     401                        int eleVal = (int) ElevationHelper.getElevation(wpt);
    402402                        Color c = renderer.getColorForWaypoint(profile, wpt,
    403403                                        ElevationWayPointKind.Plain);
     
    405405                        if (i == this.selectedIndex) {
    406406                                g.setColor(Color.BLACK);
    407                                 drawAlignedString(WayPointHelper.getElevationText(eleVal),
     407                                drawAlignedString(ElevationHelper.getElevationText(eleVal),
    408408                                                (getPlotRight() + getPlotLeft()) / 2,
    409409                                                getPlotBottom() + 6,
     
    420420                       
    421421                        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;
    424424                                case Fixed: // not impl
    425425                        }
     
    532532                WayPoint wpt = getSelectedWayPoint();
    533533                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));
    535535                }
    536536               
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/IElevationProfileRenderer.java

    r23795 r29907  
    2020import org.openstreetmap.josm.data.gpx.WayPoint;
    2121import org.openstreetmap.josm.gui.MapView;
    22 import org.openstreetmap.josm.plugins.elevation.ElevationWayPointKind;
    2322import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
     23import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
    2424
    2525/**
Note: See TracChangeset for help on using the changeset viewer.