4

我正在使用可以在此处找到的 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 库根本没有记录,我真的不知道如何使用它。

有人熟悉这个吗?

4

1 回答 1

7

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

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的源代码,如果您需要解决其他问题。

于 2017-11-16T02:11:07.310 回答