Changeset 11648 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2017-03-02T01:28:53+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java
r11324 r11648 31 31 32 32 import org.junit.Assert; 33 import org.junit.Rule; 33 34 import org.junit.Test; 34 35 import org.openstreetmap.josm.data.Bounds; … … 36 37 import org.openstreetmap.josm.data.coor.LatLon; 37 38 import org.openstreetmap.josm.gui.preferences.projection.CodeProjectionChoice; 39 import org.openstreetmap.josm.testutils.JOSMTestRules; 38 40 import org.openstreetmap.josm.tools.Pair; 39 41 import org.openstreetmap.josm.tools.Utils; … … 48 50 * program from the proj.4 library in path (or use <code>CS2CS_EXE</code> to set 49 51 * the full path of the executable). Make sure the required *.gsb grid files 50 * can be accessed, i.e. copy them from <code>data /projection</code> to <code>/usr/share/proj</code> or52 * can be accessed, i.e. copy them from <code>data_nodist/projection</code> to <code>/usr/share/proj</code> or 51 53 * wherever cs2cs expects them to be placed. 52 54 * … … 75 77 76 78 static Random rand = new SecureRandom(); 79 80 /** 81 * Setup test. 82 */ 83 @Rule 84 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 85 public JOSMTestRules test = new JOSMTestRules().platform(); 77 86 78 87 /** … … 284 293 } 285 294 295 /** 296 * Test projections. 297 * @throws IOException if any I/O error occurs 298 */ 286 299 @Test 287 300 public void testProjections() throws IOException { … … 296 309 } 297 310 if (!ref.def.equals(def0)) { 298 Assert.fail("definitions for " + ref.code + " do not match"); 299 } 300 Projection proj = Projections.getProjectionByCode(ref.code); 301 double scale = ((CustomProjection) proj).getToMeter(); 302 for (Pair<LatLon, EastNorth> p : ref.data) { 303 LatLon ll = p.a; 304 EastNorth enRef = p.b; 305 enRef = new EastNorth(enRef.east() * scale, enRef.north() * scale); // convert to meter 306 307 EastNorth en = proj.latlon2eastNorth(ll); 308 if (proj.switchXY()) { 309 en = new EastNorth(en.north(), en.east()); 310 } 311 en = new EastNorth(en.east() * scale, en.north() * scale); // convert to meter 312 final double EPSILON_EN = 1e-2; // 1cm 313 if (!isEqual(enRef, en, EPSILON_EN, true)) { 314 String errorEN = String.format("%s (%s): Projecting latlon(%s,%s):%n" + 315 " expected: eastnorth(%s,%s),%n" + 316 " but got: eastnorth(%s,%s)!%n", 317 proj.toString(), proj.toCode(), ll.lat(), ll.lon(), enRef.east(), enRef.north(), en.east(), en.north()); 318 fail.append(errorEN); 311 fail.append("definitions for ").append(ref.code).append(" do not match\n"); 312 } else { 313 Projection proj = Projections.getProjectionByCode(ref.code); 314 double scale = ((CustomProjection) proj).getToMeter(); 315 for (Pair<LatLon, EastNorth> p : ref.data) { 316 LatLon ll = p.a; 317 EastNorth enRef = p.b; 318 enRef = new EastNorth(enRef.east() * scale, enRef.north() * scale); // convert to meter 319 320 EastNorth en = proj.latlon2eastNorth(ll); 321 if (proj.switchXY()) { 322 en = new EastNorth(en.north(), en.east()); 323 } 324 en = new EastNorth(en.east() * scale, en.north() * scale); // convert to meter 325 final double EPSILON_EN = 1e-2; // 1cm 326 if (!isEqual(enRef, en, EPSILON_EN, true)) { 327 String errorEN = String.format("%s (%s): Projecting latlon(%s,%s):%n" + 328 " expected: eastnorth(%s,%s),%n" + 329 " but got: eastnorth(%s,%s)!%n", 330 proj.toString(), proj.toCode(), ll.lat(), ll.lon(), enRef.east(), enRef.north(), en.east(), en.north()); 331 fail.append(errorEN); 332 } 319 333 } 320 334 }
Note:
See TracChangeset
for help on using the changeset viewer.