#!/usr/bin/python3 # lädt und zeigt eine Landkarte, auf man die EAH sieht, # von Webseite der OpenStreetMap Foundation (AHG, 2022) import requests from math import pi, pow, log, radians, tan from io import BytesIO from PIL import Image from subprocess import run # Variables defining the map of the EAH Jena lat, lon = 50.918890, 11.569350 # geogr. coordinates zoom = 18 # zoom factor (integer between 0 and 18) nx = 3 # number of tiles to add east and west ny = 2 # number of tiles to add north and south # Web Mercator projection and scale -> tile coordinates z = pow(2, zoom) ; b = radians(lat) x = int( z * (lon/360.0 + 0.5) ) y = int( (z/(2.0*pi)) * (pi-log(tan(pi/4.0+b/2.0))) ) # Download and concatenation of tiles to form an image kx = ky = 0 # indices for tile column and tile row o = "https://tile.openstreetmap.org/" # OpenStreetMap img = Image.new('RGB',((2*nx+1)*256,(2*ny+1)*256)) kx = 0 # reset the index for tile column for i in range(x-nx,x+nx+1): ky = 0 # reset the index for tile row for j in range(y-ny,y+ny+1): u = o+str(zoom)+"/"+str(i)+"/"+str(j)+".png" with requests.get(u) as r: tile = Image.open(BytesIO(r.content)) img.paste(tile,(kx*256,ky*256)) ky = ky + 1 kx = kx + 1 # Save and show image (end with key "q") img.save("geo.png") # save image run(["fbi","-a","geo.png"]) # show image with autozoom