Last week, I faced an interesting problem. I was given a file containing the geographical position of various antennas around Disneyland Paris. The idea was to display them on a map: Open Street Map or Google Maps or whatever. Fine. In order to place the antenna on the map, I must use their coordinates in terms of latitude and longitude. But all coordinates are expressed in Lambert II. So I had to convert Lambert II into Longitude/Latitude.
I searched for formula, read articles and finally found the library Proj4Js which aim is to transform point coordinates from one coordinate system to another. I searched a little more and found node-proj4js a NodeJs port of Proj4Js. What’s next?
I found out that Lambert II conversion is not available by default. You had to add its specification in the Proj4Js format, which is pretty easy when you discover how to do it. First, you need to know the EPSG reference number of the coordinate system. Lambert II EPSG number is 27572. With this number, go to the website http://spatialreference.org/ref/ and search for your coordinate system using its reference number or its name. For example, the link for Lambert II is http://spatialreference.org/ref/epsg/27572/.
Once you find it, there is a link for the specification in the Proj4Js format: http://spatialreference.org/ref/epsg/27572/proj4js/. Now, just copy and paste the code in proj4js/lib/defs under the name EPSG27572 for Lambert II. I’m now able to convert Lambert II to Longitude/Latitude system. Let’s see how to do it!
I’m adding Proj4Js and initializing source and destination coordinate system:
var Proj4js = require("proj4js"); var source = new Proj4js.Proj('EPSG:27572'); //Lambert II var destination = new Proj4js.Proj('EPSG:4326'); //Longitude/Latitude
Next, we need to create the source point to be used by Proj4Js:
var xLambertII = 589987; var yLambertII = 2424591; var point = new Proj4js.Point([xLambertII, yLambertII]);
Finally, convert from Lambert II to Longitude/Latitude et print new coordinates:
var latLon = Proj4js.transform(source, destination, point); console.log('X: ' + latLon.x + ' Y: ' + latLon.y);
Let’s finish this article with a picture about map projections from the well-known xkcd website.