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));
|
const stagedPath = path.join(stagingDir, layerFile(layer));
|
||||||
exportLayer(layer.id, stagedPath);
|
exportLayer(layer.id, stagedPath);
|
||||||
const collection = readCollection(stagedPath, layer.id);
|
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}`);
|
console.log(`${layer.id}\tfeatures=${collection.features.length}`);
|
||||||
return { layer, stagedPath, collection };
|
return { layer, stagedPath, collection };
|
||||||
});
|
});
|
||||||
@@ -180,6 +184,9 @@ function exportLayer(layerName, destination) {
|
|||||||
// precision-reduction pass, which drops vertices that collapse at the given
|
// precision-reduction pass, which drops vertices that collapse at the given
|
||||||
// resolution (measured: 28 points lost across 7 lane-arrow polygons).
|
// resolution (measured: 28 points lost across 7 lane-arrow polygons).
|
||||||
execFileSync(ogr2ogr, [
|
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",
|
"-f", "GeoJSON",
|
||||||
destination,
|
destination,
|
||||||
gpkgPath,
|
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) {
|
function readCollection(file, layerName) {
|
||||||
let parsed;
|
let parsed;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user