25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

64 satır
2.4 KiB

  1. #!/usr/bin/env node
  2. import {program} from "commander";
  3. import {geoGraticule} from "d3-geo";
  4. import {readFileSync} from "fs";
  5. import {dirname, resolve} from "path";
  6. import {fileURLToPath} from "url";
  7. import write from "./write.js";
  8. const version = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../package.json"))).version;
  9. const graticule = geoGraticule();
  10. const options = program
  11. .version(version)
  12. .usage("[options]")
  13. .description("Generate a GeoJSON graticule.")
  14. .option("-o, --out <file>", "output file name; defaults to “-” for stdout", "-")
  15. .option("--extent <value>", "the major and minor extent", parseExtent)
  16. .option("--extent-minor <value>", "the minor extent; defaults to " + graticule.extentMajor(), parseExtent)
  17. .option("--extent-major <value>", "the major extent; defaults to " + graticule.extentMinor(), parseExtent)
  18. .option("--step <value>", "the major and minor step", parseStep)
  19. .option("--step-minor <value>", "the minor step; defaults to " + graticule.stepMinor(), parseStep)
  20. .option("--step-major <value>", "the major step; defaults to " + graticule.stepMajor(), parseStep)
  21. .option("--precision <value>", "the precision; defaults to " + graticule.precision(), graticule.precision)
  22. .parse(process.argv)
  23. .opts();
  24. if (program.args.length !== 0) {
  25. console.error();
  26. console.error(" error: unexpected arguments");
  27. console.error();
  28. process.exit(1);
  29. }
  30. if (options.extent != null) {
  31. if (options.extentMinor == null) options.extentMinor = options.extent;
  32. if (options.extentMajor == null) options.extentMajor = options.extent;
  33. }
  34. if (options.step != null) {
  35. if (options.stepMinor == null) options.stepMinor = options.step;
  36. if (options.stepMajor == null) options.stepMajor = options.step;
  37. }
  38. if (options.extentMinor != null) graticule.extentMinor(options.extentMinor);
  39. if (options.extentMajor != null) graticule.extentMajor(options.extentMajor);
  40. if (options.stepMinor != null) graticule.stepMinor(options.stepMinor);
  41. if (options.stepMajor != null) graticule.stepMajor(options.stepMajor);
  42. var writer = write(options.out);
  43. writer.write(JSON.stringify(graticule()) + "\n");
  44. writer.end().catch(abort);
  45. function parseStep(x) {
  46. return x = x.split(","), x.length === 1 ? [+x[0], +x[0]] : [+x[0], +x[1]];
  47. }
  48. function parseExtent(x) {
  49. return x = x.split(","), [[+x[0], +x[1]], [+x[2], +x[3]]];
  50. }
  51. function abort(error) {
  52. console.error(error.stack);
  53. }