Created
February 22, 2025 19:06
-
-
Save andyfowler/91a4ddcefaa4260b7e7ab50d3b97f0af to your computer and use it in GitHub Desktop.
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
WITH | |
bitShiftLeft(1::UInt64, {z:UInt8}) AS zoom_factor, | |
bitShiftLeft(1::UInt64, 32 - {z:UInt8}) AS tile_size, | |
tile_size * {x:UInt16} AS tile_x_begin, | |
tile_size * ({x:UInt16} + 1) AS tile_x_end, | |
tile_size * {y:UInt16} AS tile_y_begin, | |
tile_size * ({y:UInt16} + 1) AS tile_y_end, | |
mercator_x >= tile_x_begin AND mercator_x < tile_x_end | |
AND mercator_y >= tile_y_begin AND mercator_y < tile_y_end AS in_tile, | |
bitShiftRight(mercator_x - tile_x_begin, 32 - 10 - {z:UInt8}) AS x, | |
bitShiftRight(mercator_y - tile_y_begin, 32 - 10 - {z:UInt8}) AS y, | |
y * 1024 + x AS pos, | |
count() AS total, | |
greatest(1000000 DIV {sampling:UInt32} DIV zoom_factor, count()) AS max_total, | |
pow(total / max_total, 1/5) AS transparency, | |
greatest(0, least(avg(altitude), 1000)) / 1000 AS color1, | |
greatest(0, least(avg(altitude), 10000)) / 10000 AS color3, | |
greatest(0, least(avg(ground_speed), 150)) / 150 AS color2, | |
255 AS alpha, | |
(1 + transparency) / 2 * (1 - color3) * 255 AS red, | |
transparency * color1 * 255 AS green, | |
color2 * 255 AS blue | |
SELECT round(red)::UInt8, round(green)::UInt8, round(blue)::UInt8, round(alpha)::UInt8 | |
FROM {table:Identifier} | |
WHERE in_tile AND aircraft_flight in ('N222UM', 'N333UM', 'N4614B', 'N68334', 'N68963', 'N9640V', 'N572RJ', 'N53703', 'N203GT', 'N6860H', 'N1377S', 'N120WE') | |
GROUP BY pos ORDER BY pos WITH FILL FROM 0 TO 1024*1024 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment