【问题标题】:How to convert coordinates between different coordinate systems with JMapProjLib, Proj4j or Proj4js?如何使用 JMapProjLib、Proj4j 或 Proj4js 在不同坐标系之间转换坐标?
【发布时间】:2015-04-05 14:22:01
【问题描述】:

我正在创建一个 Android 应用(使用 Java),它将从文件中读取 SWEREF99 TM 坐标,并将它们转换为 WGS84(long-lat)坐标,反方向。为此,我将使用 JMapProjLibProj4jProj4js(我将使用 Java 的 @ 访问的 JavaScript 库987654326@).

问题是由于文档很少,我不知道如何使用这些库...
我试过 JMapProjLib-JavaLibrary,但它没有给我正确的结果,我也试过使用 Proj4js 2.3.3,但我不能甚至不能让后面提到的工作......

我目前正在使用的 JavaScript(和一些 HTML)代码,带有 Proj4js 2.3.3(目前我只在 HTML 文件中尝试这个脚本,所以浏览器应该会显示一个 pop-转换完成时显示“完成!”的消息):

<!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-库包含 git-repository 中的文件夹 src/com/jhlabs/mapsrc/coordsys/ 中的内容,使用 Eclipse,我做的。

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

【问题讨论】:

    标签: java javascript coordinate-systems wgs84 proj4js


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-08-29
      • 2011-09-29
      • 2015-07-07
      • 1970-01-01
      • 2011-04-30
      • 2021-02-20
      • 1970-01-01
      • 2019-10-08
      • 1970-01-01
      相关资源
      最近更新 更多