From: Diego F. <di...@go...> - 2008-01-29 12:18:08
|
Hi: Is this the right way to do UTM -> Long/Lat conversion? -- CODE START public DirectPosition UTMtoLatLong(DirectPosition positionUTM) { DirectPosition positionLatLong = null; GeographicCRS geoCRS = DefaultGeographicCRS.WGS84; CartesianCS cartCS = DefaultCartesianCS.GENERIC_2D; MathTransformFactory mtFactory = FactoryFinder.getMathTransformFactory(null); FactoryGroup factories = new FactoryGroup(null); try { ParameterValueGroup parameters = mtFactory.getDefaultParameters("Mercator_1SP"); parameters.parameter("scale_factor").setValue(0.9996); //parameters.parameter("scale_factor").setValue(1.000); //parameters.parameter("central_meridian").setValue(0.0); //parameters.parameter("latitude_of_origin").setValue(0.0); parameters.parameter("false_easting").setValue(500000.0); //parameters.parameter("false_northing").setValue(0.0); Map properties = Collections.singletonMap("name", "WGS 84 / Mercator_1SP"); ProjectedCRS projCRS = factories.createProjectedCRS(properties, geoCRS, null, parameters, cartCS); CoordinateOperationFactory coFactory = FactoryFinder.getCoordinateOperationFactory(null); CoordinateReferenceSystem sourceCRS = geoCRS; CoordinateReferenceSystem targetCRS = projCRS; CoordinateOperation op = coFactory.createOperation(sourceCRS, targetCRS); MathTransform mtLatLong2UTM = op.getMathTransform(); //System.out.println("Math Transform: " + mtLatLong2UTM.toWKT()); MathTransform mtUTM2LatLong = mtLatLong2UTM.inverse(); positionLatLong = mtUTM2LatLong.transform(positionUTM, null); } catch (Exception ex) { System.err.println(ex.getMessage()); } return positionLatLong; } -- CODE END -- Diego Fdez. Durán <di...@go...> | http://www.goedi.net GPG : 925C 9A21 7A11 3B13 6E43 50DB F579 D119 90D2 66BB |