From a1bbc4e689abec6e4165883c06ee298e93157db5 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Tue, 20 Jun 2023 22:49:58 +0200 Subject: [PATCH] Scripts: fix generateStatistics-script --- scripts/GenerateSeries.ts | 65 ++++++++++++++------------------------- scripts/generateStats.ts | 2 +- 2 files changed, 24 insertions(+), 43 deletions(-) diff --git a/scripts/GenerateSeries.ts b/scripts/GenerateSeries.ts index 6aa59df850..6ed84955fc 100644 --- a/scripts/GenerateSeries.ts +++ b/scripts/GenerateSeries.ts @@ -2,10 +2,9 @@ import { existsSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from import ScriptUtils from "./ScriptUtils" import { Utils } from "../Utils" import Script from "./Script" -import TiledFeatureSource from "../Logic/FeatureSource/TiledFeatureSource/TiledFeatureSource" -import StaticFeatureSource from "../Logic/FeatureSource/Sources/StaticFeatureSource" import { GeoOperations } from "../Logic/GeoOperations" import { Feature, Polygon } from "geojson" +import { Tiles } from "../Models/TileRange" class StatsDownloader { private readonly urlTemplate = @@ -275,47 +274,29 @@ class GenerateSeries extends Script { const centerpoints = allFeatures.map((f) => GeoOperations.centerpoint(f)) console.log("Found", centerpoints.length, " changesets in total") const path = `${targetDir}/all_centerpoints.geojson` - /*fs.writeFileSync( - path, - JSON.stringify( - { - type: "FeatureCollection", - features: centerpoints, - }, - null, - " " + + const perBbox = GeoOperations.spreadIntoBboxes(centerpoints, options.zoomlevel) + + for (const [tileNumber, features] of perBbox) { + const [z, x, y] = Tiles.tile_from_index(tileNumber) + const path = `${targetDir}/tile_${z}_${x}_${y}.geojson` + features.forEach((f) => { + delete f.bbox + }) + writeFileSync( + path, + JSON.stringify( + { + type: "FeatureCollection", + features: features, + }, + null, + " " + ) ) - )//*/ - TiledFeatureSource.createHierarchy(StaticFeatureSource.fromGeojson(centerpoints), { - minZoomLevel: options.zoomlevel, - maxZoomLevel: options.zoomlevel, - maxFeatureCount: Number.MAX_VALUE, - registerTile: (tile) => { - const path = `${targetDir}/tile_${tile.z}_${tile.x}_${tile.y}.geojson` - const features = tile.features.data.map((ff) => ff.feature) - features.forEach((f) => { - delete f.bbox - }) - writeFileSync( - path, - JSON.stringify( - { - type: "FeatureCollection", - features: features, - }, - null, - " " - ) - ) - ScriptUtils.erasableLog( - "Written ", - path, - "which has ", - tile.features.data.length, - "features" - ) - }, - }) + + ScriptUtils.erasableLog("Written ", path, "which has ", features.length, "features") + } } } diff --git a/scripts/generateStats.ts b/scripts/generateStats.ts index 43463db77a..8e83170e67 100644 --- a/scripts/generateStats.ts +++ b/scripts/generateStats.ts @@ -21,7 +21,7 @@ async function main(includeTags = true) { continue } - const sources = TagUtils.Tag(layer.source.osmTags) + const sources = TagUtils.Tag(layer.source["osmTags"]) const allKeys = sources.usedKeys() for (const key of allKeys) { if (!keysAndTags.has(key)) {