{"id":1243,"date":"2013-05-27T23:17:24","date_gmt":"2013-05-27T21:17:24","guid":{"rendered":"http:\/\/www.unicoda.com\/?p=1243"},"modified":"2013-05-27T23:29:20","modified_gmt":"2013-05-27T21:29:20","slug":"map-projection-convert-lambert-ii-into-longitudelatitude","status":"publish","type":"post","link":"https:\/\/www.unicoda.com\/?p=1243","title":{"rendered":"Map projection: Convert Lambert II into Longitude\/Latitude"},"content":{"rendered":"<p>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.<\/p>\n<p>I searched for formula, read articles and finally found the library <a href=\"http:\/\/trac.osgeo.org\/proj4js\/\">Proj4Js<\/a> which aim is to transform point coordinates from one coordinate system to another. I searched a little more and found <a href=\"https:\/\/github.com\/temsa\/node-proj4js\">node-proj4js<\/a> a NodeJs port of Proj4Js. What&rsquo;s next?<\/p>\n<p>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\u00a027572. With this number, go to the website <a href=\"http:\/\/spatialreference.org\/ref\/\">http:\/\/spatialreference.org\/ref\/<\/a> and search for your coordinate system using its reference number or its name. For example, the link for Lambert II is <a href=\"http:\/\/spatialreference.org\/ref\/epsg\/27572\/\">http:\/\/spatialreference.org\/ref\/epsg\/27572\/<\/a>.<\/p>\n<p>Once you find it, there is a link for the specification in the Proj4Js format: <a href=\"http:\/\/spatialreference.org\/ref\/epsg\/27572\/proj4js\/\">http:\/\/spatialreference.org\/ref\/epsg\/27572\/proj4js\/<\/a>. Now, just copy and paste the code in proj4js\/lib\/defs under the name EPSG27572 for Lambert II. I&rsquo;m now able to convert Lambert II to Longitude\/Latitude system. Let&rsquo;s see how to do it!<\/p>\n<p>I&rsquo;m adding Proj4Js and initializing source and destination coordinate system:<\/p>\n<pre>var Proj4js = require(\"proj4js\");\r\nvar source = new Proj4js.Proj('EPSG:27572'); \/\/Lambert II\r\nvar destination = new Proj4js.Proj('EPSG:4326'); \/\/Longitude\/Latitude<\/pre>\n<p>Next, we need to create the source point to be used by Proj4Js:<\/p>\n<pre>var xLambertII = 589987;\r\nvar yLambertII = 2424591;\r\nvar point = new Proj4js.Point([xLambertII, yLambertII]);<\/pre>\n<p>Finally, convert from Lambert II to Longitude\/Latitude et print new coordinates:<\/p>\n<pre>var latLon = Proj4js.transform(source, destination, point);\r\nconsole.log('X: ' + latLon.x + ' Y: ' + latLon.y);<\/pre>\n<p>Let&rsquo;s finish this article with a picture about map projections from the well-known <a href=\"http:\/\/xkcd.com\/\">xkcd <\/a>website.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" alt=\"\" src=\"http:\/\/imgs.xkcd.com\/comics\/map_projections.png\" width=\"650\" height=\"1990\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/www.unicoda.com\/?p=1243\" class=\"more-link\">Continuer la lecture<span class=\"screen-reader-text\"> de &laquo;&nbsp;Map projection: Convert Lambert II into Longitude\/Latitude&nbsp;&raquo;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[119,13,118,120,27,117],"class_list":["post-1243","post","type-post","status-publish","format-standard","hentry","category-code","tag-epgs27572","tag-javascript","tag-lambert-ii","tag-longitudelatitude","tag-nodejs","tag-proj4js"],"_links":{"self":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/1243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1243"}],"version-history":[{"count":11,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/1243\/revisions"}],"predecessor-version":[{"id":1256,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/1243\/revisions\/1256"}],"wp:attachment":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}