Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect coordinate transformation Gauss-Kruger - WGS84 using GeoTools

I´m having a problem concerning the beloved coordinate transformation with the aid of GeoTools: I would like to convert a set of coordinates from Gauss-Kruger (zone 5, EPSG 31469) into ordinary WGS84 coordinates (EPSG 4326).

I´ve built a code with a simple example (just one pair of coordinates to try):

double coordX = 5408301.53; 
double coordY = 5659230.5;
double[] punt = new double[2];

CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:31469");
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");

MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true);

DirectPosition expPt = new GeneralDirectPosition(coordX, coordY);
expPt = transform.transform(expPt, null);
punt = expPt.getCoordinate();

System.out.println(punt[0] + ", " + punt[1]); //lon, lat

The result after debugging is as follows: 48.791886921764345, 17.16525096311777

When I then check my obtained WGS84 coordinates (just hit them into Google Maps) I end up somewhere in the the Czech Republic near Austria although this pair of coordinates should be somewhere in the east of Germany (for sure, I checked it by some html decoder):

---> should be the result: 51.0609167, 13.6900142.

I cannot imagine any reason why this failure occurs. GeoTools gets both of the wanted CRS (I attached an extract from the response out of the java console)

Does anybody is able to explain this? I´d appreciate any help!

Many greets, Sebastian


**sourceCRS:**
PROJCS["DHDN / 3-degree Gauss-Kruger zone 5",
    GEOGCS["DHDN", 
    DATUM["Deutsches Hauptdreiecksnetz", 
      SPHEROID["Bessel 1841", 6377397.155, 299.1528128, AUTHORITY["EPSG","7004"]], 
      TOWGS84[612.4, 77.0, 440.2, -0.054, 0.057, -2.797, 2.55], 
      AUTHORITY["EPSG","6314"]], 
    PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], 
    UNIT["degree", 0.017453292519943295], 
    AXIS["Geodetic latitude", NORTH], 
    AXIS["Geodetic longitude", EAST], 
    AUTHORITY["EPSG","4314"]], 
  PROJECTION["Transverse_Mercator", AUTHORITY["EPSG","9807"]], 
  PARAMETER["central_meridian", 15.0], 
  PARAMETER["latitude_of_origin", 0.0], 
  PARAMETER["scale_factor", 1.0], 
  PARAMETER["false_easting", 5500000.0], 
  PARAMETER["false_northing", 0.0], 
  UNIT["m", 1.0], 
  AXIS["Northing", NORTH], 
  AXIS["Easting", EAST], 
  AUTHORITY["EPSG","31469"]]

**targetCRS:**
GEOGCS["WGS 84", 
  DATUM["World Geodetic System 1984", 
    SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], 
    AUTHORITY["EPSG","6326"]], 
  PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], 
  UNIT["degree", 0.017453292519943295], 
  AXIS["Geodetic latitude", NORTH], 
  AXIS["Geodetic longitude", EAST], 
  AUTHORITY["EPSG","4326"]]
CONCAT_MT[PARAM_MT["Affine", 
    PARAMETER["num_row", 3], 
    PARAMETER["num_col", 3], 
    PARAMETER["elt_0_0", 0.0], 
    PARAMETER["elt_0_1", 1.0], 
    PARAMETER["elt_1_0", 1.0], 
    PARAMETER["elt_1_1", 0.0]], 
  INVERSE_MT[PARAM_MT["Transverse_Mercator", 
      PARAMETER["semi_major", 6377397.155], 
      PARAMETER["semi_minor", 6356078.962818189], 
      PARAMETER["central_meridian", 15.0], 
      PARAMETER["latitude_of_origin", 0.0], 
      PARAMETER["scale_factor", 1.0], 
      PARAMETER["false_easting", 5500000.0], 
      PARAMETER["false_northing", 0.0]]], 
  PARAM_MT["Ellipsoid_To_Geocentric", 
    PARAMETER["dim", 2], 
    PARAMETER["semi_major", 6377397.155], 
    PARAMETER["semi_minor", 6356078.962818189]], 
  PARAM_MT["Position Vector transformation (geog2D domain)", 
    PARAMETER["dx", 612.4], 
    PARAMETER["dy", 77.0], 
    PARAMETER["dz", 440.2], 
    PARAMETER["ex", -0.054], 
    PARAMETER["ey", 0.057], 
    PARAMETER["ez", -2.797], 
    PARAMETER["ppm", 2.5500000000455714]], 
  PARAM_MT["Geocentric_To_Ellipsoid", 
    PARAMETER["dim", 2], 
    PARAMETER["semi_major", 6378137.0], 
    PARAMETER["semi_minor", 6356752.314245179]], 
  PARAM_MT["Affine", 
    PARAMETER["num_row", 3], 
    PARAMETER["num_col", 3], 
    PARAMETER["elt_0_0", 0.0], 
    PARAMETER["elt_0_1", 1.0], 
    PARAMETER["elt_1_0", 1.0], 
    PARAMETER["elt_1_1", 0.0]]]
like image 404
sebjun87 Avatar asked Nov 04 '22 01:11

sebjun87


1 Answers

I get the correct result (13.690015717822922, 51.06089012028224) when I try to reproduce the problem with your code and the latest Geotools (8.0). With lon,lat swapped, that is.

The bad result (17.16525096311777, 48.791886921764345) comes when I swap coordX and coordY. This puts you into the Yemenite desert instead of Dresden.

Maybe you implicitly assume a wrong ordering of axes. Arguably, putting latitude before longitude somehow violates the general agreement for cartesian coordinates to put X before Y.

While I can't reproduce your problem, one of the workarounds in this tutorial, where ordering of axes is discussed may help you.

like image 67
Hok Avatar answered Nov 09 '22 10:11

Hok