23 a5 fast
In [1]:
Copied!
%pip install a5_fast
%pip install a5_fast
Collecting a5_fast Using cached a5_fast-0.2.1-cp313-cp313-win_amd64.whl.metadata (2.2 kB) Using cached a5_fast-0.2.1-cp313-cp313-win_amd64.whl (166 kB) Installing collected packages: a5_fast Successfully installed a5_fast-0.2.1 Note: you may need to restart the kernel to use updated packages.
[notice] A new release of pip is available: 25.3 -> 26.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip
In [7]:
Copied!
import a5_fast
# Convert (lon, lat) to a cell index at resolution 5
cell = a5_fast.lonlat_to_cell(13.4, 52.5, 5)
cell
import a5_fast
# Convert (lon, lat) to a cell index at resolution 5
cell = a5_fast.lonlat_to_cell(13.4, 52.5, 5)
cell
Out[7]:
7205196453839372288
In [8]:
Copied!
# Get the centre of a cell
lon, lat = a5_fast.cell_to_lonlat(cell)
print (lon, lat)
# Get the centre of a cell
lon, lat = a5_fast.cell_to_lonlat(cell)
print (lon, lat)
13.307262551006033 52.51990354028486
In [10]:
Copied!
# Get the boundary polygon of a cell
boundary = a5_fast.cell_to_boundary(cell)
boundary
# Get the boundary polygon of a cell
boundary = a5_fast.cell_to_boundary(cell)
boundary
Out[10]:
[(12.33927896786669, 52.86789216215701), (11.988768957646613, 52.18120364903989), (11.65026899860898, 51.4922954888735), (12.779638713673677, 51.59762297993924), (13.914394881970011, 51.693414013322766), (14.449960154041364, 52.221381003634946), (15.0, 52.74633016262496), (14.524364533709885, 53.299474403380614), (14.034747736340393, 53.849993501436046), (13.143555527484438, 53.372460379093155), (12.33927896786669, 52.86789216215701)]
In [12]:
Copied!
# Batch convert coordinates (flat list: [lon0, lat0, lon1, lat1, ...])
cells = a5_fast.lonlat_to_cell_batch([13.4, 52.5, -73.9, 40.7], 5)
cells
# Batch convert coordinates (flat list: [lon0, lat0, lon1, lat1, ...])
cells = a5_fast.lonlat_to_cell_batch([13.4, 52.5, -73.9, 40.7], 5)
cells
Out[12]:
[7205196453839372288, 2739877423301525504]
In [25]:
Copied!
# Traverse the hierarchy
parent = a5_fast.cell_to_parent(cell,1)
print('parent: ', parent)
children = a5_fast.cell_to_children(cell,6)
print('children: ', children)
# Traverse the hierarchy
parent = a5_fast.cell_to_parent(cell,1)
print('parent: ', parent)
children = a5_fast.cell_to_children(cell,6)
print('children: ', children)
parent: 6989586621679009792 children: [7204774241374306304, 7205055716351016960, 7205337191327727616, 7205618666304438272]
In [22]:
Copied!
# Neighbours within k hops
disk = a5_fast.grid_disk(cell, 1)
disk
# Neighbours within k hops
disk = a5_fast.grid_disk(cell, 1)
disk
Out[22]:
[864128178501713920, 865254078408556544, 5860871965069279232, 7202944654025687040, 7205196453839372288, 7685955714061172736]
In [26]:
Copied!
# Compact / uncompact cell sets
compacted = a5_fast.compact(cells)
print ('compacted: ', compacted)
expanded = a5_fast.uncompact(compacted, 5)
print ('expanded: ', expanded)
# Compact / uncompact cell sets
compacted = a5_fast.compact(cells)
print ('compacted: ', compacted)
expanded = a5_fast.uncompact(compacted, 5)
print ('expanded: ', expanded)
compacted: [2739877423301525504, 7205196453839372288] expanded: [2739877423301525504, 7205196453839372288]
In [27]:
Copied!
# Hex conversion
hex_str = a5_fast.u64_to_hex(cell)
cell = a5_fast.hex_to_u64(hex_str)
cell
# Hex conversion
hex_str = a5_fast.u64_to_hex(cell)
cell = a5_fast.hex_to_u64(hex_str)
cell
Out[27]:
7205196453839372288
In [29]:
Copied!
# Metadata
res = a5_fast.get_resolution(cell)
area = a5_fast.cell_area(5) # area in m² at resolution 5
n = a5_fast.get_num_cells(5) # total cells at resolution 5
base = a5_fast.get_res0_cells() # the 12 resolution-0 cells
print (res, area, n, base)
# Metadata
res = a5_fast.get_resolution(cell)
area = a5_fast.cell_area(5) # area in m² at resolution 5
n = a5_fast.get_num_cells(5) # total cells at resolution 5
base = a5_fast.get_res0_cells() # the 12 resolution-0 cells
print (res, area, n, base)
5 33207397446.578068 15360 [144115188075855872, 432345564227567616, 720575940379279360, 1008806316530991104, 1297036692682702848, 1585267068834414592, 1873497444986126336, 2161727821137838080, 2449958197289549824, 2738188573441261568, 3026418949592973312, 3314649325744685056]