1

I am trying to convert coordinates (and polygons from com.vividsolutions.jts.geom) in Lambert72 (EPSG:31370) to WGS84 (or the other way around). I'm using the org.geotools.referencing CRS and MathTransform. To check I used an existing point from an official government database. As you can see, the transformed coordinates do not match but differ by up to 70 meters.

I'm using Java Oracle 8 and GeoTools 14 (with gt-epsg-wkt-14.0) in Eclipse.

Am I not using the MathTransform or the coordinate systems correctly?


Code:

public static Geometry convertWGSToLambert(Geometry g) {
    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
    CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:31370");
    MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
    return JTS.transform(g, transform);
}

public static Geometry convertLambertToWSG(Geometry g){
    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:31370");
    CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
    MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
    return JTS.transform(g, transform);
}

public static void main(String[] args) {
    //Point:
    //1. Lambert72: 
    double Lx = 148349;
    double Ly = 170851;
    Geometry lambert = geometryFactory.createPoint(new Coordinate(Lx, Ly));
    // 2. WGS84:
    double wgsX = 50 + 50.0 / 60 + 53.0 / 3600;
    double wgsY = 4 + 20.0 / 60 + 43.0 / 3600;
    Geometry wgs84 = geometryFactory.createPoint(new Coordinate(wgsY, wgsX));

    // conversion tests
    System.out.println("Conversion test case");
    System.out.println("Lambert->WSG: " + convertLambertToWSG(lambert));
    System.out.println("    instead of      (" + wgsY + "\t" + wgsX + ")");
    System.out.println("wgs84->Lambert:" + convertWGSToLambert(wgs84));
    System.out.println("    instead of      (" + Lx + "\t" + Ly + ")");
    System.out.println("\n");
    System.out.println("\"Dubbele\" transformatie:");
    System.out.println(convertWGSToLambert(convertLambertToWSG(lambert)));
    System.out.println("instead of (" + Lx + "\t" + Ly + ")");
}

Output:

Conversion test case
Lambert->WSG: POINT (4.344261536168711 50.847806380256316)
    instead of      (4.345277777777778 50.84805555555556)
wgs84->Lambert:POINT (148420.57570480864 170878.70642028935)
    instead of       (148349.0           170851.0)


"Dubbele" transformatie:
POINT      (148348.99959955606 170851.00944651756)
instead of (148349.0           170851.0)

CRS WKT's:

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 longitude", EAST], 
  AXIS["Geodetic latitude", NORTH], 
  AUTHORITY["EPSG","4326"]]

PROJCS["Belge 1972 / Belgian Lambert 72", 
  GEOGCS["Belge 1972", 
    DATUM["Reseau National Belge 1972", 
      SPHEROID["International 1924", 6378388.0, 297.0, AUTHORITY["EPSG","7022"]], 
      TOWGS84[-106.8686, 52.2978, -103.7239, 0.3366, 0.457, -1.8422, -1.2747], 
      AUTHORITY["EPSG","6313"]], 
    PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], 
    UNIT["degree", 0.017453292519943295], 
    AXIS["Geodetic longitude", EAST], 
    AXIS["Geodetic latitude", NORTH], 
    AUTHORITY["EPSG","4313"]], 
  PROJECTION["Lambert_Conformal_Conic_2SP"], 
  PARAMETER["central_meridian", 4.367486666666666], 
  PARAMETER["latitude_of_origin", 90.0], 
  PARAMETER["standard_parallel_1", 51.166667233333335], 
  PARAMETER["false_easting", 150000.013], 
  PARAMETER["false_northing", 5400088.438], 
  PARAMETER["scale_factor", 1.0], 
  PARAMETER["standard_parallel_2", 49.833333900000014], 
  UNIT["m", 1.0], 
  AXIS["Easting", EAST], 
  AXIS["Northing", NORTH], 
  AUTHORITY["EPSG","31370"]]
  • Using tags to identify what software you are using to accomplish this would be helpful :) – MaryBeth Nov 5 '15 at 21:02
  • It looks like you are missing the closing double quotes on CRS.decode("EPSG:4326) in two cases. – Mintx Nov 5 '15 at 21:19
  • 1
    Can you print out the CRS definitions that are used? It might be that Lambert72 or WGS84 is missing the +towgs84 parameters of the datum shift. – AndreJ Nov 6 '15 at 7:02
  • The missing quotes are a typo :) I'm using Java Oracle 8 and GeoTools 14 (with Eclipse). – AlpacasInSpace Nov 6 '15 at 14:35
  • As far as I can see Lambert72 does contain a towgs84: TOWGS84[-106.8686, 52.2978, -103.7239, 0.3366, 0.457, -1.8422, -1.2747] – AlpacasInSpace Nov 6 '15 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.