import Script from "./Script" import { Tiles } from "../src/Models/TileRange" class GeneratePmTilesExtractionScript extends Script { constructor() { super("Generates a bash script to extract all subpyramids of maxzoom=8 from planet-latest.pmtiles") } private emitRange(z: number, x: number, y: number, maxzoom?: number): string { const [[max_lat, min_lon], [min_lat, max_lon]] = Tiles.tile_bounds(z, x, y) let maxzoomflag = "" if(maxzoom !== undefined){ maxzoomflag = " --maxzoom="+maxzoom } return (`./pmtiles extract planet-latest.pmtiles --minzoom=${z}${maxzoomflag} --bbox=${[min_lon, min_lat + 0.0001, max_lon, max_lat].join(",")} ${z}-${x}-${y}.pmtiles`) } private generateField(z: number, maxzoom?:number){ const boundary = 2 << z for (let x = 0; x < boundary; x++) { const xCommands = [] for (let y = 0; y < boundary; y++) { xCommands.push(this.emitRange(z, x, y,maxzoom)) } console.log(xCommands.join(" && ") + " && echo 'All pyramids for x = " + x + " are generated' & ") } } async main(): Promise { this.generateField(0, 4) this.generateField(5, 8) this.generateField(9) } } new GeneratePmTilesExtractionScript().run()