Ignore:
Timestamp:
2013-05-10T04:44:12+02:00 (11 years ago)
Author:
donvip
Message:

[josm_measurement] fix #josm4849 - wrong area, somewhat inaccurate length (patch by Preferred)

File:
1 edited

Legend:

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

    r29531 r29578  
    143143        }
    144144    }
    145 
     145   
     146        /*
     147     * Use an equal area sinusoidal projection to improve accuracy and so we can still use normal polygon area calculation
     148     * http://stackoverflow.com/questions/4681737/how-to-calculate-the-area-of-a-polygon-on-the-earths-surface-using-python
     149     */
    146150    public static double calcX(LatLon p1){
    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 = lat1;
    153         lon2 = 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     }
     151        return p1.lat() * Math.PI * 6367000 / 180;
     152        }
    162153
    163154    public static double calcY(LatLon p1){
    164         double lat1, lon1, lat2, lon2;
    165         double dlon, dlat;
    166 
    167         lat1 = p1.lat() * Math.PI / 180.0;
    168         lon1 = p1.lon() * Math.PI / 180.0;
    169         lat2 = 0;
    170         lon2 = lon1;
    171 
    172         dlon = lon2 - lon1;
    173         dlat = lat2 - lat1;
    174 
    175         double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2));
    176         double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    177         return 6367000 * c;
     155        return p1.lon() * ( Math.PI * 6367000 / 180) * Math.cos(p1.lat() * Math.PI / 180);
    178156    }
    179157
Note: See TracChangeset for help on using the changeset viewer.