我有CTS转换坐标的错误。
这是我的代码:
CRSFactory cRSFactory = new CRSFactory();
RegistryManager registryManager = cRSFactory.getRegistryManager();
registryManager.addRegistry(new EPSGRegistry());
CoordinateReferenceSystem crs1 = null;
CoordinateReferenceSystem crs2 = null;
try{
crs1 = (CoordinateReferenceSystem) cRSFactory.getCRS("EPSG:25831");
crs2 = (CoordinateReferenceSystem) cRSFactory.getCRS("EPSG:4326");
}catch (CRSException ie){
System.err.println("CRSException: " + ie.getMessage());
}
GeodeticCRS sourceGCRS = (GeodeticCRS) crs1;
GeodeticCRS targetGCRS = (GeodeticCRS) crs2;
Set<CoordinateOperation> coordOps = null;
try{
coordOps = CoordinateOperationFactory.createCoordinateOperations(sourceGCRS, targetGCRS);
}catch (CoordinateOperationException ie){
System.err.println("CoordinateOperationException: " + ie.getMessage());
}
parts = new String[2];
parts = parts2;
System.out.println("latitud: " + parts[0]);
System.out.println("longitud: " + parts[1]);
double[] coord = new double[2];
boolean isValidDouble = false;
try{
coord[0] = Double.parseDouble(parts[1]);
coord[1] = Double.parseDouble(parts[0]);
isValidDouble = true;
}catch(NumberFormatException eo){
isValidDouble = false;
}
double[] dd = new double[2];
if (coordOps.size() != 0 && isValidDouble == true) {
// Test each transformation method (generally, only one method is available)
//System.out.println("POINT (" + coord[0] + " " + coord[1] + ")");
for (CoordinateOperation op : coordOps) {
// Transform coord using the op CoordinateOperation from crs1 to crs2
try{
dd = op.transform(coord);
}catch (IllegalCoordinateException ie){
System.err.println("IllegalCoordinateException: " + ie.getMessage());
}catch (CoordinateOperationException ie){
System.err.println("CoordinateOperationException: " + ie.getMessage());
}
}
}
System.out.println(getGeometry() + " (" + dd[1] + " " + dd[0] + ")");
这是我的输出:
纬度:932178.5916381918 纵向:4592070.597899773 Point(6.253901743245093E-5 -1.4884056282499645)
预期产出:
纬度:932178.5916381918 纵向:4592070.597899773 Point(8.16641764158 41.3640864715)
PD:我试图将lat / long改为long / lat,这是一个例子,反之亦然。不要做任何改变。
有人有答案吗?
非常感谢!