如何使用JMapProjLib、Proj4j或Proj4js在不同坐标系之间进行坐标转换?

How to convert coordinates between different coordinate systems with JMapProjLib, Proj4j or Proj4js?

我正在创建一个 Android 应用程序(使用 Java),它将从文件中读取 SWEREF99 TM 坐标,并将它们转换为WGS84(经纬度)坐标,方向相反。为此,我将使用 JMapProjLibProj4jProj4js(Java我将使用 Java 的 ScriptEngine).

访问的脚本库

问题是由于文档很少,我不知道如何使用这些库...
我已经尝试了 JMapProjLib-JavaLibrary, but it is not giving me the correct result, and I've also tried using Proj4js 2.3.3,但我什至无法让后面提到的工作...

Java脚本(和一些 HTML)我目前使用的代码,Proj4js 2.3.3(目前我只在 HTML 文件中尝试此脚本,因此当转换完成时,浏览器应显示一条弹出消息,提示 "Done!":

<!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 包含文件夹 src/com/jhlabs/mapsrc/coordsys/ 中的内容git-由我使用 Eclipse 编译为 .jar 文件的存储库。

因为 JavaScript-library Proj4js 在我看来 "well-done",我更喜欢将它与 Java ScriptEngine 结合使用,所以我现在真正需要的只是某种文档,或者可以向我解释的人。

您可以查看此存储库并提取您需要的内容:

https://github.com/dsegerss/Sonardrone/tree/master/src/org/sonardrone/proj/positions