我正在创建一个 Android 应用程序(使用 Java),它将从文件中读取SWEREF99 TM坐标,并将它们转换为WGS84(经纬度)坐标,并且方向相反。为此,我将使用JMapProjLib、Proj4j或Proj4js(我将使用 Java 访问的 JavaScript 库ScriptEngine
)。
问题是我无法弄清楚如何使用这些库,因为文档很少......
我已经尝试过JMapProjLib -JavaLibrary,但它没有给我正确的结果,我也尝试过使用Proj4js 2.3.3,但我什至无法让后面提到的工作......
我目前正在使用的 JavaScript(和一些 HTML)代码,带有Proj4js 2.3.3(目前我只在 HTML 文件中尝试这个脚本,所以浏览器应该显示一个弹出消息说“完成!”当转换完成):
<!DOCTYPE html>
<html>
<head>
<title>Proj4js Testing</title>
</head>
<body onload="convertCoordinates()">
<script type"text/javascript" src="proj4js.js"></script>
<script type="text/javascript">
// Convert coordinates
function convertCoordinates()
// Define the target projection (SWEREF99 TM)
var targetProjection = "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
// Convert the WGS84 coordinates Lon: 15 and Lat: 55 to SWEREF99 TM coordinates
proj4(targetProjection, [15, 55]);
// Just show an alert message telling that the code has executed properly
alert("Done!");
}
</script>
</body>
</html>
我正在尝试的Java代码(使用JMapProjLib):
/**
* Convert a long-lat coordinate to a SWEREF99 TM coordinate.
*
* @param longLatCoordinate The long-lat coordinate to convert.
*
* @return The converted SWEREF99 TM coordinate.
*/
public static SWEREF99TMCoordinate longLatToSWEREF99TM(LongLatCoordinate longLatCoordinate) {
// Create a new SWEREF99 TM projection
Projection projection = ProjectionFactory.fromPROJ4Specification(new String[] {
"+proj=tmerc",
"+zone=33",
"+ellps=GRS80",
"+towgs84=0,0,0,0,0,0,0",
"+units=m",
"+no_defs"
});
// Convert the LongLatCoordinate to a Point2D.Double
Point2D.Double longLatPoint = new Point2D.Double(longLatCoordinate.getLongitude(), longLatCoordinate.getLatitude());
// Get the location as a SWEREF99 TM Point2D.Double
Point2D.Double sweref99TMPoint = projection.transform(longLatPoint, new Point2D.Double());
// COnvert the location to a SWEREF99TMCoordinate
SWEREF99TMCoordinate sweref99TMCoordinate = new SWEREF99TMCoordinate(sweref99TMPoint.x, sweref99TMPoint.y);
// Return the projected coordinate
return sweref99TMCoordinate;
}
引用到我的 Java 项目的JMapProjLib -library 由我使用Eclipsesrc/com/jhlabs/map
编译为文件的文件夹和src/coordsys/
git-repository 中的内容组成。.jar
由于JavaScript库 Proj4js对我来说看起来更“做得好”,我更喜欢将它与 Java 结合使用ScriptEngine
,所以我现在真正需要的只是某种文档,或者可以向我解释这一点的人。