Skip to content

Instantly share code, notes, and snippets.

@Fil
Created August 18, 2016 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fil/0f89f5119a8f98d359fe45930f5f83d6 to your computer and use it in GitHub Desktop.
Save Fil/0f89f5119a8f98d359fe45930f5f83d6 to your computer and use it in GitHub Desktop.
render-world-variant
#!/usr/bin/env node
var fs = require("fs"),
topojson = require("topojson"),
Canvas = require("canvas"),
d3_geo = require("d3-geo"),
d3_geo_projection = require("../");
var world = require("./data/world-50m.json"),
land = topojson.feature(world, world.objects.land);
var width = 2*960,
height = 2*500;
'airy aitoff armadillo august baker berghaus boggs bonne bottomley bromley chamberlinAfrica collignon craig craster cylindricalEqualArea cylindricalStereographic eckert1 eckert2 eckert3 eckert4 eckert5 eckert6 eisenlohr fahey foucaut gilbert gingery ginzburg4 ginzburg5 ginzburg6 ginzburg8 ginzburg9 gringorten gringortenQuincuncial guyou hammer hammerRetroazimuthal healpix hill homolosine interruptedBoggs interruptedHomolosine interruptedMollweide interruptedMollweideHemispheres interruptedSinusoidal interruptedSinuMollweide kavrayskiy7 lagrange larrivee laskowski littrow loximuthal miller modifiedStereographicAlaska modifiedStereographicGs48 modifiedStereographicGs50 modifiedStereographicMiller modifiedStereographicLee mollweide mtFlatPolarParabolic mtFlatPolarQuartic mtFlatPolarSinusoidal naturalEarth nellHammer patterson peirceQuincuncial polyconic polyhedronButterfly polyhedronCollignon polyhedronWaterman rectangularPolyconic robinson satellite sinuMollweide sinusoidal times twoPointAzimuthalUsa twoPointEquidistantUsa vanDerGrinten vanDerGrinten2 vanDerGrinten3 vanDerGrinten4 wagner4 wagner6 wagner7 wiechel winkel3'.split(/ /)
.forEach(project);
function project(projectionName) {
var canvas = new Canvas(width, height),
context = canvas.getContext("2d");
var projectionSymbol = "geo" + projectionName[0].toUpperCase() + projectionName.slice(1);
if (!/^[a-z0-9]+$/i.test(projectionName)) throw new Error;
var graticule = d3_geo.geoGraticule(),
outline = {type: "Sphere"}
switch (projectionName) {
case "littrow": outline = graticule.extent([[-90, -60], [90, 60]]).outline(); break;
case "modifiedStereographicGs50": outline = graticule.extent([[-180, 15], [-50, 75]]).outline(); break;
case "modifiedStereographicMiller": outline = graticule.extent([[-40, -40], [80, 80]]).outline(); break;
}
var pr = d3_geo_projection[projectionSymbol]().precision(0.1);
pr.scale(2 * pr.scale());
pr.translate(pr.translate().map(function(t) { return 2*t; }));
if (pr.rotate) pr.rotate([-10.5,0]);
var path = d3_geo.geoPath()
.projection(pr)
.context(context);
context.fillStyle = "#fff";
context.fillRect(0, 0, width, height);
context.save();
switch (projectionName) {
case "armadillo":
case "berghaus":
case "gingery":
case "hammerRetroazimuthal":
case "healpix":
case "interruptedBoggs":
case "interruptedHomolosine":
case "interruptedSinusoidal":
case "interruptedSinuMollweide":
case "interruptedMollweide":
case "interruptedMollweideHemispheres":
case "littrow":
case "modifiedStereographicGs50":
case "modifiedStereographicMiller":
case "polyhedronButterfly":
case "polyhedronWaterman":
case "polyhedronCollignon": {
context.beginPath();
path(outline);
context.clip();
break;
}
}
context.beginPath();
path(land);
context.strokeStyle = "#000";
context.stroke();
context.beginPath();
path(graticule());
context.strokeStyle = "rgba(119,119,119,0.5)";
context.stroke();
context.restore();
context.beginPath();
path(outline);
context.strokeStyle = "#000";
context.stroke();
console.warn("↳ fil/" + projectionName + ".png");
canvas.pngStream().pipe(fs.createWriteStream("fil/" + projectionName + ".png"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment