aims-ks / atlasmapper

Automatically exported from code.google.com/p/atlasmapper
2 stars 0 forks source link

Inverted reprojection #130

Closed gaellafond closed 5 years ago

gaellafond commented 5 years ago

Sometimes, reprojections are inverted. For example, instead of getting [180, 90], GeoTools returns [90, 180]

If I run the following code

try {
    System.out.println("ConfigManager");
    System.out.println("Reprojection test");
    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:3857");
    CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");

    {
        Coordinate source = new Coordinate(200000, 100000);
        Coordinate destination = new Coordinate();
        MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS) ;
        JTS.transform(source, destination, transform);
        System.out.println("REPROJECTED " + source.toString() + " TO " + destination.toString());
    }
} catch(Exception ex) { ex.printStackTrace(); }

On my computer, I get the expected result:

REPROJECTED (200000.0, 100000.0, NaN) TO (1.7966305682390429, 0.8982784828192615, NaN)

On Porcata, GeoTools invert the coordinates:

REPROJECTED (200000.0, 100000.0, NaN) TO (0.8982784828192615, 1.7966305682390429, NaN)
gaellafond commented 5 years ago

I finally found the solution!!

    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:3857", true);
    CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326", true);

See: https://gis.stackexchange.com/questions/258020/erroneous-transformation-with-geotools#answer-258114

gaellafond commented 5 years ago

Fixed in 2.0.11