Proj.4 Java - convert coordinates from WGS84 to EPSG4141?

拟墨画扇 提交于 2019-12-12 17:51:30

问题


I am using the Proj.4 java library that can be found here And I am pretty much unsure on how can I implement a code that looks like this in 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

I am new to the whole projection subjects and I really want to know what am I doing. I need to convert my coordinate system from WGS84 to EPSG:4141 but Proj.4 Java library is not documented at all and I can't really find out on how to use it.

Is anyone familiar with this?


回答1:


Unfortunately the library is still not well documented so for those still searching for a solution:

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);

Source code at https://github.com/Proj4J/proj4j if you need to figure anything else out.



来源:https://stackoverflow.com/questions/38906402/proj-4-java-convert-coordinates-from-wgs84-to-epsg4141

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!