Skip to content

Commit

Permalink
Add Bonne geographic projection.
Browse files Browse the repository at this point in the history
Note that the Werner projection is a special case with standard parallel
at 90°N, and the Sinusoidal projection is also a special case with
standard parallel at 0°N.
  • Loading branch information
jasondavies committed Sep 25, 2011
1 parent c974d3a commit a6eb928
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -183,6 +183,7 @@ d3.geo.js: \
src/geo/geo.js \
src/geo/azimuthal.js \
src/geo/albers.js \
src/geo/bonne.js \
src/geo/equirectangular.js \
src/geo/mercator.js \
src/geo/path.js \
Expand Down
64 changes: 64 additions & 0 deletions d3.geo.js
Expand Up @@ -197,6 +197,70 @@ d3.geo.albersUsa = function() {
};

var d3_radians = Math.PI / 180;
d3.geo.bonne = function() {
var origin,
scale = 200,
translate = [480, 250],
standardParallel, // 90 for Wener, 0 for Sinusoidal
p0,
ctp0,
x0,
y0;

function bonne(coordinates) {
var x1 = coordinates[0] * d3_radians - x0,
y1 = coordinates[1] * d3_radians - y0,
p = ctp0 + p0 - y1,
E = x1 * Math.cos(y1) / p,
x = p * Math.sin(E),
y = p * Math.cos(E) - ctp0;
return [
scale * x + translate[0],
scale * y + translate[1]
];
}

bonne.invert = function(coordinates) {
var x = (coordinates[0] - translate[0]) / scale,
y = (coordinates[1] - translate[1]) / scale,
c = ctp0 + y,
p = Math.sqrt(x * x + c * c),
y1 = (ctp0 + p0 - p);
return [
(x0 + p * Math.atan2(x, c) / Math.cos(y1)) / d3_radians,
y1 / d3_radians
];
};

bonne.standardParallel = function(x) {
if (!arguments.length) return standardParallel;
standardParallel = +x;
ctp0 = 1 / Math.tan(p0 = standardParallel * d3_radians);
return bonne;
};

bonne.origin = function(x) {
if (!arguments.length) return origin;
origin = x;
x0 = origin[0] * d3_radians;
y0 = origin[1] * d3_radians;
return bonne;
};

bonne.scale = function(x) {
if (!arguments.length) return scale;
scale = +x;
return bonne;
};

bonne.translate = function(x) {
if (!arguments.length) return translate;
translate = [+x[0], +x[1]];
return bonne;
};

return bonne.origin([0, 0]).standardParallel(40);
};
d3.geo.equirectangular = function() {
var scale = 500,
translate = [480, 250];
Expand Down
2 changes: 1 addition & 1 deletion d3.geo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a6eb928

Please sign in to comment.