Does not look horrible; what is all the parametervaluegroup stuff for? 
Are you defining the UTM coordinate reference system yourself?

Two alternatives for defining the UTM:
- There are lots of UTMs defined already the the EPSG dataset;
- You could represent the UTM information as WKT and parse it

And a suggestion; make sure the incoming positionUTM is constructued 
with the correct coordinate reference system; that
way you can just call the translate method with 
DefaultGeographicCRS.WGS84 and get on with your life.
Jody
> 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
>
>   


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to