Thursday 4 May 2017

coordinate system - geotools / jts crs transformation result not at correct position


I copied the example from geotools, which shows how to transform a shapefile into a different projection. (http://docs.geotools.org/latest/userguide/tutorial/geometry/geometrycrs.html) But when transforming from Gauss Krueger 4 into Pseudo Mercator (3857) the shapes are not at the correct position, they are displaced several meters.


What can I do to fix this?


The sample code contains :


 CoordinateReferenceSystem dataCRS = schema.getCoordinateReferenceSystem();
CoordinateReferenceSystem worldCRS = map.getCoordinateReferenceSystem();
boolean lenient = true; // allow for some error due to different datums
MathTransform transform = CRS.findMathTransform(dataCRS, worldCRS, lenient);


... and then ...


Geometry geometry2 = JTS.transform(geometry, transform);

additional information:


The sample data of the source as the following CRS


PROJCS["PD_83_3_degree_Gauss_Kruger_zone_4", 
GEOGCS["GCS_PD/83",
DATUM["D_Potsdam_Datum_83",
SPHEROID["Bessel_1841", 6377397.155, 299.1528128]],
PRIMEM["Greenwich", 0.0],

UNIT["degree", 0.017453292519943295],
AXIS["Longitude", EAST],
AXIS["Latitude", NORTH]],
PROJECTION["Transverse_Mercator"],
PARAMETER["central_meridian", 12.0],
PARAMETER["latitude_of_origin", 0.0],
PARAMETER["scale_factor", 1.0],
PARAMETER["false_easting", 4500000.0],
PARAMETER["false_northing", 0.0],
UNIT["m", 1.0],

AXIS["x", EAST],
AXIS["y", NORTH]]

and the target has the following CRS:


PROJCS["WGS 84 / Pseudo-Mercator", 
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"]],
PROJECTION["Popular Visualisation Pseudo Mercator"],
PARAMETER["semi_minor", 6378137.0],
PARAMETER["latitude_of_origin", 0.0],
PARAMETER["central_meridian", 0.0],
PARAMETER["scale_factor", 1.0],
PARAMETER["false_easting", 0.0],

PARAMETER["false_northing", 0.0],
UNIT["m", 1.0],
AXIS["Easting", EAST],
AXIS["Northing", NORTH],
AUTHORITY["EPSG","3857"]]

Any idea? D3



Answer



Meanwhile I learned that I have to use the Bursa Wolf parameters for a precise transformation between shapes with different datum. The required parameters are in the Geotools hsql database, which can be 'queried' by CRS.decode().


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...