Ignore:
Timestamp:
2015-06-19T21:45:15+02:00 (9 years ago)
Author:
simon04
Message:

JOSM/measurement: compute and display selection radius (patch by willytiengo)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java

    r30737 r31285  
    7070
    7171    /**
     72     * The measurement label for radius if the currently selected loop is a circle.
     73     */
     74    protected JLabel selectRadiusLabel;
     75
     76    /**
    7277     * The measurement label for the segment angle, actually updated, if 2 nodes are selected
    7378     */
     
    119124        valuePanel.add(selectAreaLabel);
    120125
     126        valuePanel.add(new JLabel(tr("Selection Radius")));
     127
     128        selectRadiusLabel = new JLabel(getRadiusText(0));
     129        valuePanel.add(selectRadiusLabel);
     130
    121131        JLabel angle = new JLabel(tr("Angle"));
    122132        angle.setToolTipText(tr("Angle between two selected Nodes"));
     
    142152    protected String getAreaText(double v) {
    143153        return NavigatableComponent.getSystemOfMeasurement().getAreaText(v, new DecimalFormat("#0.000"), 1e-3);
     154    }
     155
     156    protected String getRadiusText(double v) {
     157        return NavigatableComponent.getSystemOfMeasurement().getDistText(v, new DecimalFormat("#0.000"), 1e-3);
    144158    }
    145159
     
    160174        double segAngle = 0.0;
    161175        double area = 0.0;
     176        double radius = 0.0;
    162177        Node lastNode = null;
    163178        // Don't mix up way and nodes computation (fix #6872). Priority given to ways
     
    181196                Node lastN = null;
    182197                double wayArea = 0.0;
     198                Double firstSegLength = null;
     199                boolean isCircle = true;
    183200                for (Node n: w.getNodes()) {
    184201                    if (lastN != null && lastN.getCoor() != null && n.getCoor() != null) {
    185                         length += lastN.getCoor().greatCircleDistance(n.getCoor());
     202                        final double segLength = lastN.getCoor().greatCircleDistance(n.getCoor());
     203                        if (firstSegLength == null) {
     204                            firstSegLength = segLength;
     205                        }
     206                        if (isCircle && Math.abs(firstSegLength - segLength) > 0.000001) {
     207                            isCircle = false;
     208                        }
     209                        length += segLength;
    186210                        //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/
    187211                        wayArea += (MeasurementLayer.calcX(n.getCoor()) * MeasurementLayer.calcY(lastN.getCoor()))
     
    197221                area += wayArea;
    198222            }
     223            if (ways.size() == 1 && area > 0.0) {
     224                radius = length / (2 * Math.PI);
     225            }
    199226        }
    200227
     
    202229        final String angleLabel = getAngleText(segAngle);
    203230        final String areaLabel = getAreaText(area);
     231        final String radiusLabel = getRadiusText(radius);
    204232
    205233        GuiHelper.runInEDT(new Runnable() {
     
    209237                segAngleLabel.setText(angleLabel);
    210238                selectAreaLabel.setText(areaLabel);
     239                selectRadiusLabel.setText(radiusLabel);
    211240            }
    212241        });
Note: See TracChangeset for help on using the changeset viewer.