Changeset 9558 in josm


Ignore:
Timestamp:
2016-01-21T16:46:00+01:00 (4 years ago)
Author:
bastiK
Message:

always normalize longitude before projection and after inverse projection (see #12186)

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/data_nodist/projection/projection-regression-test-data

    r9549 r9558  
    62446244  ll  49.23525189671949 -54.40128360306443
    62456245  en  -4263130.034442673 2917092.5518731494
    6246   ll2 50156.3548390288 246510.82413196223
     6246  ll2 50156.3548390288 -89.17586803776794
    62476247EPSG:3060
    62486248  ll  -1.1011308836770013 155.39223808455847
     
    85648564  ll  35.30468974675124 -181.75048187801644
    85658565  en  67958.20646357589 3917197.8125596363
    8566   ll2 35.30468974617765 -181.75048187860764
     8566  ll2 35.30468974617765 178.24951812139236
    85678567EPSG:32602
    85688568  ll  -0.35895685791257925 -175.75420623162898
     
    91249124  ll  -36.29211488935783 181.82910716731914
    91259125  en  933779.944968744 5972815.905636139
    9126   ll2 -36.29211488867873 181.82910716792168
     9126  ll2 -36.29211488867873 -178.17089283207832
    91279127EPSG:32761
    91289128  ll  -38.055794555690284 -128.52440162080111
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r9419 r9558  
    102102
    103103    /**
     104     * Make sure longitude value is within <code>[-180, 180]</code> range.
     105     * @param lon the longitude in degrees
     106     * @return lon plus/minus multiples of <code>360</code>, as needed to get
     107     * in <code>[-180, 180]</code> range
     108     */
     109    public static double normalizeLon(double lon) {
     110        if (lon >= -180 && lon <= 180)
     111            return lon;
     112        else {
     113            lon = lon % 360.0;
     114            if (lon > 180) {
     115                return lon - 360;
     116            } else if (lon < -180) {
     117                return lon + 360;
     118            }
     119            return lon;
     120        }
     121    }
     122
     123    /**
    104124     * Replies true if lat is in the range [-90,90] and lon is in the range [-180,180]
    105125     *
  • trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java

    r9135 r9558  
    7171    public EastNorth latlon2eastNorth(LatLon ll) {
    7272        ll = datum.fromWGS84(ll);
    73         double[] en = proj.project(Math.toRadians(ll.lat()), Math.toRadians(ll.lon() - lon0 - pm));
     73        double[] en = proj.project(Math.toRadians(ll.lat()), Math.toRadians(LatLon.normalizeLon(ll.lon() - lon0 - pm)));
    7474        return new EastNorth(ellps.a * k0 * en[0] + x0, ellps.a * k0 * en[1] + y0);
    7575    }
     
    7878    public LatLon eastNorth2latlon(EastNorth en) {
    7979        double[] latlon_rad = proj.invproject((en.east() - x0) / ellps.a / k0, (en.north() - y0) / ellps.a / k0);
    80         LatLon ll = new LatLon(Math.toDegrees(latlon_rad[0]), Math.toDegrees(latlon_rad[1]) + lon0 + pm);
     80        LatLon ll = new LatLon(Math.toDegrees(latlon_rad[0]), LatLon.normalizeLon(Math.toDegrees(latlon_rad[1]) + lon0 + pm));
    8181        return datum.toWGS84(ll);
    8282    }
  • trunk/src/org/openstreetmap/josm/data/projection/proj/AbstractProj.java

    r9535 r9558  
    137137    }
    138138
    139     /**
    140      * Make sure longitude value is within <code>[-PI, PI]</code> range.
    141      * @param lon the longitude in radians
    142      * @return lon plus/minus multiples of <code>2*PI</code>, as needed to get
    143      * in <code>[-PI, PI]</code> range
    144      */
    145     public static double normalizeLon(double lon) {
    146         if (lon >= -Math.PI && lon <= Math.PI)
    147             return lon;
    148         else {
    149             lon = lon % (2 * Math.PI);
    150             if (lon > Math.PI) {
    151                 return lon - 2 * Math.PI;
    152             } else if (lon < -Math.PI) {
    153                 return lon + 2 * Math.PI;
    154             }
    155             return lon;
    156         }
    157     }
    158 
    159139    // Iteratively solve equation (7-9) from Snyder.
    160140    final double cphi2(final double ts) {
  • trunk/src/org/openstreetmap/josm/data/projection/proj/AlbersEqualArea.java

    r9549 r9558  
    129129    @Override
    130130    public double[] project(double y, double x) {
    131         x = normalizeLon(x);
    132131        x *= n;
    133132        double rho = c - n * qsfn(Math.sin(y));
  • trunk/src/org/openstreetmap/josm/data/projection/proj/LambertConformalConic.java

    r9243 r9558  
    159159    @Override
    160160    public double[] project(double phi, double lambda) {
    161         lambda = normalizeLon(lambda);
    162161        double sinphi = sin(phi);
    163162        double l = (0.5*log((1+sinphi)/(1-sinphi))) - e/2*log((1+e*sinphi)/(1-e*sinphi));
  • trunk/src/org/openstreetmap/josm/data/projection/proj/ObliqueMercator.java

    r9545 r9558  
    288288                lon2 += 2.0 * Math.PI;
    289289            }
    290             centralMeridian = normalizeLon(0.5 * (lon1 + lon2) -
     290            centralMeridian = normalizeLonRad(0.5 * (lon1 + lon2) -
    291291                     Math.atan(J * Math.tan(0.5 * B * (lon1 - lon2)) / P) / B);
    292             gamma0 = Math.atan(2.0 * Math.sin(B * normalizeLon(lon1 - centralMeridian)) /
     292            gamma0 = Math.atan(2.0 * Math.sin(B * normalizeLonRad(lon1 - centralMeridian)) /
    293293                     (Fp - 1.0 / Fp));
    294294            azimuth = Math.asin(D * Math.sin(gamma0));
     
    359359    }
    360360
     361    private double normalizeLonRad(double a) {
     362        return Math.toRadians(LatLon.normalizeLon(Math.toDegrees(a)));
     363    }
     364
    361365    @Override
    362366    public double[] project(double y, double x) {
    363         x = normalizeLon(x);
    364367        double u, v;
    365368        if (Math.abs(Math.abs(y) - Math.PI/2.0) > EPSILON) {
  • trunk/src/org/openstreetmap/josm/data/projection/proj/TransverseMercator.java

    r9139 r9558  
    126126    @Override
    127127    public double[] project(double y, double x) {
    128         x = normalizeLon(x);
    129128        double sinphi = Math.sin(y);
    130129        double cosphi = Math.cos(y);
Note: See TracChangeset for help on using the changeset viewer.