forked from MapComplete/MapComplete
		
	Scripts: fix generateStatistics-script
This commit is contained in:
		
							parent
							
								
									83fc189fd3
								
							
						
					
					
						commit
						a1bbc4e689
					
				
					 2 changed files with 24 additions and 43 deletions
				
			
		| 
						 | 
					@ -2,10 +2,9 @@ import { existsSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from
 | 
				
			||||||
import ScriptUtils from "./ScriptUtils"
 | 
					import ScriptUtils from "./ScriptUtils"
 | 
				
			||||||
import { Utils } from "../Utils"
 | 
					import { Utils } from "../Utils"
 | 
				
			||||||
import Script from "./Script"
 | 
					import Script from "./Script"
 | 
				
			||||||
import TiledFeatureSource from "../Logic/FeatureSource/TiledFeatureSource/TiledFeatureSource"
 | 
					 | 
				
			||||||
import StaticFeatureSource from "../Logic/FeatureSource/Sources/StaticFeatureSource"
 | 
					 | 
				
			||||||
import { GeoOperations } from "../Logic/GeoOperations"
 | 
					import { GeoOperations } from "../Logic/GeoOperations"
 | 
				
			||||||
import { Feature, Polygon } from "geojson"
 | 
					import { Feature, Polygon } from "geojson"
 | 
				
			||||||
 | 
					import { Tiles } from "../Models/TileRange"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class StatsDownloader {
 | 
					class StatsDownloader {
 | 
				
			||||||
    private readonly urlTemplate =
 | 
					    private readonly urlTemplate =
 | 
				
			||||||
| 
						 | 
					@ -275,24 +274,12 @@ class GenerateSeries extends Script {
 | 
				
			||||||
        const centerpoints = allFeatures.map((f) => GeoOperations.centerpoint(f))
 | 
					        const centerpoints = allFeatures.map((f) => GeoOperations.centerpoint(f))
 | 
				
			||||||
        console.log("Found", centerpoints.length, " changesets in total")
 | 
					        console.log("Found", centerpoints.length, " changesets in total")
 | 
				
			||||||
        const path = `${targetDir}/all_centerpoints.geojson`
 | 
					        const path = `${targetDir}/all_centerpoints.geojson`
 | 
				
			||||||
        /*fs.writeFileSync(
 | 
					
 | 
				
			||||||
            path,
 | 
					        const perBbox = GeoOperations.spreadIntoBboxes(centerpoints, options.zoomlevel)
 | 
				
			||||||
            JSON.stringify(
 | 
					
 | 
				
			||||||
                {
 | 
					        for (const [tileNumber, features] of perBbox) {
 | 
				
			||||||
                    type: "FeatureCollection",
 | 
					            const [z, x, y] = Tiles.tile_from_index(tileNumber)
 | 
				
			||||||
                    features: centerpoints,
 | 
					            const path = `${targetDir}/tile_${z}_${x}_${y}.geojson`
 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                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) => {
 | 
					            features.forEach((f) => {
 | 
				
			||||||
                delete f.bbox
 | 
					                delete f.bbox
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
| 
						 | 
					@ -307,15 +294,9 @@ class GenerateSeries extends Script {
 | 
				
			||||||
                    "  "
 | 
					                    "  "
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
                ScriptUtils.erasableLog(
 | 
					
 | 
				
			||||||
                    "Written ",
 | 
					            ScriptUtils.erasableLog("Written ", path, "which has ", features.length, "features")
 | 
				
			||||||
                    path,
 | 
					        }
 | 
				
			||||||
                    "which has ",
 | 
					 | 
				
			||||||
                    tile.features.data.length,
 | 
					 | 
				
			||||||
                    "features"
 | 
					 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,7 @@ async function main(includeTags = true) {
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const sources = TagUtils.Tag(layer.source.osmTags)
 | 
					        const sources = TagUtils.Tag(layer.source["osmTags"])
 | 
				
			||||||
        const allKeys = sources.usedKeys()
 | 
					        const allKeys = sources.usedKeys()
 | 
				
			||||||
        for (const key of allKeys) {
 | 
					        for (const key of allKeys) {
 | 
				
			||||||
            if (!keysAndTags.has(key)) {
 | 
					            if (!keysAndTags.has(key)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue