Ignore:
Timestamp:
2011-01-25T11:13:50+01:00 (14 years ago)
Author:
upliner
Message:

measurement plugin: use LatLon.greatCircleDistance() instead of plugin's distance function

Location:
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement
Files:
2 edited

Legend:

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

    r21307 r25137  
    104104        final MeasurementDialog dlg = this;
    105105
    106         DataSet.selListeners.add(new SelectionChangedListener() {
     106        DataSet.addSelectionListener(new SelectionChangedListener() {
     107            @Override
    107108            public void selectionChanged(Collection<? extends OsmPrimitive> arg0) {
    108109                double length = 0.0;
     
    117118                            lastNode = n;
    118119                        } else {
    119                             length += MeasurementLayer.calcDistance(lastNode.getCoor(), n.getCoor());
     120                            length += lastNode.getCoor().greatCircleDistance(n.getCoor());
    120121                            segAngle = MeasurementLayer.angleBetween(lastNode.getCoor(), n.getCoor());
    121122                            lastNode = n;
     
    126127                        for(Node n: w.getNodes()) {
    127128                            if(lastN != null) {
    128                                 length += MeasurementLayer.calcDistance(lastN.getCoor(), n.getCoor());
     129                                length += lastN.getCoor().greatCircleDistance(n.getCoor());
    129130                                //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/
    130131                                area += (MeasurementLayer.calcX(n.getCoor()) * MeasurementLayer.calcY(lastN.getCoor()))
     
    148149    }
    149150
     151    @Override
    150152    public void actionPerformed(ActionEvent e)
    151153    {
  • applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java

    r22547 r25137  
    144144    }
    145145
    146     public static double calcDistance(LatLon p1, LatLon p2){
    147         double lat1, lon1, lat2, lon2;
    148         double dlon, dlat;
    149 
    150         lat1 = p1.lat() * Math.PI / 180.0;
    151         lon1 = p1.lon() * Math.PI / 180.0;
    152         lat2 = p2.lat() * Math.PI / 180.0;
    153         lon2 = p2.lon() * Math.PI / 180.0;
    154 
    155         dlon = lon2 - lon1;
    156         dlat = lat2 - lat1;
    157 
    158         double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2));
    159         double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    160         return 6367000 * c;
    161     }
    162 
    163146    public static double calcX(LatLon p1){
    164147        double lat1, lon1, lat2, lon2;
     
    196179
    197180    public static double calcDistance(WayPoint p1, WayPoint p2){
    198         return calcDistance(p1.getCoor(), p2.getCoor());
     181        return p1.getCoor().greatCircleDistance(p2.getCoor());
    199182    }
    200183
     
    260243    }
    261244
     245    @Override
    262246    public void actionPerformed(ActionEvent e) {
    263247        Box panel = Box.createVerticalBox();
Note: See TracChangeset for help on using the changeset viewer.