Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## geotools-gt2-users

 [Geotools-gt2-users] Re: [Geotools-devel] Help, Please - UTM <-> WGS84 Coordinate Transformations From: Martin Desruisseaux - 2004-02-03 12:27:57 ```Hello Grange, John a =E9crit : > I need some sample code for doing transformations between utm=20 > coordinates (Irish National Grid, Saudi National Grid, etc...) and WGS8= 4. The steps are: 1) Gets the source coordinate system. This is the most difficult part. You can construct the CS by hand using the API, but it is tedious. An easier solution is to use EPSG database (http://www.epsg.org). Click on "Browse Coordinate Reference System" and search for "Irish" in the "name and code" field. Once you have found the CRS you are looking for, note its code (for example 2157 for "IRENET95 / Irish Transverse Mercator"). Then use the following: CoordinateSystemAuthorityFactory factory =3D=20 CoordinateSystemESPGFactory.getDefault(); CoordinateSystem sourceCS =3D factory.createCoordinateSystem("2157"); (note: you can try the following from the command line if you just want to test if it works: java org.geotools.cs.CoordinateSystemEPSGFactory 2157 2) Gets the target coordinate system. Can be done in the same way than 1. But in yours case, it is simply: CoordinateSystem targetCS =3D GeographicCoordinateSystem.WGS84; 3) Gets the transformation from sourceCS to targetCS: CoordinateTransformation tr =3D=20 CoordinateTransformationFactory.getDefault().createFromCoordinateSystems(= sourceCS,=20 targetCS); 4) Use the MathTransform (from tr.getMathTransform()) for appyling the transformations. Note: if you know for sure that source and target CS are both two-dimensional, you can cast the transform to MathTransform2D, which provides some convenient API for use with Java2D. There is a demo using hand-constructed CS (not from the EPSG database)=20 on the CVS tree. You can browse it here: http://cvs.sourceforge.net/viewcvs.py/geotools/geotools2/geotools-src/cts= -coordtrans/demo/TransformationConsole.java?rev=3D1.3&view=3Dauto (this demo will be moved in an other directory later). Regards Martin. ```
 Re: [Geotools-gt2-users] Re: [Geotools-devel] Help, Please - UTM <-> WGS84 Coordinate Transformations From: Rueben Schulz - 2004-02-04 04:56:46 ```Hi, To add to Martin's help: Another way to quickly create a coordinate system object (easier than by hand) is to use the CoordinateSystemFactory::createFromWKT(wkt) method. An example of a well known text string for UTM (with annoying escapes) is: String wkt =3D "PROJCS[\"UTM_Zone_10N\", GEOGCS[\"WGS84\", DATUM[\"WGS84\", SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], PRIMEM[\"Greenwich\", 0.0], UNIT[\"degree\",0.017453292519943295], AXIS[\"Longitude\",EAST], AXIS[\"Latitude\",NORTH]], PROJECTION[\"Transverse_Mercator\"], PARAMETER[\"semi_major\", 6378137.0], PARAMETER[\"semi_minor\", 6356752.314245179], PARAMETER[\"central_meridian\", -123.0], PARAMETER[\"latitude_of_origin\", 0.0], PARAMETER[\"scale_factor\", 0.9996], PARAMETER[\"false_easting\", 500000.0], PARAMETER[\"false_northing\", 0.0], UNIT[\"metre\",1.0], AXIS[\"x\",EAST], AXIS[\"y\",NORTH]]"; For more wkt examples, see the test scripts in geotools-src/cts-coordtrans/tests/unit/test-data. Usually it is just a matter of copying them and changing a few parameters. Rueben On Tue, 2004-02-03 at 04:25, Martin Desruisseaux wrote: > Hello >=20 > Grange, John a =E9crit : >=20 > > I need some sample code for doing transformations between utm=20 > > coordinates (Irish National Grid, Saudi National Grid, etc...) and WG= S84. >=20 > The steps are: >=20 > 1) Gets the source coordinate system. This is the most difficult part. > You can construct the CS by hand using the API, but it is tedious. > An easier solution is to use EPSG database (http://www.epsg.org). > Click on "Browse Coordinate Reference System" and search for "Irish= " > in the "name and code" field. Once you have found the CRS you are > looking for, note its code (for example 2157 for "IRENET95 / Irish > Transverse Mercator"). Then use the following: >=20 > CoordinateSystemAuthorityFactory factory =3D=20 > CoordinateSystemESPGFactory.getDefault(); > CoordinateSystem sourceCS =3D factory.createCoordinateSystem("2157"= ); >=20 > (note: you can try the following from the command line if you just > want to test if it works: >=20 > java org.geotools.cs.CoordinateSystemEPSGFactory 2157 >=20 >=20 > 2) Gets the target coordinate system. Can be done in the same way than > 1. But in yours case, it is simply: >=20 > CoordinateSystem targetCS =3D GeographicCoordinateSystem.WGS84; >=20 >=20 > 3) Gets the transformation from sourceCS to targetCS: >=20 > CoordinateTransformation tr =3D=20 > CoordinateTransformationFactory.getDefault().createFromCoordinateSystem= s(sourceCS,=20 > targetCS); >=20 >=20 > 4) Use the MathTransform (from tr.getMathTransform()) for appyling > the transformations. Note: if you know for sure that source and > target CS are both two-dimensional, you can cast the transform > to MathTransform2D, which provides some convenient API for use > with Java2D. >=20 >=20 > There is a demo using hand-constructed CS (not from the EPSG database)=20 > on the CVS tree. You can browse it here: >=20 > http://cvs.sourceforge.net/viewcvs.py/geotools/geotools2/geotools-src/c= ts-coordtrans/demo/TransformationConsole.java?rev=3D1.3&view=3Dauto >=20 > (this demo will be moved in an other directory later). >=20 > Regards >=20 > Martin. >=20 >=20 >=20 >=20 > ------------------------------------------------------- > The SF.Net email is sponsored by EclipseCon 2004 > Premiere Conference on Open Tools Development and Integration > See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. > http://www.eclipsecon.org/osdn > _______________________________________________ > Geotools-gt2-users mailing list > Geotools-gt2-users@... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users ```