Inspect a Cell
Take a cell apart — its address, its place in the hierarchy, its shape family and its measured geometry.
import itacart
from itacart import index as ix, boundary, metrics
cell = itacart.geo_to_cell(-46.6328862, -23.5508962, resolution=9)
cell
'SW(0476/0260(4(A2(4(A4(1(E5(4(D4)))))))))'
The address, component by component
ix.split_components(cell)
['SW', '0476/0260', '4', 'A2', '4', 'A4', '1', 'E5', '4', 'D4']
Quadrant, base cell, then one refinement code per level. The two shortcuts save parsing it yourself:
ix.quadrant_of(cell), ix.base_cell_of(cell)
('SW', 'SW(0476/0260)')
Note the alternating alphabets: single digits on even levels, letter-digit pairs on odd ones. Which alphabet is legal at a position is fixed by the position, not chosen:
ix.is_valid_index("NE(0001/0002(1))"), ix.is_valid_index("NE(0001/0002(A1))")
(True, False)
Where it sits in the hierarchy
parent = itacart.get_parent(cell)
parent, itacart.child_position(cell)
('SW(0476/0260(4(A2(4(A4(1(E5(4))))))))', 18)
The parent is the address with its last component removed — ascent is truncation, not computation. The ancestors, coarse to fine:
itacart.get_ancestors(cell)
['SW',
'SW(0476/0260)',
'SW(0476/0260(4))',
'SW(0476/0260(4(A2)))',
'SW(0476/0260(4(A2(4))))',
'SW(0476/0260(4(A2(4(A4)))))',
'SW(0476/0260(4(A2(4(A4(1))))))',
'SW(0476/0260(4(A2(4(A4(1(E5)))))))',
'SW(0476/0260(4(A2(4(A4(1(E5(4))))))))']
Descending gives the siblings this cell belongs to. Pass flatten=True, or you
get one list per input cell rather than the cells themselves:
siblings = list(itacart.get_children(parent, flatten=True))
len(siblings), siblings[0]
(25, 'SW(0476/0260(4(A2(4(A4(1(E5(4(A1)))))))))')
Twenty-five, because resolution 9 is an odd level.
Which family it belongs to
boundary.cell_shape(cell), boundary.is_boundary_cell(cell), boundary.absorbs_border(cell)
('parallelogram', False, False)
An ordinary interior parallelogram. Compare against one of each other family:
[(c, boundary.cell_shape(c), itacart.is_equal_area_cell(c))
for c in (cell, "NE(0000/0500)", "SE(1930/0196)", "NE(0000/1000)")]
[('SW(0476/0260(4(A2(4(A4(1(E5(4(D4)))))))))', 'parallelogram', True),
('NE(0000/0500)', 'triangle', True),
('SE(1930/0196)', 'trapezoid', False),
('NE(0000/1000)', 'triangle', False)]
A meridian triangle keeps the nominal area; a border trapezoid does not; and a
polar cap is called a triangle and does not either. This is why the guard is
always is_equal_area_cell and never the shape name.
Polar & Border Cell Families.
Its geometry
itacart.cell_to_anchor(cell), itacart.cell_to_centroid(cell)
((-46.632885523707145, -23.550894698684775),
(-46.632887116254246, -23.550899213284907))
itacart.cell_to_boundary(cell, close=True)
[(-46.632885523707145, -23.550894698684775),
(-46.63289531785696, -23.550894698684775),
(-46.63288870880175, -23.550903727885043),
(-46.632878914651265, -23.550903727885043),
(-46.632885523707145, -23.550894698684775)]
And on the sinusoidal plane, where the lattice is regular:
itacart.cell_to_sinusoidal(cell)
(-4761300.0, -2605548.0)
Its measurements
(itacart.nominal_cell_area(9),
itacart.effective_cell_area(cell),
itacart.is_equal_area_cell(cell))
(1.0, 1.0, True)
Nominal and effective agree, which is the guarantee doing its job.
(round(metrics.cell_base_angle(cell), 6),
round(metrics.compactness(cell), 6),
round(metrics.normalized_cell_area(cell), 6))
(55.988672, 0.645342, 1.0)
The base angle is what the sinusoidal plane’s forty-five degrees becomes on the ellipsoid — it varies across the lattice and is measured, not predicted. The other two are transcriptions of published conventions, for comparing this grid against others; each states where its convention stops being trustworthy. Area, Perimeter & Compactness.
Is it where you think it is?
from itacart import interop
interop.cell_to_wkt(cell)
'POLYGON ((-46.632885523707145 -23.550894698684775, -46.63289531785696 -23.550894698684775, -46.63288870880175 -23.550903727885043, -46.632878914651265 -23.550903727885043, -46.632885523707145 -23.550894698684775))'