Proj4J / proj4j

proj4j migration from svn. Project details can be found at http://trac.osgeo.org/proj4j/
51 stars 24 forks source link

Wrong output for EPSG:3857 #5

Open jwgmeligmeyling opened 8 years ago

jwgmeligmeyling commented 8 years ago

I am getting the wrong output when transforming EPSG:28992 to EPSG:3857. I have double checked my test case against the results for proj4 and proj4js, and they always have a different answer.

The test case I am using:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.osgeo.proj4j.BasicCoordinateTransform;
import org.osgeo.proj4j.ProjCoordinate;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.*;

/**
 * @author Jan-Willem Gmelig Meyling
 */
@RunWith(Parameterized.class)
public class TestRefSystem {

    CoordinateSystemFactory coordinateSystemFactory= new CoordinateSystemFactory();

    @Parameters
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][] {
            {
                96874.9995d, 438374.99950000003d, "EPSG:28992",
                4.542078787824207, 51.930803740349724, "EPSG:4326"
            },
            {
                96874.9995d, 438374.99950000003d, "EPSG:28992",
                505621.8978035199, 6787623.540322363, "EPSG:3857"
            }
        });
    }

    private final ProjCoordinate input, expected;
    private final BasicCoordinateTransform transform;

    public TestRefSystem(
        double x, double y, String sourceProjection,
        double expectedX, double expectedY, String targetProjection
    ) {
        transform =  new BasicCoordinateTransform(
            coordinateSystemFactory.createFromName(sourceProjection),
            coordinateSystemFactory.createFromName(targetProjection)
        );

        input = new ProjCoordinate(x, y);
        expected = new ProjCoordinate(expectedX, expectedY);
    }

    @Test
    public void testName() throws Exception {
        ProjCoordinate result = transform.transform(input, new ProjCoordinate(0d,0d,0d));

        assertEquals(
            expected.x, result.x, 1e-4
        );

        assertEquals(
            expected.y, result.y, 1e-4
        );
    }
}

(I am using this CoordinateSystemFactory by the way)

MarcelHeckel commented 7 years ago

I have had a similar problem. Try the fork at https://github.com/dwins/proj4j (See also https://www.locationtech.org/proposals/proj4j)

Andre-J commented 7 years ago

For reference: http://gis.stackexchange.com/questions/221552/proj4j-not-precise-for-epsg3857-transformations . EPSG:3857 is a kind of dirty hack, and some tweaks are introduced into the original PROJ.4 code after this Java port was done.