minikomi
minikomi

Reputation: 8503

d3js - how to set albers projection properly?

I have some geojson data for Japan, which I managed to position properly on a mercator projection, but I'm a bit lost as to how to position it properly using an albers projection, other than trial and error.

Is there a good tool to use?

blocks example: http://bl.ocks.org/4043986

long, lat for japan (wikipedia):

geojson link: https://gist.github.com/raw/4043986/f53b85ab0af1585cd0461b4865ca4acd1fb79e9f/japan.json

Upvotes: 9

Views: 4789

Answers (2)

minikomi
minikomi

Reputation: 8503

I found the answer looking through the repository - the tool is right there!

  1. clone d3.js from the github repository.
  2. edit /d3/examples/albers.html line 53 to point at your GEOJSON file:
  3. Put the origin long / lat sliders to the center of your country / region (for me, it was 134° / 25°)
  4. Change the paralells to be as close to the edges of your country / region.
  5. adjust scale & offset to a nice size & position.

There are similar tools for the other projections.

edit: The repository has changed (and is constantly changing), so I've created a gist to preserve the example: https://gist.github.com/4552802

The examples are no longer part of the github repository.

Upvotes: 6

chanp
chanp

Reputation: 675

As of now, it's the version 3 of D3.js. It might be worth looking at the original source albers.js at github, which contains :

d3.geo.albers = function() {
    return d3.geo.conicEqualArea()
      .parallels([29.5, 45.5])
      .rotate([98, 0])
      .center([0, 38])
      .scale(1000);
};

Now, d3.js use combination of projection.rotate and projection.center to place center of the projection to long 98°W, lat 38°N (around Hutchinson, Kansas).

From Geo Projections API,d3.geo.conicEqualArea() .parallels([29.5, 45.5]) sets the Albers projection’s two standard parallels latitudes 29.5°N and 45.5°N, respectively. But what is two standard parallels?

To understand what parallels setting is, one need to know that Albers projection is a kind of conic projection.

A conic projection projects information from the spherical Earth to a cone that is either tangent to the Earth at a single parallel, or that is secant at two standard parallels.

enter image description here

Choosing the best standard parallels setting seems to be a subtle task, of which the goal is to minimize the projection distortion when mapping between surfaces. Anyway, choosing the two values to be closed to a country top/bottom edges is intuitively good, as it helps minimize the distance between the [conic/sphere] surfaces enclosing a country. enter image description here

Upvotes: 18

Related Questions