forked from MapComplete/MapComplete
Improve slice script, formatting
This commit is contained in:
parent
cce6a9e832
commit
ccb548816f
3 changed files with 88 additions and 73 deletions
|
@ -24,6 +24,7 @@ import {GeoOperations} from "../Logic/GeoOperations";
|
||||||
import SimpleMetaTaggers from "../Logic/SimpleMetaTagger";
|
import SimpleMetaTaggers from "../Logic/SimpleMetaTagger";
|
||||||
import FilteringFeatureSource from "../Logic/FeatureSource/Sources/FilteringFeatureSource";
|
import FilteringFeatureSource from "../Logic/FeatureSource/Sources/FilteringFeatureSource";
|
||||||
import Loc from "../Models/Loc";
|
import Loc from "../Models/Loc";
|
||||||
|
|
||||||
ScriptUtils.fixUtils()
|
ScriptUtils.fixUtils()
|
||||||
|
|
||||||
function createOverpassObject(theme: LayoutConfig, relationTracker: RelationsTracker, backend: string) {
|
function createOverpassObject(theme: LayoutConfig, relationTracker: RelationsTracker, backend: string) {
|
||||||
|
@ -182,6 +183,7 @@ function sliceToTiles(allFeatures: FeatureSource, theme: LayoutConfig, relations
|
||||||
|
|
||||||
const indexedFeatures: Map<string, any> = new Map<string, any>()
|
const indexedFeatures: Map<string, any> = new Map<string, any>()
|
||||||
let indexisBuilt = false;
|
let indexisBuilt = false;
|
||||||
|
|
||||||
function buildIndex() {
|
function buildIndex() {
|
||||||
for (const ff of allFeatures.features.data) {
|
for (const ff of allFeatures.features.data) {
|
||||||
const f = ff.feature
|
const f = ff.feature
|
||||||
|
@ -227,7 +229,6 @@ function sliceToTiles(allFeatures: FeatureSource, theme: LayoutConfig, relations
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (SimpleMetaTaggers.country.runningTasks.size > 0) {
|
while (SimpleMetaTaggers.country.runningTasks.size > 0) {
|
||||||
console.log("Still waiting for ", SimpleMetaTaggers.country.runningTasks.size, " features which don't have a country yet")
|
console.log("Still waiting for ", SimpleMetaTaggers.country.runningTasks.size, " features which don't have a country yet")
|
||||||
await ScriptUtils.sleep(1)
|
await ScriptUtils.sleep(1)
|
||||||
|
@ -376,8 +377,6 @@ async function main(args: string[]) {
|
||||||
const lon1 = Number(args[6])
|
const lon1 = Number(args[6])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const tileRange = Tiles.TileRangeBetween(zoomlevel, lat0, lon0, lat1, lon1)
|
const tileRange = Tiles.TileRangeBetween(zoomlevel, lat0, lon0, lat1, lon1)
|
||||||
|
|
||||||
if (tileRange.total === 0) {
|
if (tileRange.total === 0) {
|
||||||
|
|
|
@ -6,7 +6,8 @@ import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
|
||||||
import Constants from "../Models/Constants";
|
import Constants from "../Models/Constants";
|
||||||
import {
|
import {
|
||||||
DesugaringContext,
|
DesugaringContext,
|
||||||
PrepareLayer, PrepareTheme,
|
PrepareLayer,
|
||||||
|
PrepareTheme,
|
||||||
ValidateLayer,
|
ValidateLayer,
|
||||||
ValidateThemeAndLayers
|
ValidateThemeAndLayers
|
||||||
} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert";
|
} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert";
|
||||||
|
@ -94,6 +95,32 @@ class LayerOverviewUtils {
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main(_: string[]) {
|
||||||
|
|
||||||
|
const licensePaths = new Set<string>()
|
||||||
|
for (const i in licenses) {
|
||||||
|
licensePaths.add(licenses[i].path)
|
||||||
|
}
|
||||||
|
|
||||||
|
const sharedLayers = this.buildLayerIndex(licensePaths);
|
||||||
|
const sharedThemes = this.buildThemeIndex(licensePaths, sharedLayers)
|
||||||
|
|
||||||
|
writeFileSync("./assets/generated/known_layers_and_themes.json", JSON.stringify({
|
||||||
|
"layers": Array.from(sharedLayers.values()),
|
||||||
|
"themes": Array.from(sharedThemes.values())
|
||||||
|
}))
|
||||||
|
|
||||||
|
writeFileSync("./assets/generated/known_layers.json", JSON.stringify(Array.from(sharedLayers.values())))
|
||||||
|
|
||||||
|
writeFileSync('./assets/themes/mapcomplete-changes/icons-mapping.txt', JSON.stringify(
|
||||||
|
Array.from(sharedThemes.values()).map(th => ({
|
||||||
|
if: "theme=" + th.id,
|
||||||
|
then: th.icon
|
||||||
|
}))
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private buildLayerIndex(knownImagePaths: Set<string>): Map<string, LayerConfigJson> {
|
private buildLayerIndex(knownImagePaths: Set<string>): Map<string, LayerConfigJson> {
|
||||||
// First, we expand and validate all builtin layers. These are written to assets/generated/layers
|
// First, we expand and validate all builtin layers. These are written to assets/generated/layers
|
||||||
|
@ -126,7 +153,6 @@ class LayerOverviewUtils {
|
||||||
return sharedLayers;
|
return sharedLayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private buildThemeIndex(knownImagePaths: Set<string>, sharedLayers: Map<string, LayerConfigJson>): Map<string, LayoutConfigJson> {
|
private buildThemeIndex(knownImagePaths: Set<string>, sharedLayers: Map<string, LayerConfigJson>): Map<string, LayoutConfigJson> {
|
||||||
console.log(" ---------- VALIDATING BUILTIN THEMES ---------")
|
console.log(" ---------- VALIDATING BUILTIN THEMES ---------")
|
||||||
const themeFiles = ScriptUtils.getThemeFiles();
|
const themeFiles = ScriptUtils.getThemeFiles();
|
||||||
|
@ -160,24 +186,6 @@ class LayerOverviewUtils {
|
||||||
return fixed;
|
return fixed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main(_: string[]) {
|
|
||||||
|
|
||||||
const licensePaths = new Set<string>()
|
|
||||||
for (const i in licenses) {
|
|
||||||
licensePaths.add(licenses[i].path)
|
|
||||||
}
|
|
||||||
|
|
||||||
const sharedLayers = this.buildLayerIndex(licensePaths);
|
|
||||||
const sharedThemes = this.buildThemeIndex(licensePaths, sharedLayers)
|
|
||||||
|
|
||||||
writeFileSync("./assets/generated/known_layers_and_themes.json", JSON.stringify({
|
|
||||||
"layers": Array.from(sharedLayers.values()),
|
|
||||||
"themes": Array.from(sharedThemes.values())
|
|
||||||
}))
|
|
||||||
|
|
||||||
writeFileSync("./assets/generated/known_layers.json", JSON.stringify(Array.from(sharedLayers.values())))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new LayerOverviewUtils().main(process.argv)
|
new LayerOverviewUtils().main(process.argv)
|
||||||
|
|
|
@ -3,6 +3,7 @@ import TiledFeatureSource from "../Logic/FeatureSource/TiledFeatureSource/TiledF
|
||||||
import StaticFeatureSource from "../Logic/FeatureSource/Sources/StaticFeatureSource";
|
import StaticFeatureSource from "../Logic/FeatureSource/Sources/StaticFeatureSource";
|
||||||
import * as readline from "readline";
|
import * as readline from "readline";
|
||||||
import ScriptUtils from "./ScriptUtils";
|
import ScriptUtils from "./ScriptUtils";
|
||||||
|
import {Utils} from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This script slices a big newline-delimeted geojson file into tiled geojson
|
* This script slices a big newline-delimeted geojson file into tiled geojson
|
||||||
|
@ -103,16 +104,23 @@ async function main(args: string[]) {
|
||||||
|
|
||||||
let allFeatures: any [];
|
let allFeatures: any [];
|
||||||
if (inputFile.endsWith(".geojson")) {
|
if (inputFile.endsWith(".geojson")) {
|
||||||
|
console.log("Detected geojson")
|
||||||
allFeatures = await readFeaturesFromGeoJson(inputFile)
|
allFeatures = await readFeaturesFromGeoJson(inputFile)
|
||||||
} else {
|
} else {
|
||||||
|
console.log("Loading as newline-delimited features")
|
||||||
allFeatures = await readFeaturesFromLineDelimitedJsonFile(inputFile)
|
allFeatures = await readFeaturesFromLineDelimitedJsonFile(inputFile)
|
||||||
}
|
}
|
||||||
|
allFeatures = Utils.NoNull(allFeatures)
|
||||||
|
|
||||||
|
|
||||||
console.log("Loaded all", allFeatures.length, "points")
|
console.log("Loaded all", allFeatures.length, "points")
|
||||||
|
|
||||||
const keysToRemove = ["STRAATNMID", "GEMEENTE", "POSTCODE"]
|
const keysToRemove = ["STRAATNMID", "GEMEENTE", "POSTCODE"]
|
||||||
for (const f of allFeatures) {
|
for (const f of allFeatures) {
|
||||||
|
if(f.properties === null){
|
||||||
|
console.log("Got a feature without properties!", f)
|
||||||
|
continue
|
||||||
|
}
|
||||||
for (const keyToRm of keysToRemove) {
|
for (const keyToRm of keysToRemove) {
|
||||||
delete f.properties[keyToRm]
|
delete f.properties[keyToRm]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue