【问题标题】:Proj.4 Java - convert coordinates from WGS84 to EPSG4141?Proj.4 Java - 将坐标从 WGS84 转换为 EPSG4141?
【发布时间】:2016-12-18 18:50:58
【问题描述】:

我正在使用可以是found here 的 Proj.4 java 库 而且我非常不确定如何在 Proj.4JS 中实现这样的代码:

// include the library
<script src="lib/proj4js-combined.js"></script>  //adjust the path for your server
                                                 //or else use the compressed version
// creating source and destination Proj4js objects
// once initialized, these may be re-used as often as needed
var source = new Proj4js.Proj('EPSG:4326');    //source coordinates will be in Longitude/Latitude, WGS84
var dest = new Proj4js.Proj('EPSG:4141');     //destination coordinates in meters, global spherical mercators projection, see http://spatialreference.org/ref/epsg/3785/


// transforming point coordinates
var p = new Proj4js.Point(-76.0,45.0);   //any object will do as long as it has 'x' and 'y' properties
Proj4js.transform(source, dest, p);      //do the transformation.  x and y are modified in place

//p.x and p.y are now EPSG:3785 in meters

我是整个投影主题的新手,我真的很想知道我在做什么。我需要将我的坐标系从 WGS84 转换为 EPSG:4141,但 Proj.4 Java 库根本没有记录,我真的不知道如何使用它。

有人知道吗?

【问题讨论】:

    标签: java proj


    【解决方案1】:

    不幸的是,该库仍然没有很好的文档记录,所以对于那些仍在寻找解决方案的人来说:

    CRSFactory factory = new CRSFactory();
    CoordinateReferenceSystem srcCrs = factory.createFromName("EPSG:4326");
    CoordinateReferenceSystem dstCrs = factory.createFromName("EPSG:4141");
    
    BasicCoordinateTransform transform = new BasicCoordinateTransform(srcCrs, dstCrs);
    
    // Note these are x, y so lng, lat
    ProjCoordinate srcCoord = new ProjCoordinate(-76.0, 45.0);
    ProjCoordinate dstCoord = new ProjCoordinate();
    
    // Writes result into dstCoord
    transform.transform(srcCoord, dstCoord);
    

    https://github.com/Proj4J/proj4j 的源代码,如果您需要解决其他问题。

    【讨论】:

    • 在使用 geotools 一天后,我终于来到了这里!
    猜你喜欢
    • 2011-01-29
    • 2017-03-08
    • 2016-05-25
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 2019-08-30
    相关资源
    最近更新 更多