3

I'm currently testing a web app that calculates EPSG:2163 coordinates based on user interaction with a map created through d3.js. I wish to convert these coordinates to WGS84 in order to use various APIs whose parameters are in the form of WGS84 coordinates. Is there an simple formula or javascript library that can do this?

To further clarify, the map seen http://spatialreference.org/ref/epsg/2163/ takes WGS84 coordinates as input and converts them to EPSG:2163. All I want to do is reverse that calculation.

EDIT

Here's an example, however, I'm not convinced I'm getting correct results. I started with WGS84 coordinates and projected them to epsg:2163 using cs2cs. In the Javascript I transform the epsg:2163 coordinates back to WGS84, but as you will see, they don't end up the same as my starting coordinates. I'm a little puzzled, myself, and I sure could have botched a step:

<html>
<head>
<script src="proj4js/lib/proj4js-compressed.js"></script>
<!-- Omit the next line if you don't mind requesting the parameters for EPSG:2163 from spatialreference.org -->
<script src="proj4js/lib/defs/EPSG2163.js"></script>
<script>
// Transformed these WGS84 coordinates in cs2cs to produce EPSG:2163 coordinates in "coords"
    var coords84 = [ 
[-98.0, 29.0],
[-101.2, 30.8],
[-102.1, 27.4],
[-97.8, 30.2]
];
    var coords = [ 
[196396.96, -1771089.12],
[-115495.45, -1574127.29],
[-209758.25, -1946836.60],
[213174.20, -1638406.38]
];
    var src = new Proj4js.Proj('EPSG:2163');
    var dest = new Proj4js.Proj('EPSG:4326');

function project() {
    for(var inx=0;inx<coords.length;inx++) {
        pt = new Proj4js.Point(coords[inx][0],coords[inx][1]);
        Proj4js.transform(src,dest,pt);
        document.body.innerHTML += ("<p>Proj4js:" + pt.x + ", " + pt.y + "</p>");
        document.body.innerHTML += ("<p>Expected:" + coords84[inx][0] + ", " +  coords84[inx][1] + "</p>");
    }
}
</script>
</head>
<body>
<input type="button" value="Project" onclick="javascript:project();" />
</body>
</html>

1 Answer 1

6

If you don't mind using an external library, Proj4js may address your requirements here. Following the UserGuide example, your destination "projection" would be 'EPSG:4326'.

2
  • +1 This advice is 100% appropriate. @Dave can you provide a snippet/example to demonstrate its application?
    – elrobis
    Commented Apr 19, 2013 at 2:11
  • This library looks exactly what I'm looking for, however I am unable to even create Proj4js objects without my code stalling. Looking further into the source code of the Proj4js, I figured out I could make my own rough estimation of the conversion (using 2163's given center and scaling) for now until I figure out how to properly use Proj4js
    – nick
    Commented Apr 19, 2013 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.