From d26921c6d1962ec252ce5844f9f64de53af735a6 Mon Sep 17 00:00:00 2001 From: que01 Date: Tue, 11 Aug 2026 13:25:54 +0800 Subject: [PATCH] fix(reimport): retain intersection IDs for cruise routes --- scripts/reimport-gpkg.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/reimport-gpkg.js b/scripts/reimport-gpkg.js index f0a25b8..3ac959c 100755 --- a/scripts/reimport-gpkg.js +++ b/scripts/reimport-gpkg.js @@ -78,6 +78,10 @@ try { const stagedPath = path.join(stagingDir, layerFile(layer)); exportLayer(layer.id, stagedPath); const collection = readCollection(stagedPath, layer.id); + if (layer.id === "intersection_surface") { + restoreIntersectionSurfaceIds(collection); + fs.writeFileSync(stagedPath, JSON.stringify(collection)); + } console.log(`${layer.id}\tfeatures=${collection.features.length}`); return { layer, stagedPath, collection }; }); @@ -180,6 +184,9 @@ function exportLayer(layerName, destination) { // precision-reduction pass, which drops vertices that collapse at the given // resolution (measured: 28 points lost across 7 lane-arrow polygons). execFileSync(ogr2ogr, [ + // GeoPackage reserves "id" as its FID column. Preserve it so the + // intersection surface can retain its osm2streets internal ID on export. + "-preserve_fid", "-f", "GeoJSON", destination, gpkgPath, @@ -190,6 +197,23 @@ function exportLayer(layerName, destination) { }); } +function restoreIntersectionSurfaceIds(collection) { + for (const [index, feature] of collection.features.entries()) { + if (!feature || typeof feature !== "object") { + throw new Error(`intersection_surface feature ${index + 1} is invalid`); + } + const existingId = Number(feature.properties?.id); + if (Number.isInteger(existingId)) continue; + const fid = Number(feature.id); + if (!Number.isInteger(fid)) { + throw new Error( + `intersection_surface feature ${index + 1} is missing its osm2streets internal ID`, + ); + } + feature.properties = { ...(feature.properties || {}), id: fid }; + } +} + function readCollection(file, layerName) { let parsed; try {