#!/usr/bin/env node import {EOL} from "os"; import {program} from "commander"; import {geoPath} from "d3-geo"; import {readFileSync} from "fs"; import {dirname, resolve} from "path"; import {fileURLToPath} from "url"; import {geoQuantize} from "../src/index.js"; import read from "./read.js"; import write from "./write.js"; const version = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../package.json"))).version; const options = program .version(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) .opts(); if (program.args.length === 0) program.args[0] = "-"; else if (program.args.length !== 1) { console.error(); console.error(" error: multiple input files"); console.error(); process.exit(1); } var reader = read(program.args[0], options.newlineDelimited, transform).then(end), writer = write(options.out), path = geoPath().pointRadius(function(d) { var p = d.properties, v; return p && (v = p["point-radius"] || p.pointRadius) != null ? v : options.radius; }), render = options.precision == null ? path : function(d) { return path(geoQuantize(d, options.precision)); }; reader.catch(error => { console.error(error.stack); }); writer.write("" + EOL + "" + EOL + "" + EOL + "" + EOL); function transform(d) { var p = d.properties, v; return writer.write(" " + ((v = p && p["title"]) != null ? "" + text(v + "") + "" : "") + "" + EOL); } function end() { return writer.write("" + EOL); } function text(string) { return string.replace(/[&<>]/g, function(character) { switch (character) { case "&": return "&"; case "<": return "<"; case ">": return ">"; } }); } function attr(string) { return string.replace(/"/g, """); }