6

I try to convert some coordinates from "EPSG:31469" to "EPSG:3857" and back.

With the heavy framework GeoTools it seems to work pretty precise.

"EPSG:31469" - 5439627.33,          5661628.09
"EPSG:3857"  - 1573655.6648492748,  6636624.730959651
"EPSG:31469" - 5439627.330626475,   5661628.099510074

But I would like to use the lightweight library Proj4j (https://github.com/Proj4J/proj4j) which produces massive deviation:

"EPSG:31469" - 5439627.33,          5661628.09
"EPSG:3857"  - 1573659.9666159092   6603334.624358153
"EPSG:31469" - 5439626.576916553    5661585.491150079

Any ideas why this is the case?

My code:

import org.cts.crs.CRSException;
import org.osgeo.proj4j.CRSFactory;
import org.osgeo.proj4j.CoordinateTransform;
import org.osgeo.proj4j.CoordinateTransformFactory;
import org.osgeo.proj4j.ProjCoordinate;

public class Test
{

    public static void main(String[] args) throws CRSException
    {
        ProjCoordinate coord = new ProjCoordinate(5439627.33, 5661628.09);
        System.out.println(coord);

        ProjCoordinate target = new ProjCoordinate();
        CRSFactory crsFactory = new CRSFactory();
        CoordinateTransformFactory f = new CoordinateTransformFactory();
        CoordinateTransform t;

        t = f.createTransform(crsFactory.createFromName("EPSG:31469"),
            crsFactory.createFromName("EPSG:3857"));

        t.transform(coord, target);

        System.out.println(target);

        ProjCoordinate coord2 = new ProjCoordinate(target.x, target.y);

        t = f.createTransform(crsFactory.createFromName("EPSG:3857"),
            crsFactory.createFromName("EPSG:31469"));

        t.transform(coord2, target);

        System.out.println(target);
        System.out.println(target.x - coord.x);
        System.out.println(target.y - coord.y);

    }

}
2

You have a problem with your code, because in Python with pyproj (python interface to PROJ4 library)

from pyproj import Proj, transform
inProj  = Proj("+init=EPSG:31469")
outProj = Proj("+init=EPSG:3857")
x1,y1 =  (5439627.33,5661628.09)
x2,y2 =transform(inProj,outProj,x1,y1)
x3,y3 =  transform(outProj,inProj,x2,y2)
print x1,y1
5439627.33 5661628.09
print x2,y2
1573657.37085 6636624.40597
print x3,y3
5439627.33052 5661628.09049

The core of the library OSGEO Proj4J is a port of the ​PROJ.4 C library and it is specified that:

Status: Currently this library is still being created, and is not yet ready for download

There is a mailing list The Proj4j Archives and the last post is from Mars 2016 (for user30184)

1

Thanks to AndreJ! The fork of proj4j at https://github.com/dwins/proj4j works precisely on EPSG:3857

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.