I am trying to use GeoTools to transform between two coordinate systems, one in meter and the other in degree, but no matter what i try the converted values are not correct. I have tried to follow other examples using the same code, but for some reason it fails to convert between these two coordinate systems: [EPSG:3044] -> [EPSG:4326] (WGS 84)
I am parsing the WKT
for both CRS and then transform it using GeoTools - below is my current code, together with my results:
EDIT The source code has been updated to reflect the output of using WKT and the internal CRS decoder.
val sourceCRS = CRS.parseWKT(
"""PROJCS["ETRS89 / UTM zone 32N (N-E)",
| GEOGCS["ETRS89",
| DATUM["European_Terrestrial_Reference_System_1989",
| SPHEROID["GRS 1980",6378137,298.257222101,
| AUTHORITY["EPSG","7019"]],
| TOWGS84[0,0,0,0,0,0,0],
| AUTHORITY["EPSG","6258"]],
| PRIMEM["Greenwich",0,
| AUTHORITY["EPSG","8901"]],
| UNIT["degree",0.0174532925199433,
| AUTHORITY["EPSG","9122"]],
| AUTHORITY["EPSG","4258"]],
| PROJECTION["Transverse_Mercator"],
| PARAMETER["latitude_of_origin",0],
| PARAMETER["central_meridian",9],
| PARAMETER["scale_factor",0.9996],
| PARAMETER["false_easting",500000],
| PARAMETER["false_northing",0],
| UNIT["metre",1,
| AUTHORITY["EPSG","9001"]],
| AUTHORITY["EPSG","3044"]]""".stripMargin)
val targetCRS = CRS.parseWKT(
"""
|GEOGCS["WGS 84",
| DATUM["WGS_1984",
| SPHEROID["WGS 84",6378137,298.257223563,
| AUTHORITY["EPSG","7030"]],
| AUTHORITY["EPSG","6326"]],
| PRIMEM["Greenwich",0,
| AUTHORITY["EPSG","8901"]],
| UNIT["degree",0.0174532925199433,
| AUTHORITY["EPSG","9122"]],
| AUTHORITY["EPSG","4326"]]
|""".stripMargin)
val source = CRS.decode("EPSG:3044");
val target = CRS.decode("EPSG:4326");
val originalCoordinate = new Coordinate(5293975.04, 959436.64)
// WKT
val coordinateWKT = new Coordinate()
val wktTransform = CRS.findMathTransform(sourceCRS, targetCRS, true)
JTS.transform(originalCoordinate, coordinateWKT, wktTransform)
// EPSG
val coordinateEPSG = new Coordinate()
val epsgTransform = CRS.findMathTransform(source, target, true);
JTS.transform(originalCoordinate, coordinateEPSG, epsgTransform);
// Output
System.out.println(s"Original: ${originalCoordinate}")
System.out.println(s"EKT: ${coordinateWKT}")
System.out.println(s"EPSG: ${coordinateEPSG}")
And my input and output coordinates are:
Original: (5293975.04, 959436.64, NaN)
EKT: (48.79550725975144, 6.678848738740256, NaN)
EPSG: (47.63578358581114, 15.117187455070956, NaN)
CodePudding user response:
So the correct transformed coordinate would be: (56.4336819°, 4.1353377°)
Maybe your source coordinate is inaccurate because it is not in the area where the coordinate system is used.
From epsg.io:
Area of use: Europe between 6°E and 12°E: Austria; Belgium; Denmark - onshore and offshore; Germany - onshore and offshore; Norway including - onshore and offshore; Spain - offshore
Your coordinate is east of Africa, in the Indian Ocean.
If I'm using for example coordinates from Austria, I get the following output (in Java):
CoordinateReferenceSystem source = CRS.decode("EPSG:25832");
CoordinateReferenceSystem target = CRS.decode("EPSG:4326");
Coordinate coordinate = new Coordinate(959436.64, 5293975.04);
// when you are using EPSG:3044, you have to change x and y:
// Coordinate coordinate = new Coordinate(5293975.04, 959436.64);
MathTransform transform = CRS.findMathTransform(source, target, false);
JTS.transform(coordinate, coordinate, transform);
System.out.println(coordinate); //(47.63578358581114, 15.117187455070956, NaN)
And that's the same result as from epsg.io. Note that I'm using EPSG:25832 instead of EPSG:3044.