All examples By author By category About

armollica

Proj4/WKT + D3

Use Proj4js to convert proj4 or WKT projection definition strings into D3 projections.

// Create Proj4js projection function
var proj4Projection = proj4(wkt);  // WGS84 to projection defined in `wkt`

// Use this to create a D3 projection
var project = function(lambda, phi) {
	return proj4Projection
		.forward([lambda, phi].map(radiansToDegrees));
};

project.invert = function(x, y) {
	return proj4Projection
		.inverse([x, y]).map(degreesToRadians);
};

var projection = d3.geoProjection(project);

Geographic data from Eurostat's GISCO program. The example projections came from Spatial Reference.

I had trouble interpolating the graticules. See Fil's block for a solution to that: Proj4/WKT + D3 + d3-interpolate-path