> A 10 kilometers error is not an accuracy problem. There is a bug or a
> missing parameter somewhere... Could you post a small (but complete)
> code reproducing this issue please?
There seems to be some improvement compared to the last values I posted. But
unfortunately I do not really remember what I changed. Perhaps I have had an
error with the input data. Find the complete class below.
-------------
import org.geotools.geometry.DirectPosition2D;
import org.geotools.referencing.FactoryFinder;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CRSFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.CoordinateOperation;
import org.opengis.referencing.operation.CoordinateOperationFactory;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import org.opengis.spatialschema.geometry.DirectPosition;
import org.opengis.spatialschema.geometry.MismatchedDimensionException;
/**
*
*
* @author Michael Duergner
*/
public class CoordsTransformer {
/**
*
* @param args
*/
public static void main(String[] args) {
String location = "48.136018:11.620958";
System.out.println("Incoming location: " +location);
String[] locationArray = location.split(":");
double c0 = new Double(locationArray[0]);
double c1 = new Double(locationArray[1]);
try {
MathTransform transform = getWGS84ToGK();
DirectPosition point1 = new
DirectPosition2D(DefaultGeographicCRS.WGS84,c1,c0);
DirectPosition point2 = new
DirectPosition2D(CoordsTransformer.getGKFromWKT());
point2 = transform.transform(point1,point2);
System.out.println("Gauss-Krueger point: "+point2);
}
catch (FactoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (MismatchedDimensionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (TransformException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @return
* @throws FactoryException
*/
public static MathTransform getWGS84ToGK() throws FactoryException {
CoordinateOperationFactory operationFactory =
FactoryFinder.getCoordinateOperationFactory(null);
CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84;
System.out.println(sourceCRS.toWKT());
CoordinateReferenceSystem targetCRS = CoordsTransformer.getGKFromWKT();
System.out.println(targetCRS);
CoordinateOperation operation =
operationFactory.createOperation(sourceCRS,targetCRS);
System.out.println(operation.getMathTransform().toWKT());
return operation.getMathTransform();
}
/**
*
* @return
* @throws FactoryException
*/
public static CoordinateReferenceSystem getGKFromWKT() throws
FactoryException {
String wkt = "PROJCS[\"GK_Zone_4N\", "
+ "GEOGCS[\"DE_DHDN\", "
+ "DATUM[\"DE_DHDN\", "
+ "SPHEROID[\"Bessel 1841\", 6377397.155, 299.15281285,
AUTHORITY[\"EPSG\",\"31467\"]], "
+ "TOWGS84[-231.89,101.34,27.23,-0.61,0.17,-0.93,1.84],
AUTHORITY[\"EPSG\",\"6326\"]], "
+ "PRIMEM[\"Greenwich\", 0.0], "
+ "UNIT[\"degree\",0.017453292519943295], "
+ "AXIS[\"Longitude\",EAST], "
+ "AXIS[\"Latitude\",NORTH]], "
+ "PROJECTION[\"Transverse_Mercator\"], "
+ "PARAMETER[\"semi_major\", 6377397.1550], "
+ "PARAMETER[\"semi_minor\", 6356078.9633], "
+ "PARAMETER[\"central_meridian\", 12], "
+ "PARAMETER[\"latitude_of_origin\", 0.0], "
+ "PARAMETER[\"scale_factor\", 1.0], "
+ "PARAMETER[\"false_easting\", 4500000.0], "
+ "PARAMETER[\"false_northing\", 0.0], "
+ "UNIT[\"metre\",1.0], "
+ "AXIS[\"x\",EAST], "
+ "AXIS[\"y\",NORTH]]";
CRSFactory crsFactory = FactoryFinder.getCRSFactory(null);
return crsFactory.createFromWKT(wkt);
}
}
-------------
--
With kind regards
Michael Duergner
Student
Department of Computer Science (http://www.ifi.lmu.de)
Ludwig-Maximilians University Munich
Center for Digital Technology and Management (http://www.cdtm.de)
Ludwig-Maximilians University and Technical University Munich
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users