[GIS] Convert from EPSG:27700 to latitude and longitude

javalatitude longitudeprojwgs84

I'm trying to transform EPSG:27700 coordinates to latitude and longitude. From my research I understand that WGS 84 (EPSG:4326) is the SRS that resembles latitude and longitude.

I'm using Proj4j to try and convert a test coordinate (those familiar with my previous question will recognise Kirkby In Ashfield station).

My Java code snippet:

String projection27700 = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 "
    + "+x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs";
CRSFactory crsFactory = new CRSFactory();
CoordinateReferenceSystem sourceSRS = crsFactory.createFromParameters(null,
    projection27700);

String projection4326 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
CoordinateReferenceSystem targetSRS = crsFactory.createFromParameters(null,
    projection4326);

CoordinateTransform transformation = new BasicCoordinateTransform(sourceSRS,
    targetSRS);

ProjCoordinate result = new ProjCoordinate();
ProjCoordinate input = new ProjCoordinate(450077, 356089);
transformation.transform(input, result);

System.out.println(result.x + ", " + result.y);

The result printed is:

-155.20355661333892, -35.91545136124713

This doesn't seem right – it neither makes sense as degrees or metres (to me at least). Have I missed out a conversion somewhere, either on my input data or in this output data I've produced?

I'm fairly happy my input data is right, based on this documentation, which confirms that +units=m will allow my input data to be in metres. It also suggests the output data should be in degrees, which is what I want.

Best Answer

I haven't solved the original problem, but I've worked around it by using CTS instead.

CRSFactory crsFactory = new CRSFactory();

// Download the data files from Github and place on the class path
RegistryManager registryManager = crsFactory.getRegistryManager();
registryManager.addRegistry(new EPSGRegistry());
CoordinateReferenceSystem crs4326 = crsFactory.getCRS("EPSG:4326");
CoordinateReferenceSystem crs27700 = crsFactory.getCRS("EPSG:27700");

// These ugly casts seem unavoidable
List<CoordinateOperation> operations = CoordinateOperationFactory
    .createCoordinateOperations((GeodeticCRS) crs27700, (GeodeticCRS) crs4326);

double[] result = operations.get(0).transform(new double[] {450077, 356089});
System.out.println(Arrays.toString(result));

This produces:

[-1.2535570562769147, 53.09965984661543]

which is the correct answer.