Browse Source

fetch and optimize png from tileserver

master
Markus Bergholz 1 year ago
parent
commit
17c70ed267
1 changed files with 33 additions and 0 deletions
  1. +33
    -0
      osm/getTiles.py

+ 33
- 0
osm/getTiles.py View File

@ -0,0 +1,33 @@
from math import pow
import requests
import sys
import progressbar
from pathlib import Path
import pngquant
BASE_URL = 'https://mytileserver/{Z}/{X}/{Y}.png'
OUTPUT = '/home/m/osm/{Z}/{X}/{Y}.png'
pngquant.config(min_quality=50, max_quality=80)
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0'
}
def get_pngs(zoom):
max_x = int(pow(2,zoom)-1)
for x in range(0, max_x):
print(str(x) + '/' + str(max_x))
progress = progressbar.ProgressBar()
for y in progress(range(0, int(pow(2,zoom)-1))):
Path('/home/m/osm/{Z}/{X}'.format(X=x,Z=zoom)).mkdir(parents=True, exist_ok=True)
img_data = requests.get(BASE_URL.format(Z=zoom, X=x, Y=y), headers=headers).content
png = pngquant.quant_data(data=img_data)
with open(OUTPUT.format(Z=zoom,X=x,Y=y), 'wb') as handler:
handler.write(png[1])
if __name__ == '__main__':
zoom = int(sys.argv[1])
print("fetching " + str(pow(2,zoom)+ pow(2,zoom)) + " tiles" )
get_pngs(zoom)

Loading…
Cancel
Save