Skip to content

Instantly share code, notes, and snippets.

@stephanbogner
Created July 18, 2017 11:34
Show Gist options
  • Save stephanbogner/88bb95fe4f84b65fcc9bbede12af4f03 to your computer and use it in GitHub Desktop.
Save stephanbogner/88bb95fe4f84b65fcc9bbede12af4f03 to your computer and use it in GitHub Desktop.
Simple example to convert coordinates from one projection into another one
// import
// - https://d3js.org/d3-geo.v1.min.js
// - https://d3js.org/d3-geo-projection.v2.min.js
// Keep x and y in the same range of values as coordinates
var x = 180;
var y = 90;
var fromXY = [x, y];
var fromLonLat = d3.geoEquirectangular().invert(fromXY);
var toXY = d3.geoMercator()(fromLonLat);
//document.getElementById("console").innerHTML = 'Before <br>' + fromXY[0] + ', ' + fromXY[1] + '<br><br>After<br>' + toXY[0] + ', ' + toXY[1];
console.log('Before', fromXY, 'After', toXY);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment