Hello all,

I'm new to GeoTools, which I want to use for coordinate 
transformation/conversion. So I tried to write a first "HelloWorld"-kinded 
Java-Programm as listed below.

To do this, I obviously need - at runtime - the following jars:

geoapi
gt-api
gt-epsg-hsql
gt-epsg-wkt
gt-metadata
gt-referencing
hsqldb
jsr
jts
vecmath

That  is in GT 2.4 I use:

geoapi-nogenerics-2.1.0.jar
gt2-api-2.4.4.jar
gt2-epsg-hsql-2.4.4.jar
gt2-epsg-wkt-2.4.4.jar
gt2-metadata-2.4.4.jar
gt2-referencing-2.4.4.jar
hsqldb-1.8.0.7.jar
jts-1.8.jar
vecmath" value="vecmath-1.3.1.jar
jsr108-0.01.jar

Working with GT 2.4 I get the expected results:

   (5.5, 51.5, NaN)--(2465319.9084173385, 5707389.990091773, NaN)
   Geom-x=2465319.9084173385 Geom-y=5707389.990091773 Geom-z=NaN


But if I use the corresponding jars delivered with GT 2.5 I get obviusly wrong 
results:

   (5.5, 51.5, NaN)--(8160251.446339277, 866025.4670919782, NaN)
   Geom-x=8160251.446339277 Geom-y=866025.4670919782 Geom-z=NaN

In that case I'm using:

geoapi-2.2-M1.jar
gt-api-2.5-RC0.jar
gt-epsg-hsql-2.5-RC0.jar
gt-epsg-wkt-2.5-RC0.jar
gt-metadata-2.5-RC0.jar
gt-referencing-2.5-RC0.jar
hsqldb-1.8.0.7.jar
jts-1.9.jar
vecmath-1.3.1.jar
jsr-275-1.0-beta-2.jar
Could anybody tell me what I'm doing wrong?

Greetings
Erich


// code:
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
public class myTest {
   public static void main(String [] args) {
                // TODO Auto-generated method stub

                
                CoordinateReferenceSystem srIn  = null;
                CoordinateReferenceSystem srOut = null;
                try {
                        srIn  = CRS.decode( "EPSG:4326" );  // WGS84
                        System.out.println(srIn.getName());
                        srOut = CRS.decode( "EPSG:31462" );  // GK2
                        System.out.println(srOut.getName());
                        System.out.println(srOut.toWKT());

                        MathTransform trans = CRS.findMathTransform(srIn, 
srOut, true);
                        
                        Coordinate oCoor = new Coordinate( 5.5, 51.5);
                        Coordinate nCoor = null;
                        GeometryFactory gf = new GeometryFactory();
                        Point oP = gf.createPoint( oCoor );                     
                        
                        try {
                                // 1st try
                                nCoor = JTS.transform(oCoor, nCoor, trans);
                                if (nCoor != null) {
                                        System.out.println(oCoor.toString() + 
"--" + nCoor.toString());
                                }
                                else
                                        System.out.println("Failure!");

                                // 2nd try
                                Geometry geom = JTS.transform(oP, trans);
                                System.out.println("Geom-x=" + 
geom.getCoordinate().x + " Geom-y=" + geom.getCoordinate().y + " Geom-z=" + 
geom.getCoordinate().z);
                                
                        } catch (TransformException e) {
                                e.printStackTrace();
                        }
                } catch (NoSuchAuthorityCodeException e) {
                        e.printStackTrace();
                } catch (FactoryException e) {
                        e.printStackTrace();
                }
}
_________________________________________________________________________
In 5 Schritten zur eigenen Homepage. Jetzt Domain sichern und gestalten! 
Nur 3,99 EUR/Monat! http://www.maildomain.web.de/?mc=021114


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to