From 0564c524a2207e6848aeff4ff65effe1e4959c1b Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 27 Jul 2021 15:06:36 +0200 Subject: [PATCH] Fixed generateCacheScript as not to redownload duplicate features --- scripts/ScriptUtils.ts | 4 ++++ scripts/generateCache.ts | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/scripts/ScriptUtils.ts b/scripts/ScriptUtils.ts index 93c6dfaca..2fba05984 100644 --- a/scripts/ScriptUtils.ts +++ b/scripts/ScriptUtils.ts @@ -86,6 +86,10 @@ export default class ScriptUtils { }) } + + public static erasableLog(...text) { + process.stdout.write("\r "+text.join(" ")+" \r") + } public static sleep(ms) { if (ms <= 0) { diff --git a/scripts/generateCache.ts b/scripts/generateCache.ts index fb2303e71..d76347d25 100644 --- a/scripts/generateCache.ts +++ b/scripts/generateCache.ts @@ -34,7 +34,7 @@ function createOverpassObject(theme: LayoutConfig) { if (layer.source.geojsonSource !== undefined) { // This layer defines a geoJson-source // SHould it be cached? - if (!layer.source.isOsmCacheLayer) { + if (layer.source.isOsmCacheLayer !== true) { continue; } } @@ -131,7 +131,7 @@ async function downloadExtraData(theme: LayoutConfig)/* : any[] */ { if (source === undefined) { continue; } - if (layer.source.isOsmCacheLayer) { + if (layer.source.isOsmCacheLayer !== undefined) { // Cached layers are not considered here continue; } @@ -148,7 +148,7 @@ function postProcess(targetdir: string, r: TileRange, theme: LayoutConfig, extra for (let y = r.ystart; y <= r.yend; y++) { processed++; const filename = rawJsonName(targetdir, x, y, r.zoomlevel) - console.log(" Post processing", processed, "/", r.total, filename) + ScriptUtils.erasableLog(" Post processing", processed, "/", r.total, filename) if (!existsSync(filename)) { console.error("Not found - and not downloaded. Run this script again!: " + filename) continue; @@ -234,9 +234,8 @@ function splitPerLayer(targetdir: string, r: TileRange, theme: LayoutConfig) { }) const new_path = geoJsonName(targetdir + "_" + layer.id, x, y, z); - console.log(new_path, " has ", geojson.features.length, " features after filtering (dropped ", oldLength - geojson.features.length, ")") + ScriptUtils.erasableLog(new_path, " has ", geojson.features.length, " features after filtering (dropped ", oldLength - geojson.features.length, ")") if (geojson.features.length == 0) { - console.log("Not writing geojson file as it is empty", new_path) continue; } writeFileSync(new_path, JSON.stringify(geojson, null, " ")) @@ -289,9 +288,20 @@ async function createOverview(targetdir: string, r: TileRange, z: number, layern } } + const featuresDedup = [] + const seen = new Set() + for (const feature of allFeatures) { + const id = feature.properties.id + if(seen.has(id)){ + continue + } + seen.add(id) + featuresDedup.push(feature) + } + const geojson = { "type": "FeatureCollection", - "features": allFeatures + "features": featuresDedup } writeFileSync(targetdir + "_" + layername + "_points.geojson", JSON.stringify(geojson, null, " ")) }