我正在嘗試使用 GeoTools 在兩個坐標系之間進行轉換,一個以米為單位,另一個以度為單位,但無論我嘗試什么,轉換后的值都不正確。我曾嘗試使用相同的代碼遵循其他示例,但由于某種原因,它無法在這兩個坐標系之間進行轉換:[EPSG:3044] -> [EPSG:4326] (WGS 84)
我正在決議WKT兩個 CRS,然后使用 GeoTools 對其進行轉換 - 以下是我當前的代碼以及我的結果:
編輯源代碼已更新以反映使用 WKT 和內部 CRS 解碼器的輸出。
val sourceCRS = CRS.parseWKT(
"""PROJCS["ETRS89 / UTM zone 32N (N-E)",
| GEOGCS["ETRS89",
| DATUM["European_Terrestrial_Reference_System_1989",
| SPHEROID["GRS 1980",6378137,298.257222101,
| AUTHORITY["EPSG","7019"]],
| TOWGS84[0,0,0,0,0,0,0],
| AUTHORITY["EPSG","6258"]],
| PRIMEM["Greenwich",0,
| AUTHORITY["EPSG","8901"]],
| UNIT["degree",0.0174532925199433,
| AUTHORITY["EPSG","9122"]],
| AUTHORITY["EPSG","4258"]],
| PROJECTION["Transverse_Mercator"],
| PARAMETER["latitude_of_origin",0],
| PARAMETER["central_meridian",9],
| PARAMETER["scale_factor",0.9996],
| PARAMETER["false_easting",500000],
| PARAMETER["false_northing",0],
| UNIT["metre",1,
| AUTHORITY["EPSG","9001"]],
| AUTHORITY["EPSG","3044"]]""".stripMargin)
val targetCRS = CRS.parseWKT(
"""
|GEOGCS["WGS 84",
| DATUM["WGS_1984",
| SPHEROID["WGS 84",6378137,298.257223563,
| AUTHORITY["EPSG","7030"]],
| AUTHORITY["EPSG","6326"]],
| PRIMEM["Greenwich",0,
| AUTHORITY["EPSG","8901"]],
| UNIT["degree",0.0174532925199433,
| AUTHORITY["EPSG","9122"]],
| AUTHORITY["EPSG","4326"]]
|""".stripMargin)
val source = CRS.decode("EPSG:3044");
val target = CRS.decode("EPSG:4326");
val originalCoordinate = new Coordinate(5293975.04, 959436.64)
// WKT
val coordinateWKT = new Coordinate()
val wktTransform = CRS.findMathTransform(sourceCRS, targetCRS, true)
JTS.transform(originalCoordinate, coordinateWKT, wktTransform)
// EPSG
val coordinateEPSG = new Coordinate()
val epsgTransform = CRS.findMathTransform(source, target, true);
JTS.transform(originalCoordinate, coordinateEPSG, epsgTransform);
// Output
System.out.println(s"Original: ${originalCoordinate}")
System.out.println(s"EKT: ${coordinateWKT}")
System.out.println(s"EPSG: ${coordinateEPSG}")
我的輸入和輸出坐標是:
Original: (5293975.04, 959436.64, NaN)
EKT: (48.79550725975144, 6.678848738740256, NaN)
EPSG: (47.63578358581114, 15.117187455070956, NaN)
uj5u.com熱心網友回復:
所以正確的變換坐標是:(56.4336819°, 4.1353377°)
也許您的源坐標不準確,因為它不在使用坐標系的區域內。
來自 epsg.io:
使用區域:歐洲 6°E 至 12°E:奧地利;比利時; 丹麥 - 在岸和離岸;德國 - 在岸和離岸;挪威包括 - 陸上和海上;西班牙 - 離岸
您的坐標位于非洲以東,在印度洋。
例如,如果我使用來自奧地利的坐標,我會得到以下輸出(在 Java 中):
CoordinateReferenceSystem source = CRS.decode("EPSG:25832");
CoordinateReferenceSystem target = CRS.decode("EPSG:4326");
Coordinate coordinate = new Coordinate(959436.64, 5293975.04);
// when you are using EPSG:3044, you have to change x and y:
// Coordinate coordinate = new Coordinate(5293975.04, 959436.64);
MathTransform transform = CRS.findMathTransform(source, target, false);
JTS.transform(coordinate, coordinate, transform);
System.out.println(coordinate); //(47.63578358581114, 15.117187455070956, NaN)
這與 epsg.io 的結果相同。請注意,我使用的是 EPSG:25832 而不是 EPSG:3044。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/372772.html
