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.
bonjour d’abord je tien a vous félicité pour l’astusse que vous venez de publier sa fait 5 mois que je la cherche mais sans successe :( et vous me donnée maintenant espoir ^^ et sa ma paru utile le souci que j’ai suivi votre tuto mais sa na pas fait de conversion peut être que je l’ai mal configuré, je vous demande si c possible de me fournir l’astuss possible pour faire la conversion de « latitude longitude google maps » en « Lambert Maroc » et vis versa
je vous tien reconnaissant et merci d’avance
Bonjour,
En fait, il s’avère que le format Proj4Js pour les Lambert Maroc avec les codes SR-ORG:4713, SR-ORG:4714, SR-ORG:4715, SR-ORG:4716 n’est malheureusement pas défini sur spatialreference. On trouve seulement Proj4js.defs[« SR-ORG:4713 »] = « »; .
La seule définition complétée est celle des Lambert I Nord Maroc, sous le code SR-ORG:41 (http://spatialreference.org/ref/sr-org/41/): Proj4js.defs[« SR-ORG:41 »] = « +proj=lcc +lat_1=31.73 +lat_2=34.87 +lat_0=33.3 +lon_0=-5.4 +x_0=500000 +y_0=300000 +a=6378249.2 +b=6356514.999904194 +units=m +no_defs »;
Je pense que c’est la raison principale de l’absence de conversion.