如何使用JMapProjLib,Proj4j或Proj4js转换不同坐标系之间的坐标?

时间:2015-02-05 16:18:01

标签: java javascript coordinate-systems wgs84 proj4js

我正在创建一个Android应用程序(使用Java),它将从文件中读取 SWEREF99 TM 坐标,并将它们转换为 WGS84 (long-lat)坐标,并在对面方向。为此,我将使用 JMapProjLib Proj4j Proj4js (我将使用Java访问的JavaScript库{ {1}})。

问题在于我无法弄清楚如何使用这些库,因为文档很少...... 我已经尝试了 JMapProjLib -JavaLibrary,但它没有给我正确的结果,我也尝试过使用 Proj4js 2.3.3 ,但我甚至不能让后面提到的工作......

我正在使用的JavaScript(以及一些HTML)代码,使用 Proj4js 2.3.3 (目前我只在HTML文件中尝试此脚本,因此浏览器应显示转换完成后弹出消息说“完成!”:

ScriptEngine

我正在尝试的Java代码(使用 JMapProjLib ):

<!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 -library包含编译为{{1的git-repository中的文件夹/** * 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; } src/com/jhlabs/map中的内容我使用 Eclipse 文件。

由于 JavaScript -library Proj4js 对我来说看起来更“完美”,我宁愿将它与Java结合使用{{1}所以我现在真正需要的只是某种文档,或者可以向我解释这一点的人。

1 个答案:

答案 0 :(得分:1)