Browse Source

optimize

master
Markus Bergholz 1 year ago
parent
commit
c9a404ba92
1 changed files with 13 additions and 4 deletions
  1. +13
    -4
      osm/getTiles.py

+ 13
- 4
osm/getTiles.py View File

@ -4,24 +4,33 @@ import sys
import progressbar
from pathlib import Path
import pngquant
from random import randrange
BASE_URL = 'https://mytileserver/{Z}/{X}/{Y}.png'
OUTPUT = '/home/m/osm/{Z}/{X}/{Y}.png'
server = ['a','b','c']
FOLDER = '/home/m/osm'
OUTPUT = HOME + '/{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 base_url(zoom, x, y):
BASE_URL = 'https://{SERVER}.tile.openstreetmap.org/{Z}/{X}/{Y}.png'
return BASE_URL.format(Z=zoom, X=x, Y=y, SERVER=server[randrange(3)])
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)
Path(HOME + '/{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
img_data = requests.get(base_url(zoom, x, 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])


Loading…
Cancel
Save