1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.projection;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertTrue;
|
---|
5 |
|
---|
6 | import org.junit.BeforeClass;
|
---|
7 | import org.junit.Test;
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
10 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
11 |
|
---|
12 | public class SwissGridTest {
|
---|
13 | @BeforeClass
|
---|
14 | public static void setUp() {
|
---|
15 | Main.proj = new SwissGrid();
|
---|
16 | }
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * source: http://www.swisstopo.admin.ch/internet/swisstopo/en/home/topics/survey/sys/refsys/switzerland.parsysrelated1.37696.downloadList.97912.DownloadFile.tmp/swissprojectionen.pdf
|
---|
20 | */
|
---|
21 | ProjData[] data = {
|
---|
22 | new ProjData("Zimmerwald", d(7,27,54.983506), d(46,52,37.540562), 947.149, 602030.680, 191775.030, 897.915),
|
---|
23 | new ProjData("Chrischona", d(7,40,6.983077), d(47,34, 1.385301), 504.935, 617306.300, 268507.300, 456.064),
|
---|
24 | new ProjData("Pfaender", d(9,47,3.697723), d(47,30,55.172797), 1089.372, 776668.105, 265372.681, 1042.624),
|
---|
25 | new ProjData("La Givrine", d(6,6,7.326361), d(46,27,14.690021), 1258.274, 497313.292, 145625.438, 1207.434),
|
---|
26 | new ProjData("Monte Generoso", d(9,1,16.389053), d(45,55,45.438020), 1685.027, 722758.810, 87649.670, 1636.600) };
|
---|
27 |
|
---|
28 | private double d(double deg, double min, double sec) {
|
---|
29 | return deg + min / 60. + sec / 3600.;
|
---|
30 | }
|
---|
31 |
|
---|
32 | private class ProjData {
|
---|
33 | public String name;
|
---|
34 | public LatLon ll;
|
---|
35 | public EastNorth en;
|
---|
36 | public ProjData(String name, double lon, double lat, double h1, double x, double y, double h2) {
|
---|
37 | this.name = name;
|
---|
38 | ll = new LatLon(lat, lon);
|
---|
39 | en = new EastNorth(x, y);
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Test
|
---|
44 | public void projReferenceTest() {
|
---|
45 | Projection swiss = new SwissGrid();
|
---|
46 | String errs = "";
|
---|
47 | for (ProjData pd : data) {
|
---|
48 | EastNorth en2 = swiss.latlon2eastNorth(pd.ll);
|
---|
49 | if (Math.abs(pd.en.east() - en2.east()) > 0.01 || Math.abs(pd.en.north() - en2.north()) > 0.01) {
|
---|
50 | errs += String.format("%s should be: %s but is: %s\n", pd.name, pd.en, en2);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | assertTrue(errs, errs.length() == 0);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Test
|
---|
57 | public void a_latlon2eastNorth_test() {
|
---|
58 | {
|
---|
59 | LatLon ll = new LatLon(46.518, 6.567);
|
---|
60 | EastNorth en = Main.proj.latlon2eastNorth(ll);
|
---|
61 | System.out.println(en);
|
---|
62 | assertTrue("Lausanne", Math.abs(en.east() - 533111.69) < 0.1);
|
---|
63 | assertTrue("Lausanne", Math.abs(en.north() - 152227.85) < 0.1);
|
---|
64 | }
|
---|
65 |
|
---|
66 | {
|
---|
67 | LatLon ll = new LatLon(47.78, 8.58);
|
---|
68 | EastNorth en = Main.proj.latlon2eastNorth(ll);
|
---|
69 | System.out.println(en);
|
---|
70 | assertTrue("Schafouse", Math.abs(en.east() - 685544.16) < 0.1);
|
---|
71 | assertTrue("Schafouse", Math.abs(en.north() - 292782.91) < 0.1);
|
---|
72 | }
|
---|
73 |
|
---|
74 | {
|
---|
75 | LatLon ll = new LatLon(46.58, 10.48);
|
---|
76 | EastNorth en = Main.proj.latlon2eastNorth(ll);
|
---|
77 | System.out.println(en);
|
---|
78 | assertTrue("Grinson", Math.abs(en.east() - 833068.04) < 0.1);
|
---|
79 | assertTrue("Grinson", Math.abs(en.north() - 163265.39) < 0.1);
|
---|
80 | }
|
---|
81 |
|
---|
82 | {
|
---|
83 | LatLon ll = new LatLon(46.0 + 57.0 / 60 + 3.89813884505 / 3600, 7.0 + 26.0 / 60 + 19.076595154147 / 3600);
|
---|
84 | EastNorth en = Main.proj.latlon2eastNorth(ll);
|
---|
85 | System.out.println(en);
|
---|
86 | assertTrue("Berne", Math.abs(en.east() - 600000.0) < 0.1);
|
---|
87 | assertTrue("Berne", Math.abs(en.north() - 200000.0) < 0.1);
|
---|
88 | }
|
---|
89 | {
|
---|
90 | LatLon ll = new LatLon(46.0 + 2.0 / 60 + 38.87 / 3600, 8.0 + 43.0 / 60 + 49.79 / 3600);
|
---|
91 | EastNorth en = Main.proj.latlon2eastNorth(ll);
|
---|
92 | System.out.println(en);
|
---|
93 | assertTrue("Ref", Math.abs(en.east() - 700000.0) < 0.1);
|
---|
94 | assertTrue("Ref", Math.abs(en.north() - 100000.0) < 0.1);
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | @Test
|
---|
100 | public void b_eastNorth2latlon_test() {
|
---|
101 | {
|
---|
102 | EastNorth en = new EastNorth(533111.69, 152227.85);
|
---|
103 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
104 | System.out.println(ll);
|
---|
105 | assertTrue("Lausanne", Math.abs(ll.lat() - 46.518) < 0.00001);
|
---|
106 | assertTrue("Lausanne", Math.abs(ll.lon() - 6.567) < 0.00001);
|
---|
107 | }
|
---|
108 |
|
---|
109 | {
|
---|
110 | EastNorth en = new EastNorth(685544.16, 292782.91);
|
---|
111 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
112 | System.out.println(ll);
|
---|
113 | assertTrue("Schafouse", Math.abs(ll.lat() - 47.78) < 0.00001);
|
---|
114 | assertTrue("Schafouse", Math.abs(ll.lon() - 8.58) < 0.00001);
|
---|
115 | }
|
---|
116 |
|
---|
117 | {
|
---|
118 | EastNorth en = new EastNorth(833068.04, 163265.39);
|
---|
119 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
120 | System.out.println(ll);
|
---|
121 | assertTrue("Grinson", Math.abs(ll.lat() - 46.58) < 0.00001);
|
---|
122 | assertTrue("Grinson", Math.abs(ll.lon() - 10.48) < 0.00001);
|
---|
123 | }
|
---|
124 |
|
---|
125 | {
|
---|
126 | EastNorth en = new EastNorth(600000.0, 200000.0);
|
---|
127 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
128 | System.out.println(ll);
|
---|
129 | assertTrue("Berne", Math.abs(ll.lat() - (46.0 + 57.0 / 60 + 3.89813884505 / 3600)) < 0.00001);
|
---|
130 | assertTrue("Berne", Math.abs(ll.lon() - (7.0 + 26.0 / 60 + 19.076595154147 / 3600)) < 0.00001);
|
---|
131 | }
|
---|
132 |
|
---|
133 | {
|
---|
134 | EastNorth en = new EastNorth(700000.0, 100000.0);
|
---|
135 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
136 | System.out.println(ll);
|
---|
137 | assertTrue("Ref", Math.abs(ll.lat() - 46.0 + 2.0 / 60 + 38.87 / 3600) < 0.00001);
|
---|
138 | assertTrue("Ref", Math.abs(ll.lon() - 8.0 + 43.0 / 60 + 49.79 / 3600) < 0.00001);
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Send and return should have less than 2mm of difference.
|
---|
145 | */
|
---|
146 | @Test
|
---|
147 | public void c_sendandreturn_test() {
|
---|
148 | {
|
---|
149 | EastNorth en = new EastNorth(533111.69, 152227.85);
|
---|
150 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
151 | EastNorth en2 = Main.proj.latlon2eastNorth(ll);
|
---|
152 | System.out.println(en.east() - en2.east());
|
---|
153 | System.out.println(en.north() - en2.north());
|
---|
154 | assertTrue("Lausanne", Math.abs(en.east() - en2.east()) < 0.002);
|
---|
155 | assertTrue("Lausanne", Math.abs(en.north() - en2.north()) < 0.002);
|
---|
156 | }
|
---|
157 |
|
---|
158 | {
|
---|
159 | EastNorth en = new EastNorth(685544.16, 292782.91);
|
---|
160 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
161 | EastNorth en2 = Main.proj.latlon2eastNorth(ll);
|
---|
162 | System.out.println(en.east() - en2.east());
|
---|
163 | System.out.println(en.north() - en2.north());
|
---|
164 | assertTrue("Schafouse", Math.abs(en.east() - en2.east()) < 0.002);
|
---|
165 | assertTrue("Schafouse", Math.abs(en.north() - en2.north()) < 0.002);
|
---|
166 | }
|
---|
167 |
|
---|
168 | {
|
---|
169 | EastNorth en = new EastNorth(833068.04, 163265.39);
|
---|
170 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
171 | EastNorth en2 = Main.proj.latlon2eastNorth(ll);
|
---|
172 | System.out.println(en.east() - en2.east());
|
---|
173 | System.out.println(en.north() - en2.north());
|
---|
174 | assertTrue("Grinson", Math.abs(en.east() - en2.east()) < 0.002);
|
---|
175 | assertTrue("Grinson", Math.abs(en.north() - en2.north()) < 0.002);
|
---|
176 | }
|
---|
177 |
|
---|
178 | {
|
---|
179 | EastNorth en = new EastNorth(600000.0, 200000.0);
|
---|
180 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
181 | EastNorth en2 = Main.proj.latlon2eastNorth(ll);
|
---|
182 | System.out.println(en.east() - en2.east());
|
---|
183 | System.out.println(en.north() - en2.north());
|
---|
184 | assertTrue("Berne", Math.abs(en.east() - en2.east()) < 0.002);
|
---|
185 | assertTrue("Berne", Math.abs(en.north() - en2.north()) < 0.002);
|
---|
186 | }
|
---|
187 |
|
---|
188 | {
|
---|
189 | EastNorth en = new EastNorth(700000.0, 100000.0);
|
---|
190 | LatLon ll = Main.proj.eastNorth2latlon(en);
|
---|
191 | EastNorth en2 = Main.proj.latlon2eastNorth(ll);
|
---|
192 | System.out.println(en.east() - en2.east());
|
---|
193 | System.out.println(en.north() - en2.north());
|
---|
194 | assertTrue("Ref", Math.abs(en.east() - en2.east()) < 0.002);
|
---|
195 | assertTrue("Ref", Math.abs(en.north() - en2.north()) < 0.002);
|
---|
196 | }
|
---|
197 | }
|
---|
198 | }
|
---|