#!/usr/bin/env node var os = require("os"), commander = require("commander"), d3 = Object.assign({}, require("d3-geo"), require("../")), read = require("./read"), write = require("./write"); commander .version(require("../package.json").version) .usage("[options] [file]") .description("Convert GeoJSON to SVG.") .option("-o, --out ", "output file name; defaults to “-” for stdout", "-") .option("-w, --width ", "output width", 960) .option("-h, --height ", "output height", 500) .option("-p, --precision ", "number of output digits after the decimal point", 6) .option("-n, --newline-delimited", "accept newline-delimited JSON") .option("--fill ", "default fill", "none") .option("--stroke ", "default stroke", "black") .option("-r, --radius ", "default point radius", 4.5) .parse(process.argv); if (commander.args.length === 0) commander.args[0] = "-"; else if (commander.args.length !== 1) { console.error(); console.error(" error: multiple input files"); console.error(); process.exit(1); } var reader = read(commander.args[0], commander.newlineDelimited, transform).then(end).catch(abort), writer = write(commander.out), path = d3.geoPath().pointRadius(function(d) { var p = d.properties, v; return p && (v = p["point-radius"] || p.pointRadius) != null ? v : commander.radius; }), render = commander.precision == null ? path : function(d) { return path(d3.geoQuantize(d, commander.precision)); }; writer.write("" + os.EOL + "" + os.EOL + "" + os.EOL + "" + os.EOL); function transform(d) { var p = d.properties, v; return writer.write(" " + ((v = p && p["title"]) != null ? "" + text(v + "") + "" : "") + "" + os.EOL); } function end() { return writer.write("" + os.EOL); } function abort(error) { console.error(error.stack); } function text(string) { return string.replace(/[&<>]/g, function(character) { switch (character) { case "&": return "&"; case "<": return "<"; case ">": return ">"; } }); } function attr(string) { return string.replace(/"/g, """); }