source: josm/trunk/test/unit/org/openstreetmap/josm/data/projection/SwissGridTest.java

Last change on this file was 18870, checked in by taylor.smock, 8 months ago

See #16567: Update to JUnit 5

This converts most tests to use @Annotations. There are also some performance
improvements as it relates to tests.

  • Property svn:eol-style set to native
File size: 9.5 KB
RevLine 
[3473]1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection;
3
[17275]4import static org.junit.jupiter.api.Assertions.assertSame;
5import static org.junit.jupiter.api.Assertions.assertTrue;
[3473]6
[17275]7import org.junit.jupiter.api.BeforeAll;
8import org.junit.jupiter.api.Test;
[3473]9import org.openstreetmap.josm.data.coor.EastNorth;
10import org.openstreetmap.josm.data.coor.LatLon;
[18870]11import org.openstreetmap.josm.testutils.annotations.ProjectionNadGrids;
[3473]12
[13702]13/**
14 * Unit tests for the Swiss projection grid.
15 */
[18870]16@ProjectionNadGrids
[17275]17class SwissGridTest {
[10758]18 private static final String SWISS_EPSG_CODE = "EPSG:21781";
[16913]19 private final boolean debug = false;
[3483]20
[6881]21 /**
22 * Setup test.
23 */
[17275]24 @BeforeAll
[3473]25 public static void setUp() {
[14120]26 ProjectionRegistry.setProjection(Projections.getProjectionByCode(SWISS_EPSG_CODE)); // Swiss grid
[3473]27 }
28
[8540]29 // CHECKSTYLE.OFF: LineLength
[10378]30 // CHECKSTYLE.OFF: SingleSpaceSeparator
[8540]31
[3473]32 /**
[11660]33 * source: https://www.swisstopo.admin.ch/content/swisstopo-internet/en/topics/survey/reference-systems/projections/_jcr_content/contentPar/tabs/items/dokumente_publikatio/tabPar/downloadlist/downloadItems/463_1459341821844.download/refsyse.pdf
[3473]34 */
35 ProjData[] data = {
[10378]36 new ProjData("Zimmerwald", d(7, 27, 54.983506), d(46, 52, 37.540562), 947.149, 602030.680, 191775.030, 897.915),
37 new ProjData("Chrischona", d(7, 40, 6.983077), d(47, 34, 1.385301), 504.935, 617306.300, 268507.300, 456.064),
38 new ProjData("Pfaender", d(9, 47, 3.697723), d(47, 30, 55.172797), 1089.372, 776668.105, 265372.681, 1042.624),
39 new ProjData("La Givrine", d(6, 6, 7.326361), d(46, 27, 14.690021), 1258.274, 497313.292, 145625.438, 1207.434),
40 new ProjData("Monte Generoso", d(9, 1, 16.389053), d(45, 55, 45.438020), 1685.027, 722758.810, 87649.670, 1636.600) };
[3473]41
[10378]42 // CHECKSTYLE.ON: SingleSpaceSeparator
[8540]43 // CHECKSTYLE.ON: LineLength
44
[3473]45 private double d(double deg, double min, double sec) {
46 return deg + min / 60. + sec / 3600.;
47 }
[3479]48
49 private static class ProjData {
[3473]50 public String name;
51 public LatLon ll;
52 public EastNorth en;
[8510]53
[8836]54 ProjData(String name, double lon, double lat, double h1, double x, double y, double h2) {
[3473]55 this.name = name;
56 ll = new LatLon(lat, lon);
57 en = new EastNorth(x, y);
58 }
59 }
60
[10758]61 private static final double EPSILON_ACCURATE = 0.05;
[3483]62
[10758]63 private void projReferenceTest(final double epsilon) {
[5556]64 Projection swiss = Projections.getProjectionByCode("EPSG:21781"); // Swiss grid
[6264]65 StringBuilder errs = new StringBuilder();
[3473]66 for (ProjData pd : data) {
67 EastNorth en2 = swiss.latlon2eastNorth(pd.ll);
[7151]68 if (Math.abs(pd.en.east() - en2.east()) > epsilon || Math.abs(pd.en.north() - en2.north()) > epsilon) {
[6334]69 errs.append(String.format("%s should be: %s but is: %s%n", pd.name, pd.en, en2));
[3473]70 }
71 }
[17275]72 assertSame(errs.length(), 0, errs::toString);
[3479]73 }
[3473]74
[13702]75 /**
76 * Test projection accuracy.
77 */
[3473]78 @Test
[17275]79 void testProjReferenceTestAccurate() {
[7151]80 projReferenceTest(EPSILON_ACCURATE);
81 }
82
[13702]83 /**
84 * Unit test A: lat/lon => east/north
85 */
[7151]86 @Test
[17275]87 void testAlatlon2eastNorth() {
[8513]88 LatLon ll = new LatLon(46.518, 6.567);
[14120]89 EastNorth en = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]90 if (debug) {
91 System.out.println(en);
[3473]92 }
[17275]93 assertTrue(Math.abs(en.east() - 533112.13) < 0.1, "Lausanne");
94 assertTrue(Math.abs(en.north() - 152227.35) < 0.1, "Lausanne");
[3473]95
[8513]96 ll = new LatLon(47.78, 8.58);
[14120]97 en = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]98 if (debug) {
99 System.out.println(en);
[3473]100 }
[17275]101 assertTrue(Math.abs(en.east() - 685542.97) < 0.1, "Schafouse");
102 assertTrue(Math.abs(en.north() - 292783.21) < 0.1, "Schafouse");
[3473]103
[8513]104 ll = new LatLon(46.58, 10.48);
[14120]105 en = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]106 if (debug) {
107 System.out.println(en);
[3473]108 }
[17275]109 assertTrue(Math.abs(en.east() - 833066.95) < 0.1, "Grinson");
110 assertTrue(Math.abs(en.north() - 163265.32) < 0.1, "Grinson");
[3473]111
[8513]112 ll = new LatLon(46.0 + 57.0 / 60 + 3.89813884505 / 3600, 7.0 + 26.0 / 60 + 19.076595154147 / 3600);
[14120]113 en = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]114 if (debug) {
115 System.out.println(en);
[3473]116 }
[17275]117 assertTrue(Math.abs(en.east() - 600000.0) < 0.1, "Berne");
118 assertTrue(Math.abs(en.north() - 200000.0) < 0.1, "Berne");
[8513]119
[11660]120 // http://geodesy.geo.admin.ch/reframe/lv03towgs84?easting=700000&northing=100000
121 ll = new LatLon(46.04412093223244, 8.730497366167727);
[14120]122 en = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]123 if (debug) {
124 System.out.println(en);
[3473]125 }
[17275]126 assertTrue(Math.abs(en.east() - 700000.0) < 0.1, "Ref");
127 assertTrue(Math.abs(en.north() - 100000.0) < 0.1, "Ref");
[3473]128 }
129
[13702]130 /**
131 * Unit test B: east/north => lat/lon
132 */
[3473]133 @Test
[17275]134 void testBeastNorth2latlon() {
[11660]135 EastNorth en = new EastNorth(533112.13, 152227.35);
[14120]136 LatLon ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
[8513]137 if (debug) {
138 System.out.println(ll);
[3473]139 }
[17275]140 assertTrue(Math.abs(ll.lat() - 46.518) < 0.00001, "Lausanne");
141 assertTrue(Math.abs(ll.lon() - 6.567) < 0.00001, "Lausanne");
[3473]142
[11660]143 en = new EastNorth(685542.97, 292783.21);
[14120]144 ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
[8513]145 if (debug) {
146 System.out.println(ll);
[3473]147 }
[17275]148 assertTrue(Math.abs(ll.lat() - 47.78) < 0.00001, "Schafouse");
149 assertTrue(Math.abs(ll.lon() - 8.58) < 0.00001, "Schafouse");
[3473]150
[11660]151 en = new EastNorth(833066.95, 163265.32);
[14120]152 ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
[8513]153 if (debug) {
154 System.out.println(ll);
[3473]155 }
[17275]156 assertTrue(Math.abs(ll.lat() - 46.58) < 0.00001, "Grinson");
157 assertTrue(Math.abs(ll.lon() - 10.48) < 0.00001, "Grinson");
[3473]158
[8513]159 en = new EastNorth(600000.0, 200000.0);
[14120]160 ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
[8513]161 if (debug) {
162 System.out.println(ll);
[3473]163 }
[17275]164 assertTrue(Math.abs(ll.lat() - (46.0 + 57.0 / 60 + 3.89813884505 / 3600)) < 0.00001, "Berne");
165 assertTrue(Math.abs(ll.lon() - (7.0 + 26.0 / 60 + 19.076595154147 / 3600)) < 0.00001, "Berne");
[3479]166
[11660]167 // http://geodesy.geo.admin.ch/reframe/lv03towgs84?easting=700000&northing=100000
[8513]168 en = new EastNorth(700000.0, 100000.0);
[14120]169 ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
[8513]170 if (debug) {
171 System.out.println(ll);
[3473]172 }
[17275]173 assertTrue(Math.abs(ll.lat() - 46.04412093223244) < 0.00001, "Ref");
174 assertTrue(Math.abs(ll.lon() - 8.730497366167727) < 0.00001, "Ref");
[3473]175 }
176
177 /**
[3479]178 * Send and return should have less than 2mm of difference.
[3473]179 */
180 @Test
[17275]181 void testCsendandreturn() {
[8513]182 EastNorth en = new EastNorth(533111.69, 152227.85);
[14120]183 LatLon ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
184 EastNorth en2 = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]185 if (debug) {
186 System.out.println(en.east() - en2.east());
[3473]187 }
[8513]188 if (debug) {
189 System.out.println(en.north() - en2.north());
190 }
[17275]191 assertTrue(Math.abs(en.east() - en2.east()) < 0.002, "Lausanne");
192 assertTrue(Math.abs(en.north() - en2.north()) < 0.002, "Lausanne");
[3473]193
[8513]194 en = new EastNorth(685544.16, 292782.91);
[14120]195 ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
196 en2 = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]197 if (debug) {
198 System.out.println(en.east() - en2.east());
[3473]199 }
[8513]200 if (debug) {
201 System.out.println(en.north() - en2.north());
202 }
[17275]203 assertTrue(Math.abs(en.east() - en2.east()) < 0.002, "Schafouse");
204 assertTrue(Math.abs(en.north() - en2.north()) < 0.002, "Schafouse");
[3473]205
[8513]206 en = new EastNorth(833068.04, 163265.39);
[14120]207 ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
208 en2 = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]209 if (debug) {
210 System.out.println(en.east() - en2.east());
[3473]211 }
[8513]212 if (debug) {
213 System.out.println(en.north() - en2.north());
214 }
[17275]215 assertTrue(Math.abs(en.east() - en2.east()) < 0.002, "Grinson");
216 assertTrue(Math.abs(en.north() - en2.north()) < 0.002, "Grinson");
[3473]217
[8513]218 en = new EastNorth(600000.0, 200000.0);
[14120]219 ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
220 en2 = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]221 if (debug) {
222 System.out.println(en.east() - en2.east());
[3473]223 }
[8513]224 if (debug) {
225 System.out.println(en.north() - en2.north());
226 }
[17275]227 assertTrue(Math.abs(en.east() - en2.east()) < 0.002, "Berne");
228 assertTrue(Math.abs(en.north() - en2.north()) < 0.002, "Berne");
[3479]229
[8513]230 en = new EastNorth(700000.0, 100000.0);
[14120]231 ll = ProjectionRegistry.getProjection().eastNorth2latlon(en);
232 en2 = ProjectionRegistry.getProjection().latlon2eastNorth(ll);
[8513]233 if (debug) {
234 System.out.println(en.east() - en2.east());
[3473]235 }
[8513]236 if (debug) {
237 System.out.println(en.north() - en2.north());
238 }
[17275]239 assertTrue(Math.abs(en.east() - en2.east()) < 0.002, "Ref");
240 assertTrue(Math.abs(en.north() - en2.north()) < 0.002, "Ref");
[3473]241 }
242}
Note: See TracBrowser for help on using the repository browser.