Add area diagnostics command
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { spawnSync } = require("child_process");
|
||||
const { readAreaConfig } = require("./lib/area-config");
|
||||
|
||||
const repoRoot = path.resolve(__dirname, "..");
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
const configPath = path.resolve(
|
||||
args.config || path.join(repoRoot, "config", "areas", "nantaizi-lake-innovation-valley.json"),
|
||||
);
|
||||
const area = normalizeAreaConfig(readJson(configPath));
|
||||
const area = readAreaConfig(configPath, { repoRoot });
|
||||
const requestedStages = args.stages
|
||||
? splitList(args.stages)
|
||||
: null;
|
||||
@@ -67,129 +68,6 @@ function parseArgs(argv) {
|
||||
return out;
|
||||
}
|
||||
|
||||
function readJson(file) {
|
||||
if (!fs.existsSync(file)) {
|
||||
throw new Error(`Config file not found: ${file}`);
|
||||
}
|
||||
return JSON.parse(fs.readFileSync(file, "utf8"));
|
||||
}
|
||||
|
||||
function normalizeAreaConfig(raw) {
|
||||
const id = requireText(raw.id, "id");
|
||||
const input = path.resolve(requireText(raw.input, "input"));
|
||||
if (!fs.existsSync(input)) {
|
||||
throw new Error(`Input OSM XML not found: ${input}`);
|
||||
}
|
||||
|
||||
const outputRoot = path.resolve(raw.outputRoot || path.join(repoRoot, "outputs"));
|
||||
const outputOverrides = raw.outputs || {};
|
||||
const areaDir = path.resolve(outputOverrides.areaDir || path.join(outputRoot, id));
|
||||
const fileStem = outputOverrides.fileStem || id;
|
||||
const compress = normalizeCompressConfig(raw.compress);
|
||||
const compressedFileStem = outputOverrides.compressedFileStem ||
|
||||
`${fileStem}-compressed-webp${compress.textureSize}${compress.meshopt ? "-meshopt" : ""}`;
|
||||
const outputs = {
|
||||
areaDir,
|
||||
geojsonDir: path.resolve(outputOverrides.geojsonDir || path.join(areaDir, "osm2streets_web_out")),
|
||||
gpkg: path.resolve(outputOverrides.gpkg || path.join(areaDir, `${fileStem}.gpkg`)),
|
||||
qgisProject: path.resolve(outputOverrides.qgisProject || path.join(areaDir, `${fileStem}.qgz`)),
|
||||
qgisPreview: path.resolve(outputOverrides.qgisPreview || path.join(areaDir, `${fileStem}-preview.png`)),
|
||||
blend: path.resolve(outputOverrides.blend || path.join(areaDir, `${fileStem}.blend`)),
|
||||
render: path.resolve(outputOverrides.render || path.join(areaDir, `${fileStem}.png`)),
|
||||
glb: path.resolve(outputOverrides.glb || path.join(areaDir, `${fileStem}.glb`)),
|
||||
metadata: path.resolve(outputOverrides.metadata || path.join(areaDir, `${fileStem}.json`)),
|
||||
cesiumPreview: path.resolve(
|
||||
outputOverrides.cesiumPreview || path.join(areaDir, `${fileStem}-cesium-preview.html`),
|
||||
),
|
||||
compressedGlb: path.resolve(
|
||||
outputOverrides.compressedGlb || path.join(areaDir, `${compressedFileStem}.glb`),
|
||||
),
|
||||
compressedMetadata: path.resolve(
|
||||
outputOverrides.compressedMetadata || path.join(areaDir, `${compressedFileStem}.json`),
|
||||
),
|
||||
compressedCesiumPreview: path.resolve(
|
||||
outputOverrides.compressedCesiumPreview || path.join(areaDir, `${compressedFileStem}-cesium-preview.html`),
|
||||
),
|
||||
vehicleRoute: path.resolve(outputOverrides.vehicleRoute || path.join(areaDir, `${fileStem}-vehicle-route.json`)),
|
||||
vehicleModel: path.resolve(outputOverrides.vehicleModel || path.join(areaDir, `${fileStem}-vehicle-car.gltf`)),
|
||||
pipelineDir: path.resolve(outputOverrides.pipelineDir || path.join(areaDir, "_pipeline")),
|
||||
};
|
||||
|
||||
return {
|
||||
id,
|
||||
input,
|
||||
outputRoot,
|
||||
qgisApp: raw.qgisApp || "/Applications/QGIS.app",
|
||||
blenderApp: raw.blenderApp || "/Applications/Blender.app",
|
||||
stages: {
|
||||
intermediates: raw.stages?.intermediates ?? raw.stages?.qgis ?? true,
|
||||
blender: raw.stages?.blender ?? true,
|
||||
cesium: raw.stages?.cesium ?? true,
|
||||
reimport: false,
|
||||
preview: false,
|
||||
compress: false,
|
||||
},
|
||||
qgis: {
|
||||
arrowScale: raw.qgis?.arrowScale ?? raw.arrowScale ?? 0.8,
|
||||
arrowMergeTriangles: raw.qgis?.arrowMergeTriangles ?? raw.arrowMergeTriangles ?? true,
|
||||
arrowOutlineSimplifyMeters: raw.qgis?.arrowOutlineSimplifyMeters ?? raw.arrowOutlineSimplifyMeters ?? 0.05,
|
||||
intersectionCornerSourceMaxDimensionMeters: raw.qgis?.intersectionCornerSourceMaxDimensionMeters ?? raw.intersectionCornerSourceMaxDimensionMeters ?? 2.6,
|
||||
clipPad: raw.qgis?.clipPad ?? raw.clipPad ?? 0.002,
|
||||
canvasPad: raw.qgis?.canvasPad ?? raw.canvasPad ?? 0.001,
|
||||
previewPad: raw.qgis?.previewPad ?? raw.previewPad ?? 0.0007,
|
||||
canvasExtent: raw.qgis?.canvasExtent ?? raw.canvasExtent ?? null,
|
||||
previewExtent: raw.qgis?.previewExtent ?? raw.previewExtent ?? null,
|
||||
layerPrefix: raw.qgis?.layerPrefix ?? raw.layerPrefix ?? "osm2streets",
|
||||
},
|
||||
osm2streets: raw.osm2streets || {
|
||||
debug_each_step: false,
|
||||
dual_carriageway_experiment: false,
|
||||
sidepath_zipping_experiment: false,
|
||||
inferred_sidewalks: true,
|
||||
osm2lanes: true,
|
||||
},
|
||||
blender: {
|
||||
treeStyle: raw.blender?.treeStyle || "natural",
|
||||
officeOverrides: raw.blender?.officeOverrides || raw.blender?.office_overrides || "",
|
||||
},
|
||||
compress,
|
||||
outputs,
|
||||
};
|
||||
}
|
||||
|
||||
function requireText(value, key) {
|
||||
if (typeof value !== "string" || value.trim() === "") {
|
||||
throw new Error(`Missing config key: ${key}`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function normalizeCompressConfig(raw) {
|
||||
const value = raw || {};
|
||||
return {
|
||||
textureSize: numberOption(value.textureSize, 768, "compress.textureSize", 64, 4096),
|
||||
quality: numberOption(value.quality, 82, "compress.quality", 1, 100),
|
||||
effort: numberOption(value.effort, 80, "compress.effort", 0, 100),
|
||||
meshopt: booleanOption(value.meshopt, false, "compress.meshopt"),
|
||||
};
|
||||
}
|
||||
|
||||
function numberOption(value, fallback, label, min, max) {
|
||||
const number = value === undefined ? fallback : Number(value);
|
||||
if (!Number.isFinite(number) || number < min || number > max) {
|
||||
throw new Error(`${label} must be a finite number in [${min}, ${max}]`);
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
function booleanOption(value, fallback, label) {
|
||||
if (value === undefined) return fallback;
|
||||
if (typeof value === "boolean") return value;
|
||||
if (value === "true") return true;
|
||||
if (value === "false") return false;
|
||||
throw new Error(`${label} must be boolean`);
|
||||
}
|
||||
|
||||
function splitList(value) {
|
||||
return String(value)
|
||||
.split(",")
|
||||
|
||||
Reference in New Issue
Block a user