Ticket #5399: reframe.patch
File reframe.patch, 4.7 KB (added by , 8 years ago) |
---|
-
src/org/openstreetmap/josm/data/projection/proj/SwissObliqueMercator.java
2 2 package org.openstreetmap.josm.data.projection.proj; 3 3 4 4 import static java.lang.Math.PI; 5 import static java.lang.Math.abs;6 5 import static java.lang.Math.asin; 7 import static java.lang.Math.atan;8 import static java.lang.Math.atan2;9 6 import static java.lang.Math.cos; 10 import static java.lang.Math.exp;11 7 import static java.lang.Math.log; 12 8 import static java.lang.Math.pow; 13 9 import static java.lang.Math.sin; … … 19 15 import org.openstreetmap.josm.data.Bounds; 20 16 import org.openstreetmap.josm.data.projection.Ellipsoid; 21 17 import org.openstreetmap.josm.data.projection.ProjectionConfigurationException; 22 import org.openstreetmap.josm.tools.JosmRuntimeException; 18 19 import com.swisstopo.geodesy.reframe_lib.IReframe.AltimetricFrame; 20 import com.swisstopo.geodesy.reframe_lib.IReframe.PlanimetricFrame; 21 import com.swisstopo.geodesy.reframe_lib.IReframe.ProjectionChange; 22 import com.swisstopo.geodesy.reframe_lib.Reframe; 23 23 24 24 // CHECKSTYLE.OFF: LineLength 25 25 … … 38 38 39 39 // CHECKSTYLE.ON: LineLength 40 40 41 private Reframe reframe; 41 42 private Ellipsoid ellps; 42 43 private double kR; 43 44 private double alpha; … … 52 53 super.initialize(params); 53 54 if (params.lat0 == null) 54 55 throw new ProjectionConfigurationException(tr("Parameter ''{0}'' required.", "lat_0")); 56 reframe = new Reframe(); 55 57 ellps = params.ellps; 56 58 initialize(params.lat0); 57 59 } … … 78 80 79 81 @Override 80 82 public double[] project(double phi, double lambda) { 81 double s = alpha * log(tan(PI / 4 + phi / 2)) - alpha * ellps.e / 283 /*double s = alpha * log(tan(PI / 4 + phi / 2)) - alpha * ellps.e / 2 82 84 * log((1 + ellps.e * sin(phi)) / (1 - ellps.e * sin(phi))) + k; 83 85 double b = 2 * (atan(exp(s)) - PI / 4); 84 86 double l = alpha * lambda; … … 89 91 double y = kR * lb; 90 92 double x = kR / 2 * log((1 + sin(bb)) / (1 - sin(bb))); 91 93 92 return new double[] {y, x}; 94 return new double[] {y, x};*/ 95 96 double[] outputCoordinates = reframe.ComputeGpsref(new double[] {Math.toDegrees(lambda), Math.toDegrees(phi), 600}, 97 ProjectionChange.ETRF93GeographicToLV95); 98 double[] result = reframe.ComputeReframe(outputCoordinates, 99 PlanimetricFrame.LV95, PlanimetricFrame.LV03_Civil, AltimetricFrame.Ellipsoid, AltimetricFrame.Ellipsoid); 100 return new double[] {result[0] / ellps.a, result[1] / ellps.a}; 93 101 } 94 102 95 103 @Override 96 104 public double[] invproject(double y, double x) { 97 double lb = y / kR;105 /*double lb = y / kR; 98 106 double bb = 2 * (atan(exp(x / kR)) - PI / 4); 99 107 100 108 double b = asin(cos(b0) * sin(bb) + sin(b0) * cos(bb) * cos(lb)); … … 114 122 * log(tan(PI / 4 + asin(ellps.e * sin(phi)) / 2)); 115 123 phi = 2 * atan(exp(s)) - PI / 2; 116 124 } 117 return new double[] {phi, lambda}; 125 return new double[] {phi, lambda};*/ 126 double[] outputCoordinates = reframe.ComputeReframe(new double[] {y * ellps.a, x * ellps.a, 600}, 127 PlanimetricFrame.LV03_Civil, PlanimetricFrame.LV95, AltimetricFrame.Ellipsoid, AltimetricFrame.Ellipsoid); 128 double[] result = reframe.ComputeGpsref(outputCoordinates, ProjectionChange.LV95ToETRF93Geographic); 129 return new double[] {Math.toRadians(result[1]), Math.toRadians(result[0])}; 118 130 } 119 131 120 132 @Override -
test/unit/org/openstreetmap/josm/data/projection/SwissGridTest.java
5 5 import static org.junit.Assert.assertTrue; 6 6 7 7 import org.junit.BeforeClass; 8 import org.junit.Ignore;9 8 import org.junit.Test; 10 9 import org.openstreetmap.josm.Main; 11 10 import org.openstreetmap.josm.data.coor.EastNorth; … … 13 12 14 13 public class SwissGridTest { 15 14 private static final String SWISS_EPSG_CODE = "EPSG:21781"; 16 private boolean debug = false;15 private boolean debug = true; 17 16 18 17 /** 19 18 * Setup test. … … 76 75 } 77 76 78 77 @Test 79 @Ignore("high accuracy of epsilon=" + EPSILON_ACCURATE + " is not met")80 78 public void testProjReferenceTestAccurate() { 81 // TODO make this test pass82 79 projReferenceTest(EPSILON_ACCURATE); 83 80 } 84 81