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

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

Location:
trunk/src/org/openstreetmap/josm/data
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • 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.