47 lines
2.2 KiB
JavaScript
47 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { gaodeReference: { inspectReference, localReferenceSvg } } = require("@osm-asset/road-compiler");
|
|
|
|
function parseArgs(argv) {
|
|
const result = {};
|
|
for (let index = 0; index < argv.length; index += 1) {
|
|
if (!argv[index].startsWith("--")) continue;
|
|
const key = argv[index].slice(2).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
result[key] = argv[index + 1] && !argv[index + 1].startsWith("--") ? argv[++index] : "true";
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function required(args, key) {
|
|
if (!args[key]) throw new Error(`--${key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)} is required`);
|
|
return path.resolve(args[key]);
|
|
}
|
|
|
|
function main() {
|
|
const args = parseArgs(process.argv.slice(2));
|
|
const result = inspectReference({
|
|
referenceFile: required(args, "reference"),
|
|
osmFile: required(args, "osm"),
|
|
nativeIntersectionFile: required(args, "nativeIntersection"),
|
|
nativeRoadSurfaceFile: args.nativeRoadSurface ? path.resolve(args.nativeRoadSurface) : null,
|
|
nodeId: args.nodeId,
|
|
clusterId: args.clusterId,
|
|
});
|
|
const output = path.resolve(args.output || `${args.reference.replace(/\.geojson$/i, "")}-wgs84.geojson`);
|
|
const comparison = output.replace(/\.geojson$/i, "-comparison.json");
|
|
fs.mkdirSync(path.dirname(output), { recursive: true });
|
|
fs.writeFileSync(output, `${JSON.stringify(result.converted, null, 2)}\n`);
|
|
fs.writeFileSync(comparison, `${JSON.stringify({ ...result, converted: undefined, matchedFeatures: undefined }, null, 2)}\n`);
|
|
const svg = output.replace(/\.geojson$/i, "-overlay.svg");
|
|
// Draw whatever the comparison actually matched: a per-node junction surface
|
|
// for ordinary junctions, or the whole complex cluster for templated ones.
|
|
const matchingNative = { type: "FeatureCollection", features: result.matchedFeatures || [] };
|
|
fs.writeFileSync(svg, localReferenceSvg({ converted: result.converted, nativeIntersection: matchingNative, center: result.matchedOsmNode.coordinate }));
|
|
console.log(JSON.stringify({ output, comparison, svg, ...result, converted: undefined, matchedFeatures: undefined }, null, 2));
|
|
}
|
|
|
|
if (require.main === module) main();
|