Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3js - how to set albers projection properly?

Tags:

d3.js

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):

  • latitudes 24° - 46°N,
  • longitudes 122° - 146°E.

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

like image 551
minikomi Avatar asked Nov 09 '12 06:11

minikomi


People also ask

How to draw the Albers equal-area conic projection in D3?

The geoAlbers () function in d3.js is used to draw the Albers equal-area conic projection. Albers projection which is named after Heinrich C. Albers is a conic, equal-area map projection that uses two standard parallels. The scale and shape are not preserved and the distortion is minimal between the standard parallels.

What is the use of D3 projection?

For a full list of projections supported in D3, you can visit it’s documentation page. The purpose of the function is actually really straightforward: translate a lattitude and longitude pair to a pair of X,Y coordinates on our SVG. Let’s try this out with some random input pairs:

What is Albers projection?

Albers projection which is named after Heinrich C. Albers is a conic, equal-area map projection that uses two standard parallels. The scale and shape are not preserved and the distortion is minimal between the standard parallels. It draws a geoAlbers projection from geojson data.

How do you Center an Alber's projection on the x axis?

Rotation for an Alber's projection is the method for centering a projection on the x axis (or by longitude). And as the earth is spinning underneath the projection, we use the negative of the longitude we want to be centered.


2 Answers

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

like image 172
chanp Avatar answered Oct 10 '22 01:10

chanp


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.

like image 6
minikomi Avatar answered Oct 10 '22 02:10

minikomi