我正在使用Proj.4 Java库,它可以是found here
而且我不确定如何在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库完全没有记录,我无法真正找到如何使用它。
有人熟悉吗?
最佳答案
不幸的是,该库仍然没有很好的文档记录,因此对于那些仍在寻找解决方案的人:
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的源代码。