MCPcopy
hub / github.com/protomaps/PMTiles / zxy_to_tileid

Function zxy_to_tileid

python/pmtiles/pmtiles/tile.py:46–61  ·  view source on GitHub ↗
(z: int, x: int, y: int)

Source from the content-addressed store, hash-verified

44
45
46def zxy_to_tileid(z: int, x: int, y: int) -> int:
47 if z > 31:
48 raise OverflowError("tile zoom exceeds 64-bit limit")
49 if x > (1 << z) - 1 or y > (1 << z) - 1:
50 raise ValueError("tile x/y outside zoom level bounds")
51
52 acc = ((1 << (z * 2)) - 1) // 3
53 a = z - 1
54 while a >= 0:
55 s = 1 << a
56 rx = s & x
57 ry = s & y
58 acc += ((3 * rx) ^ ry) << a
59 (x, y) = rotate(s, x, y, rx, ry)
60 a -= 1
61 return acc
62
63
64def tileid_to_zxy(tile_id: int) -> tuple[int, int, int]:

Callers 12

test_zxy_to_tileidMethod · 0.90
test_many_tilesMethod · 0.90
test_tile_extremesMethod · 0.90
test_invalid_tilesMethod · 0.90
test_roundtripMethod · 0.90
test_all_tilesMethod · 0.90
pmtilesFunction · 0.90
getMethod · 0.85
mbtiles_to_pmtilesFunction · 0.85
disk_to_pmtilesFunction · 0.85

Calls 1

rotateFunction · 0.70

Tested by 7

test_zxy_to_tileidMethod · 0.72
test_many_tilesMethod · 0.72
test_tile_extremesMethod · 0.72
test_invalid_tilesMethod · 0.72
test_roundtripMethod · 0.72
test_all_tilesMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…