Index: test/unit/org/openstreetmap/josm/data/projection/SwissGridTest.java
===================================================================
--- test/unit/org/openstreetmap/josm/data/projection/SwissGridTest.java	(révision 0)
+++ test/unit/org/openstreetmap/josm/data/projection/SwissGridTest.java	(révision 0)
@@ -0,0 +1,102 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.projection;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.coor.LatLon;
+
+public class SwissGridTest {
+    @BeforeClass
+    public static void setUp() {
+        Main.proj = new SwissGrid();
+    }
+
+    @Test
+    public void a_latlon2eastNorth_test() {
+        {
+            LatLon ll = new LatLon(46.518, 6.567);
+            EastNorth en = Main.proj.latlon2eastNorth(ll);
+            System.out.println(en);
+            assertTrue("Lausanne", Math.abs(en.east() - 533111.69) < 0.1);
+            assertTrue("Lausanne", Math.abs(en.north() - 152227.85) < 0.1);
+        }
+
+        {
+            LatLon ll = new LatLon(47.78, 8.58);
+            EastNorth en = Main.proj.latlon2eastNorth(ll);
+            System.out.println(en);
+            assertTrue("Schafouse", Math.abs(en.east() - 685544.16) < 0.1);
+            assertTrue("Schafouse", Math.abs(en.north() - 292782.91) < 0.1);
+        }
+
+        {
+            LatLon ll = new LatLon(46.58, 10.48);
+            EastNorth en = Main.proj.latlon2eastNorth(ll);
+            System.out.println(en);
+            assertTrue("Grinson", Math.abs(en.east() - 833068.04) < 0.1);
+            assertTrue("Grinson", Math.abs(en.north() - 163265.39) < 0.1);
+        }
+        {
+            LatLon ll = new LatLon(46.0 + 57.0 / 60 + 3.89813884505 / 3600, 7.0 + 26.0 / 60 + 19.076595154147 / 3600);
+            EastNorth en = Main.proj.latlon2eastNorth(ll);
+            System.out.println(en);
+            assertTrue("Berne", Math.abs(en.east() - 600000.0) < 0.1);
+            assertTrue("Berne", Math.abs(en.north() - 200000.0) < 0.1);
+        }
+        {
+            LatLon ll = new LatLon(46.044130, 8.730497);
+            EastNorth en = Main.proj.latlon2eastNorth(ll);
+            System.out.println(en);
+            assertTrue("Ref", Math.abs(en.east() - 700000.0) < 0.1);
+            assertTrue("Ref", Math.abs(en.north() - 100000.0) < 0.1);
+        }
+    }
+
+    @Test
+    public void b_eastNorth2latlon_test() {
+        {
+            EastNorth en = new EastNorth(533111.69, 152227.85);
+            LatLon ll = Main.proj.eastNorth2latlon(en);
+            System.out.println(ll);
+            assertTrue("Lausanne", Math.abs(ll.lat() - 46.518) < 0.00001);
+            assertTrue("Lausanne", Math.abs(ll.lon() - 6.567) < 0.00001);
+        }
+
+        {
+            EastNorth en = new EastNorth(685544.16, 292782.91);
+            LatLon ll = Main.proj.eastNorth2latlon(en);
+            System.out.println(ll);
+            assertTrue("Schafouse", Math.abs(ll.lat() - 47.78) < 0.00001);
+            assertTrue("Schafouse", Math.abs(ll.lon() - 8.58) < 0.00001);
+        }
+
+        {
+            EastNorth en = new EastNorth(833068.04, 163265.39);
+            LatLon ll = Main.proj.eastNorth2latlon(en);
+            System.out.println(ll);
+            assertTrue("Ref", Math.abs(ll.lat() - 46.58) < 0.00001);
+            assertTrue("Ref", Math.abs(ll.lon() -10.48) < 0.00001);
+        }
+
+        {
+            EastNorth en = new EastNorth(600000.0, 200000.0);
+            LatLon ll = Main.proj.eastNorth2latlon(en);
+            System.out.println(ll);
+            assertTrue("Berne", Math.abs(ll.lat() - (46.0 + 57.0 / 60 + 3.89813884505 / 3600)) < 0.00001);
+            assertTrue("Berne", Math.abs(ll.lon() - (7.0 + 26.0 / 60 + 19.076595154147 / 3600)) < 0.00001);
+        }
+        
+        {
+            EastNorth en = new EastNorth(700000.0, 100000.0);
+            LatLon ll = Main.proj.eastNorth2latlon(en);
+            System.out.println(ll);
+            assertTrue("Ref", Math.abs(ll.lat() - 46.044130) < 0.00001);
+            assertTrue("Ref", Math.abs(ll.lon() - 8.730497) < 0.00001);
+        }
+
+    }
+}
Index: src/org/openstreetmap/josm/data/projection/SwissGrid.java
===================================================================
--- src/org/openstreetmap/josm/data/projection/SwissGrid.java	(révision 3429)
+++ src/org/openstreetmap/josm/data/projection/SwissGrid.java	(copie de travail)
@@ -14,77 +14,196 @@
  * Calculations are based on formula from
  * http://www.swisstopo.admin.ch/internet/swisstopo/en/home/topics/survey/sys/refsys/switzerland.parsysrelated1.37696.downloadList.12749.DownloadFile.tmp/ch1903wgs84en.pdf
  *
+ * August 2010 update to this formula (rigorous formulas)
+ * http://www.swisstopo.admin.ch/internet/swisstopo/en/home/topics/survey/sys/refsys/switzerland.parsysrelated1.37696.downloadList.97912.DownloadFile.tmp/swissprojectionen.pdf
  */
 public class SwissGrid implements Projection {
+
+    public static void main(String[] args) {
+        SwissGrid proj = new SwissGrid();
+        {
+            EastNorth en = new EastNorth(700000.0, 100000.0);
+            LatLon ll = proj.eastNorth2latlon(en);
+            System.out.println(ll);
+        }
+        {
+            EastNorth en = new EastNorth(700000.1, 100000.1);
+            LatLon ll = proj.eastNorth2latlon(en);
+            System.out.println(ll);
+        }
+
+        {
+            LatLon ll = new LatLon(46.518, 6.567);
+            EastNorth en = proj.latlon2eastNorth(ll);
+            System.out.println(en);
+        }
+
+        {
+            LatLon ll = new LatLon(47.78, 8.58);
+            EastNorth en = proj.latlon2eastNorth(ll);
+            System.err.println(en);
+        }
+
+        {
+            LatLon ll = new LatLon(46.58, 10.48);
+            EastNorth en = proj.latlon2eastNorth(ll);
+            System.out.println(en);
+        }
+
+        {
+            LatLon ll = new LatLon(46.0 + 57.0 / 60 + 3.89813884505 / 3600, 7.0 + 26.0 / 60 + 19.076595154147 / 3600);
+            EastNorth en = proj.latlon2eastNorth(ll);
+            System.out.println(en);
+        }
+        {
+            LatLon ll = new LatLon(46.0 + 2.0 / 60 + 38.87 / 3600, 8.0 + 43.0 / 60 + 49.79 / 3600);
+            EastNorth en = proj.latlon2eastNorth(ll);
+            System.out.println(en);
+        }
+    }
+
+    private static final double dX = 674.374;
+    private static final double dY = 15.056;
+    private static final double dZ = 405.346;
+
+    private static final double wgs84_a = 6378137.000;
+    private static final double wgs84_b = 6356752.314245;
+    //    private static final double wgs84_f = (wgs84_a-wgs84_b)/wgs84_a;
+    private static final double wgs84_E2 = (Math.pow(wgs84_a, 2) - Math.pow(wgs84_b, 2)) / Math.pow(wgs84_a, 2);
+    //    private static final double wgs84_E = Math.sqrt(wgs84_E2);
+
+    private static final double a = 6377397.155;
+    private static final double b = 6356078.962822;
+    //    private static final double f = (a-b)/a;
+    private static final double E2 = (Math.pow(a, 2) - Math.pow(b, 2)) / Math.pow(a, 2);
+    private static final double E = Math.sqrt(E2);
+    private static final double phi0 = Math.toRadians(46.0 + 57.0 / 60 + 8.66 / 3600);
+    private static final double lambda0 = Math.toRadians(7.0 + 26.0 / 60 + 22.50 / 3600);
+    private static final double R = a * Math.sqrt(1 - E2) / (1 - (E2 * Math.pow(Math.sin(phi0), 2)));
+    private static final double alpha = Math.sqrt(1 + (E2 / (1 - E2) * Math.pow(Math.cos(phi0), 4)));
+    private static final double b0 = Math.asin(Math.sin(phi0) / alpha);
+    private static final double K = Math.log(Math.tan(Math.PI / 4 + b0 / 2)) - alpha
+            * Math.log(Math.tan(Math.PI / 4 + phi0 / 2)) + alpha * E / 2
+            * Math.log((1 + E * Math.sin(phi0)) / (1 - E * Math.sin(phi0)));
+
+    private static final double xTrans = 200000;
+    private static final double yTrans = 600000;
+
+    private LatLon correctETRS89toCH1903(LatLon coord) {
+        double phi = Math.toRadians(coord.lat());
+        double lambda = Math.toRadians(coord.lon());
+
+        double Rn = wgs84_a / Math.sqrt(1 - wgs84_E2 * Math.pow(Math.sin(phi), 2));
+        double X = Rn * Math.cos(phi) * Math.cos(lambda);
+        double Y = Rn * Math.cos(phi) * Math.sin(lambda);
+        double Z = Rn * (1 - wgs84_E2) * Math.sin(phi);
+        X -= dX;
+        Y -= dY;
+        Z -= dZ;
+        lambda = Math.atan2(Y, X);
+        double sX2Ys = Math.sqrt(X * X + Y * Y);
+        phi = Math.atan2(Z, sX2Ys);
+        double h = 0;
+        double prevPhi = -1000;
+        int iteration = 0;
+        while (Math.abs(phi - prevPhi) > 0.0000001) {
+            if (++iteration > 20) {
+                throw new RuntimeException("Two many iterations");
+            }
+            Rn = a / Math.sqrt(1 - E2 * Math.pow(Math.sin(phi), 2));
+            h = sX2Ys / Math.cos(phi) - Rn;
+            prevPhi = phi;
+            phi = Math.atan2(Z / sX2Ys, 1 - Rn * E2 / (Rn + h));
+        }
+
+        return new LatLon(Math.toDegrees(phi), Math.toDegrees(lambda));
+    }
+
+    private LatLon correctCH1903toETRS89(LatLon coord) {
+        double phi = Math.toRadians(coord.lat());
+        double lambda = Math.toRadians(coord.lon());
+
+        double Rn = a / Math.sqrt(1 - E2 * Math.pow(Math.sin(phi), 2));
+        double X = Rn * Math.cos(phi) * Math.cos(lambda);
+        double Y = Rn * Math.cos(phi) * Math.sin(lambda);
+        double Z = Rn * (1 - E2) * Math.sin(phi);
+        X += dX;
+        Y += dY;
+        Z += dZ;
+        lambda = Math.atan2(Y, X);
+        double sX2Ys = Math.sqrt(X * X + Y * Y);
+        phi = Math.atan((Z / sX2Ys));
+        double h = 0;
+
+        double prevPhi = -1000;
+        int iteration = 0;
+        while (Math.abs(phi - prevPhi) > 0.0000001) {
+            if (++iteration > 20) {
+                throw new RuntimeException("Two many iterations");
+            }
+            Rn = wgs84_a / Math.sqrt(1 - wgs84_E2 * Math.pow(Math.sin(phi), 2));
+            h = sX2Ys / Math.cos(phi) - Rn;
+            prevPhi = phi;
+            phi = Math.atan2(Z / sX2Ys, 1 - Rn * wgs84_E2 / (Rn + h));
+        }
+
+        return new LatLon(Math.toDegrees(phi), Math.toDegrees(lambda));
+    }
+
     /**
      * @param wgs  WGS84 lat/lon (ellipsoid GRS80) (in degree)
      * @return eastnorth projection in Swiss National Grid (ellipsoid Bessel)
      */
     public EastNorth latlon2eastNorth(LatLon wgs) {
-            double phi = 3600d * wgs.lat();
-            double lambda = 3600d * wgs.lon();
+        LatLon coord = correctETRS89toCH1903(wgs);
+        double phi = Math.toRadians(coord.lat());
+        double lambda = Math.toRadians(coord.lon());
 
-            double phiprime = (phi - 169028.66d) / 10000d;
-            double lambdaprime = (lambda - 26782.5d) / 10000d;
+        double S = alpha * Math.log(Math.tan(Math.PI / 4 + phi / 2)) - alpha * E / 2
+                * Math.log((1 + E * Math.sin(phi)) / (1 - E * Math.sin(phi))) + K;
+        double b = 2 * (Math.atan(Math.exp(S)) - Math.PI / 4);
+        double l = alpha * (lambda - lambda0);
 
-            // precompute squares for lambdaprime and phiprime
-            //
-            double lambdaprime_2 = Math.pow(lambdaprime,2);
-            double phiprime_2 = Math.pow(phiprime,2);
+        double lb = Math.atan2(Math.sin(l), Math.sin(b0) * Math.tan(b) + Math.cos(b0) * Math.cos(l));
+        double bb = Math.asin(Math.cos(b0) * Math.sin(b) - Math.sin(b0) * Math.cos(b) * Math.cos(l));
 
-            double north =
-                  200147.07d
-                + 308807.95d                           * phiprime
-                +   3745.25d    * lambdaprime_2
-                +     76.63d                           * phiprime_2
-                -    194.56d    * lambdaprime_2        * phiprime
-                +    119.79d                           * Math.pow(phiprime,3);
+        double y = R * lb;
+        double x = R / 2 * Math.log((1 + Math.sin(bb)) / (1 - Math.sin(bb)));
 
-            double east =
-                  600072.37d
-                + 211455.93d  * lambdaprime
-                - 10938.51d   * lambdaprime             * phiprime
-                - 0.36d       * lambdaprime             * phiprime_2
-                - 44.54d      * Math.pow(lambdaprime,3);
-
-            return new EastNorth(east, north);
+        return new EastNorth(y + yTrans, x + xTrans);
     }
 
     /**
      * @param xy SwissGrid east/north (in meters)
      * @return LatLon WGS84 (in degree)
      */
-
     public LatLon eastNorth2latlon(EastNorth xy) {
-        double yp = (xy.east() - 600000d) / 1000000d;
-        double xp = (xy.north() - 200000d) / 1000000d;
+        double x = xy.north() - xTrans;
+        double y = xy.east() - yTrans;
 
-        // precompute squares of xp and yp
-        //
-        double xp_2 = Math.pow(xp,2);
-        double yp_2 = Math.pow(yp,2);
+        double lb = y / R;
+        double bb = 2 * (Math.atan(Math.exp(x / R)) - Math.PI / 4);
 
-        // lambda = latitude, phi = longitude
-        double lmbp  =    2.6779094d
-                        + 4.728982d      * yp
-                        + 0.791484d      * yp               * xp
-                        + 0.1306d        * yp               * xp_2
-                        - 0.0436d        * Math.pow(yp,3);
+        double b = Math.asin(Math.cos(b0) * Math.sin(bb) + Math.sin(b0) * Math.cos(bb) * Math.cos(lb));
+        double l = Math.atan2(Math.sin(lb), Math.cos(b0) * Math.cos(lb) - Math.sin(b0) * Math.tan(bb));
 
-        double phip =     16.9023892d
-                        +  3.238272d                        * xp
-                        -  0.270978d    * yp_2
-                        -  0.002528d                        * xp_2
-                        -  0.0447d      * yp_2              * xp
-                        -  0.0140d                          * Math.pow(xp,3);
+        double lambda = lambda0 + l / alpha;
+        double phi = b;
+        double S = 0;
 
-        double lmb = lmbp * 100.0d / 36.0d;
-        double phi = phip * 100.0d / 36.0d;
+        // 5 iteration to fins S and phi
+        for (int i = 0; i < 6; i++) {
+            S = 1 / alpha * (Math.log(Math.tan(Math.PI / 4 + b / 2)) - K) + E
+                    * Math.log(Math.tan(Math.PI / 4 + Math.asin(E * Math.sin(phi)) / 2));
+            phi = 2 * Math.atan(Math.exp(S)) - Math.PI / 2;
+        }
 
-        return new LatLon(phi,lmb);
+        LatLon coord = new LatLon(Math.toDegrees(phi), Math.toDegrees(lambda));
+        return correctCH1903toETRS89(coord);
     }
 
-    @Override public String toString() {
+    @Override
+    public String toString() {
         return tr("Swiss Grid (Switzerland)");
     }
 
@@ -101,11 +220,8 @@
         return "swissgrid";
     }
 
-    public Bounds getWorldBoundsLatLon()
-    {
-        return new Bounds(
-                new LatLon(45.7, 5.7),
-                new LatLon(47.9, 10.6));
+    public Bounds getWorldBoundsLatLon() {
+        return new Bounds(new LatLon(45.7, 5.7), new LatLon(47.9, 10.6));
     }
 
     public double getDefaultZoomInPPD() {
