Changeset 9370 in josm for trunk/test/unit
- Timestamp:
- 2016-01-09T22:33:40+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionTest.java
r9189 r9370 3 3 4 4 import java.util.Arrays; 5 import java.util.Collection; 6 import java.util.HashSet; 5 7 import java.util.Random; 6 8 … … 19 21 20 22 @Test 21 public void proj () {23 public void projections() { 22 24 error = false; 23 25 text = ""; 24 26 25 testProj (Projections.getProjectionByCode("EPSG:4326")); // WGS 8426 testProj (Projections.getProjectionByCode("EPSG:3857")); // Mercator27 testProj (Projections.getProjectionByCode("EPSG:3301")); // Lambert EST27 testProjection(Projections.getProjectionByCode("EPSG:4326")); // WGS 84 28 testProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator 29 testProjection(Projections.getProjectionByCode("EPSG:3301")); // Lambert EST 28 30 29 31 for (int i = 0; i <= 3; ++i) { 30 testProj (Projections.getProjectionByCode("EPSG:"+Integer.toString(27561+i))); // Lambert 4 Zones France32 testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(27561+i))); // Lambert 4 Zones France 31 33 } 32 34 33 35 for (int i = 0; i <= 4; ++i) { 34 testProj (Projections.getProjectionByCode("EPSG:"+Integer.toString(2176+i))); // PUWG Poland36 testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(2176+i))); // PUWG Poland 35 37 } 36 38 37 testProj (Projections.getProjectionByCode("EPSG:21781")); // Swiss grid39 testProjection(Projections.getProjectionByCode("EPSG:21781")); // Swiss grid 38 40 39 41 for (int i = 0; i <= 60; ++i) { 40 testProj (Projections.getProjectionByCode("EPSG:"+Integer.toString(32601+i))); // UTM North41 testProj (Projections.getProjectionByCode("EPSG:"+Integer.toString(32701+i))); // UTM South42 testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(32601+i))); // UTM North 43 testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(32701+i))); // UTM South 42 44 } 43 45 44 46 for (String c : Arrays.asList("2969", "2970", "2972", "2973")) { 45 testProj (Projections.getProjectionByCode("EPSG:"+c)); // UTM France DOM47 testProjection(Projections.getProjectionByCode("EPSG:"+c)); // UTM France DOM 46 48 } 47 49 48 50 for (int i = 0; i <= 8; ++i) { 49 testProj (Projections.getProjectionByCode("EPSG:"+Integer.toString(3942+i))); // Lambert CC9 Zones France51 testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(3942+i))); // Lambert CC9 Zones France 50 52 } 51 53 … … 56 58 } 57 59 58 private void testProj (Projection p) {60 private void testProjection(Projection p) { 59 61 if (p != null) { 60 62 double maxErrLat = 0, maxErrLon = 0; … … 64 66 for (int num = 0; num < 1000; ++num) { 65 67 66 double lat = rand.nextDouble() * (b.getMax().lat() - b.getMin().lat()) + b.getMin().lat(); 67 double lon = rand.nextDouble() * (b.getMax().lon() - b.getMin().lon()) + b.getMin().lon(); 68 69 LatLon ll = new LatLon(lat, lon); 68 LatLon ll0 = random(b); 69 LatLon ll = ll0; 70 70 71 71 for (int i = 0; i < 10; ++i) { … … 73 73 ll = p.eastNorth2latlon(en); 74 74 } 75 maxErrLat = Math.max(maxErrLat, Math.abs(l at- ll.lat()));76 maxErrLon = Math.max(maxErrLon, Math.abs(l on- ll.lon()));75 maxErrLat = Math.max(maxErrLat, Math.abs(ll0.lat() - ll.lat())); 76 maxErrLon = Math.max(maxErrLon, Math.abs(ll0.lon() - ll.lon())); 77 77 } 78 78 … … 85 85 } 86 86 } 87 88 private LatLon random(Bounds b) { 89 for (int i=0; i<20; i++) { 90 double lat = rand.nextDouble() * (b.getMax().lat() - b.getMin().lat()) + b.getMin().lat(); 91 double lon = rand.nextDouble() * (b.getMax().lon() - b.getMin().lon()) + b.getMin().lon(); 92 LatLon result = new LatLon(lat, lon); 93 if (result.isValid()) return result; 94 } 95 throw new RuntimeException(); 96 } 97 98 boolean error2; 99 String text2; 100 Collection<String> projIds; 101 102 @Test 103 public void projs() { 104 error2 = false; 105 text2 = ""; 106 107 projIds = new HashSet<>(Projections.getAllBaseProjectionIds()); 108 109 final double EPS = 1e-6; 110 testProj("lonlat", EPS, ""); 111 testProj("josm:smerc", EPS, ""); 112 testProj("lcc", EPS, "+lat_0=34"); 113 testProj("lcc", EPS, "+lat_1=87 +lat_2=83.6 +lat_0=85.43"); 114 testProj("somerc", EPS, "+lat_0=47"); 115 testProj("tmerc", 2e-3, ""); 116 testProj("sterea", EPS, "+lat_0=52"); 117 118 if (error2) { 119 System.err.println(text2); 120 Assert.fail(); 121 } 122 Assert.assertTrue("missing test: "+projIds, projIds.isEmpty()); 123 } 124 125 private void testProj(String id, double eps, String prefAdd) { 126 final int NUM_IT = 1000; 127 projIds.remove(id); 128 String pref = String.format("+proj=%s +ellps=WGS84 +nadgrids=null "+prefAdd, id); 129 CustomProjection p = new CustomProjection(); 130 try { 131 p.update(pref); 132 } catch (ProjectionConfigurationException ex) { 133 throw new RuntimeException(ex); 134 } 135 Bounds b = p.getWorldBoundsLatLon(); 136 for (int i=0; i<NUM_IT; i++) { 137 LatLon ll1 = random(b); 138 EastNorth en = p.latlon2eastNorth(ll1); 139 LatLon ll2 = p.eastNorth2latlon(en); 140 Assert.assertTrue(p.toCode() + " at " + ll1 + " is " + ll2, ll2.isValid()); 141 double dist = ll1.greatCircleDistance(ll2); 142 if (dist > eps) { 143 error2 = true; 144 text2 += id + ": dist " + dist + " at " + ll1 + "\n"; 145 return; 146 } 147 } 148 } 87 149 }
Note:
See TracChangeset
for help on using the changeset viewer.