Really Easy Coordinate Transformation

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.  There are many solutions and approaches under the MetaCRS umbrella to choose from, depending on your requirements.

Here’s a super lightweight way to do it with proj4js:

<script src="http://svn.osgeo.org/metacrs/proj4js/trunk/lib/proj4js-compressed.js"></script>
<script src="http://svn.osgeo.org/metacrs/proj4js/trunk/lib/defs/EPSG42304.js"></script>

...

var x = -75.0;
var y = 45.0;
var p = new Proj4js.Point(x,y);
Proj4js.transform(new Proj4js.Proj("EPSG:4326"), new Proj4js.Proj("EPSG:42304"), p);
alert(p.x + " " + p.y);

Done!  Kudos to Mike Adair et. al.!

2 Comments so far »

  1. Howard Butler said,

    Wrote on January 4, 2009 @ 19:59:27

    Mozilla Firefox 3.0.5 Mac OS X 10

    Do people normally link out of OSGeo’s SVN for doing Proj4js stuff rather than caching their own local copy?

    Posted from United States United States
    Mozilla Firefox 3.0.5 Mac OS X 10
  2. tomkralidis said,

    Wrote on January 4, 2009 @ 20:23:32

    Mozilla Firefox 3.0.4 Mac OS X 10

    Some people (those of us who live off proof of concepts/demos) live on the edge 🙂

    Yes, good point. Folks would want to fetch a local copy (latest stable for that matter) for performance and stable codebase.

    Posted from Canada Canada
    Mozilla Firefox 3.0.4 Mac OS X 10

Comment RSS · TrackBack URI

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Comment:

Modified: 4 January 2009 13:33:19 EST