{"id":221,"date":"2009-01-04T13:29:34","date_gmt":"2009-01-04T18:29:34","guid":{"rendered":"http:\/\/www.kralidis.ca\/blog\/?p=221"},"modified":"2009-01-04T13:33:19","modified_gmt":"2009-01-04T18:33:19","slug":"really-easy-coordinate-transformation","status":"publish","type":"post","link":"https:\/\/www.kralidis.ca\/blog\/2009\/01\/04\/really-easy-coordinate-transformation\/","title":{"rendered":"Really Easy Coordinate Transformation"},"content":{"rendered":"<p>One of the most frequent questions I get from clients is how to transform lat\/long to LCC coordinates in a very lightweight fashion, in their webapps.\u00a0 There are many solutions and approaches under the <a title=\"MetaCRS\" href=\"http:\/\/wiki.osgeo.org\/wiki\/MetaCRS\">MetaCRS<\/a> umbrella to choose from, depending on your requirements.<\/p>\n<p>Here&#8217;s a super lightweight way to do it with <a title=\"proj4js\" href=\"http:\/\/trac.osgeo.org\/proj4js\/\">proj4js<\/a>:<\/p>\n<pre id=\"line11\">&lt;<span class=\"start-tag\">script<\/span><span class=\"attribute-name\"> <\/span><span class=\"attribute-name\">src<\/span>=<span class=\"attribute-value\">\"http:\/\/svn.osgeo.org\/metacrs\/proj4js\/trunk\/lib\/proj4js-compressed.js\"<\/span>&gt;&lt;\/<span class=\"end-tag\">script<\/span>&gt;\r\n&lt;<span class=\"start-tag\">script<\/span><span class=\"attribute-name\"> <\/span><span class=\"attribute-name\">src<\/span>=<span class=\"attribute-value\">\"http:\/\/svn.osgeo.org\/metacrs\/proj4js\/trunk\/lib\/defs\/EPSG42304.js\"<\/span>&gt;&lt;\/<span class=\"end-tag\">script<\/span>&gt;\r\n\r\n...\r\n\r\nvar x = -75.0;\r\nvar y = 45.0;\r\nvar p = new Proj4js.Point(x,y);\r\nProj4js.transform(new Proj4js.Proj(\"EPSG:4326\"), new Proj4js.Proj(\"EPSG:42304\"), p);\r\nalert(p.x + \" \" + p.y);<\/pre>\n<p>Done!\u00a0 Kudos to <a title=\"Mike Adair\" href=\"http:\/\/wiki.osgeo.org\/wiki\/User:Madair\">Mike Adair<\/a> et. al.!<\/p>\n<link rel=\"stylesheet\" href=\"http:\/\/cdn.leafletjs.com\/leaflet-0.5\/leaflet.css\" \/>\n<!--[if lte IE 8]>\n  <link rel=\"stylesheet\" href=\"http:\/\/cdn.leafletjs.com\/leaflet-0.5\/leaflet.ie.css\" \/>\n<![endif]-->\n<script src=\"http:\/\/cdn.leafletjs.com\/leaflet-0.5\/leaflet.js\"><\/script>\n<style type=\"text\/css\">#map221 { width: 300px; height: 200px; }<\/style>\n\n<div id=\"map221\"><\/div>\n<script type=\"text\/javascript\">\n  var map221 = L.map('map221').setView([43.620495, -79.513198], 10);\n  L.tileLayer('http:\/\/{s}.tile.osm.org\/{z}\/{x}\/{y}.png', {\n      attribution: '&copy; <a href=\"http:\/\/osm.org\/copyright\">OpenStreetMap<\/a> contributors'\n  }).addTo(map221);\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>One of the most frequent questions I get from clients is how to transform lat\/long to LCC coordinates in a very lightweight fashion, in their webapps.\u00a0 There are many solutions and approaches under the MetaCRS umbrella to choose from, depending on your requirements. Here&#8217;s a super lightweight way to do it with proj4js: &lt;script src=&#8221;http:\/\/svn.osgeo.org\/metacrs\/proj4js\/trunk\/lib\/proj4js-compressed.js&#8221;&gt;&lt;\/script&gt; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,7,3,11],"tags":[],"class_list":["post-221","post","type-post","status-publish","format-standard","hentry","category-geospatial","category-open-source","category-technology","category-web"],"_links":{"self":[{"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":8,"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":228,"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/posts\/221\/revisions\/228"}],"wp:attachment":[{"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kralidis.ca\/blog\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}