2

I'm trying to transform a JTS geometry from EPSG 3035 to 4326 with the code attached below. However, when I'm just reading the geometry from a WKT, the results are different from the expected value (should be long: 48°16'17.626", lat: 14°16'55.125", according to epsg.io, but is POINT (61.90... -19.77...)).

However, when I switch the coordinate order in the WKT I get the expected results. Is there any way to tell the WKTReader or JTS.transform to switch up the coordinate order internally?

final WKTReader reader = new WKTReader();
final Geometry geom = reader.read("POINT (4638804.944501147 2804557.565404966)");
final CoordinateReferenceSystem crs3035 = CRS.decode("EPSG:3035");
final CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326");

final MathTransform metersToDeg = CRS.findMathTransform(crs3035, crs4326);
final Geometry transformed = JTS.transform(geom, metersToDeg);
System.out.println(transformed);

1 Answer 1

2

Axis order with EPSG:4326 is a nightmare of such complexity that it really needs to be retired by the EPSG and replaced with 2 distinct codes for lat/lon and lon/lat.

For a quick and dirty fix you can just try adding System.setProperty("org.geotools.referencing.forceXY", "true"); to your program. Alternatively, you can use DefaultGeographicCRS.WGS84 instead of decoding an EPSG code which should give you an East/North Axis order (which can always be checked using CRS.getAxisOrder(crs).

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.