Ticket #5399: reframe.patch

File reframe.patch, 4.7 KB (added by Don-vip, 8 years ago)
  • src/org/openstreetmap/josm/data/projection/proj/SwissObliqueMercator.java

     
    22package org.openstreetmap.josm.data.projection.proj;
    33
    44import static java.lang.Math.PI;
    5 import static java.lang.Math.abs;
    65import static java.lang.Math.asin;
    7 import static java.lang.Math.atan;
    8 import static java.lang.Math.atan2;
    96import static java.lang.Math.cos;
    10 import static java.lang.Math.exp;
    117import static java.lang.Math.log;
    128import static java.lang.Math.pow;
    139import static java.lang.Math.sin;
     
    1915import org.openstreetmap.josm.data.Bounds;
    2016import org.openstreetmap.josm.data.projection.Ellipsoid;
    2117import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
    22 import org.openstreetmap.josm.tools.JosmRuntimeException;
     18
     19import com.swisstopo.geodesy.reframe_lib.IReframe.AltimetricFrame;
     20import com.swisstopo.geodesy.reframe_lib.IReframe.PlanimetricFrame;
     21import com.swisstopo.geodesy.reframe_lib.IReframe.ProjectionChange;
     22import com.swisstopo.geodesy.reframe_lib.Reframe;
    2323
    2424// CHECKSTYLE.OFF: LineLength
    2525
     
    3838
    3939    // CHECKSTYLE.ON: LineLength
    4040
     41    private Reframe reframe;
    4142    private Ellipsoid ellps;
    4243    private double kR;
    4344    private double alpha;
     
    5253        super.initialize(params);
    5354        if (params.lat0 == null)
    5455            throw new ProjectionConfigurationException(tr("Parameter ''{0}'' required.", "lat_0"));
     56        reframe = new Reframe();
    5557        ellps = params.ellps;
    5658        initialize(params.lat0);
    5759    }
     
    7880
    7981    @Override
    8082    public double[] project(double phi, double lambda) {
    81         double s = alpha * log(tan(PI / 4 + phi / 2)) - alpha * ellps.e / 2
     83        /*double s = alpha * log(tan(PI / 4 + phi / 2)) - alpha * ellps.e / 2
    8284            * log((1 + ellps.e * sin(phi)) / (1 - ellps.e * sin(phi))) + k;
    8385        double b = 2 * (atan(exp(s)) - PI / 4);
    8486        double l = alpha * lambda;
     
    8991        double y = kR * lb;
    9092        double x = kR / 2 * log((1 + sin(bb)) / (1 - sin(bb)));
    9193
    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};
    93101    }
    94102
    95103    @Override
    96104    public double[] invproject(double y, double x) {
    97         double lb = y / kR;
     105        /*double lb = y / kR;
    98106        double bb = 2 * (atan(exp(x / kR)) - PI / 4);
    99107
    100108        double b = asin(cos(b0) * sin(bb) + sin(b0) * cos(bb) * cos(lb));
     
    114122            * log(tan(PI / 4 + asin(ellps.e * sin(phi)) / 2));
    115123            phi = 2 * atan(exp(s)) - PI / 2;
    116124        }
    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])};
    118130    }
    119131
    120132    @Override
  • test/unit/org/openstreetmap/josm/data/projection/SwissGridTest.java

     
    55import static org.junit.Assert.assertTrue;
    66
    77import org.junit.BeforeClass;
    8 import org.junit.Ignore;
    98import org.junit.Test;
    109import org.openstreetmap.josm.Main;
    1110import org.openstreetmap.josm.data.coor.EastNorth;
     
    1312
    1413public class SwissGridTest {
    1514    private static final String SWISS_EPSG_CODE = "EPSG:21781";
    16     private boolean debug = false;
     15    private boolean debug = true;
    1716
    1817    /**
    1918     * Setup test.
     
    7675    }
    7776
    7877    @Test
    79     @Ignore("high accuracy of epsilon=" + EPSILON_ACCURATE + " is not met")
    8078    public void testProjReferenceTestAccurate() {
    81         // TODO make this test pass
    8279        projReferenceTest(EPSILON_ACCURATE);
    8380    }
    8481