Last active
September 14, 2023 21:38
-
-
Save celoyd/5561f4c331022a7b249235c8ecf43757 to your computer and use it in GitHub Desktop.
Draw an OSM daily aggregate tile traffic log to an image (proof of concept quality)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
draw_osm_day.py osm_tile_traffic_file.txt output_image.tiff | |
Write a float32 TIFF representing tile traffic in the OSM aggregate log. | |
Charlie Loyd, 2023-09-14. Inspired by https://en.osm.town/@pnorman/111062780453196500. | |
I recommend downloading the .xz compressed files and using xzcat to feed | |
them to this script. (Doing xz decompression in-script was slow.) E.g., | |
$ xzcat tiles-2022-03-15.txt.xz | python draw_osm_day.py - test.tiff | |
Alpha quality. Gotchas: | |
- zoom level is hard-coded | |
- ignores records below zoom level | |
- does no weighting or scaling of any kind | |
- etc. | |
""" | |
import numpy as np | |
from skimage import io | |
from sys import argv | |
src = argv[1] | |
if src == '-': | |
src = '/dev/stdin' | |
draw_zl = 10 | |
edge_length = int(2**draw_zl) | |
dst = np.zeros((edge_length, edge_length), dtype=np.float32) | |
for line in open(src): | |
zxy, count = line.split(" ") | |
z, x, y = [int(el) for el in zxy.split("/")] | |
# z, x, y are original tile coords. We convert those | |
# to pixel coords px and py, which are equivalent to | |
# what the tile at xyz would be covered by at z=zl. | |
# If input z is below zl (would be multiple pixels), | |
# we skip it. | |
zdiff = z - draw_zl | |
if zdiff < 0: | |
continue | |
px, py = [d >> zdiff for d in (x, y)] | |
dst[py, px] += float(count) | |
# Here you might run dst through, say, log10. | |
io.imsave(argv[2], dst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment