Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

proj

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?

like image 599
Artemkller545 Avatar asked Mar 12 '23 10:03

Artemkller545


1 Answers

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.

like image 66
ekarcnevets Avatar answered Mar 23 '23 04:03

ekarcnevets