Quick Start

A first session. Every cell below runs when this page is built, so what you read is what the installed package actually returned.

import itacart

Address a position

Give a longitude, a latitude and a resolution. Resolution 13 is one centimetre:

cell = itacart.geo_to_cell(-46.6328862, -23.5508962, resolution=13)
cell
'SW(0476/0260(4(A2(4(A4(1(E5(4(D4(1(B2(4(B4)))))))))))))'

The nesting is the hierarchy: each parenthesis is one step down the resolution ladder, and the whole string is the cell’s address at every level at once.

Go back to geography

lon, lat = itacart.cell_to_centroid(cell)
lon, lat
(-46.632886245130635, -23.550896188502815)

The boundary comes back as a ring of coordinates:

ring = itacart.cell_to_boundary(cell, close=True)
len(ring), ring[0]
(5, (-46.63288622920516, -23.550896143356816))

Move up and down the hierarchy

The parent is one resolution coarser:

parent = itacart.get_parent(cell)
parent
'SW(0476/0260(4(A2(4(A4(1(E5(4(D4(1(B2(4))))))))))))'

Descending gives every child. Pass flatten=True to get the children themselves rather than a grouping:

children = list(itacart.get_children(parent, flatten=True))
len(children), children[0]
(25, 'SW(0476/0260(4(A2(4(A4(1(E5(4(D4(1(B2(4(A1)))))))))))))')

Twenty-five, because resolution 13 is an odd level. Even levels refine into four. The count is obtained by enumeration rather than by multiplication, which matters near the domain border, where a cell can hold fewer children than the ratio predicts — Parent, Children & Descendants covers that case.

Move sideways

neighbours = itacart.grid_disk(cell, k_distance=1)
len(neighbours)
9

Measure an area

Area is a count multiplied by a constant, because the cells are equal-area:

itacart.nominal_cell_area(13)
0.0001

For a real parcel, fill it and count what fell inside:

from shapely.geometry import Polygon

parcel = Polygon([
    (-46.6329, -23.5509), (-46.6327, -23.5509),
    (-46.6327, -23.5507), (-46.6329, -23.5507),
])
covered = itacart.count_internal_cells(parcel, 9)
covered, covered * itacart.nominal_cell_area(9)
(468, 468.0)

The second number is square metres. No conversion factor appears anywhere, which is the practical consequence of the areas being decimal.

Where to go next

Highlights states what the grid guarantees. Cell Filling / Polyfill covers covering a polygon properly, including the choice of containment mode, and Example Notebooks works each of these through at length.