fix(reimport): retain intersection IDs for cruise routes
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user