Sunday, 28 July 2019

java - Proj4J not precise for EPSG:3857 transformations


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);


}

}

Answer



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...