Skip to content

Commit 222ff7a

Browse files
Update the map maker script
1 parent faedb4f commit 222ff7a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

tools/make_world_map_img.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
import requests
66

77
ZOOM = 7
8+
DELAY = 0.035
89

9-
# Headers for request
10+
# Extra headers for request
1011
HEADERS = {
11-
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
12-
"Connection": "keep-alive",
13-
"Host": "tile.openstreetmap.org",
14-
"User-Agent": "Requests Python3.11",
1512
"Accept-Language": "en-AU,en;q=0.9",
16-
"Accept-Encoding": "gzip, deflate, br",
13+
"User-Agent": "Requests Python3.11",
1714
"Priority": "u=0, i"
1815
}
1916

17+
# Requests session
18+
s = requests.Session()
19+
s.headers = s.headers.update(HEADERS)
20+
2021
# Calculate number of tiles
2122
X_TILES = int(2**ZOOM)
2223
Y_TILES = int(2**ZOOM)
@@ -57,18 +58,23 @@ def join_tiled_images(image_paths, x_tiles, y_tiles, output_path):
5758
# Download Tiles
5859
print("Downloading Tiles")
5960
image_array = []
61+
LAST_DL_TIME = 0.25
6062
for x in range(X_TILES):
6163
for y in range(Y_TILES):
62-
print("Downloading:", x, y)
63-
r_image = requests.get(f"http://tile.openstreetmap.org/{ZOOM}/{x}/{y}.png",
64-
timeout=20, headers=HEADERS)
65-
if not os.path.exists(f"/tmp/map-tiles/{x}"):
66-
os.makedirs(f"/tmp/map-tiles/{x}")
67-
with open(f"/tmp/map-tiles/{x}/{y}.png", "wb") as image:
64+
print(f"\rDownloading: {x:4} {y:4}. DL Time: {((X_TILES*Y_TILES)-len(image_array))*(DELAY+LAST_DL_TIME)/60:6.2f} Minutes",
65+
end="", flush=True)
66+
r_image = s.get(f"http://tile.openstreetmap.org/{ZOOM}/{x}/{y}.png", timeout=20)
67+
LAST_DL_TIME = (LAST_DL_TIME+(r_image.elapsed.microseconds/1000000))/2
68+
if not os.path.exists(f"/tmp/map-tiles/{ZOOM}/{x}"):
69+
os.makedirs(f"/tmp/map-tiles/{ZOOM}/{x}")
70+
with open(f"/tmp/map-tiles/{ZOOM}/{x}/{y}.png", "wb") as image:
6871
image.write(r_image.content)
69-
image_array.append(f"/tmp/map-tiles/{x}/{y}.png")
70-
sleep(0.01)
72+
image_array.append(f"/tmp/map-tiles/{ZOOM}/{x}/{y}.png")
73+
sleep(DELAY)
74+
print('')
7175

7276
# Make Map
7377
print("Making image array")
7478
join_tiled_images(image_array, X_TILES, Y_TILES, "sdcard/ADSB/world_map.png")
79+
80+
s.close()

0 commit comments

Comments
 (0)