itacart.geometry.cells_to_geometry

itacart.geometry.cells_to_geometry(cells, geometry_type='Polygon')[source]

Rebuild a geometry from an ordered vertex cell list.

Inverse of vertex_to_cell(). Every vertex is rebuilt at the representative position of its cell, the centroid, which is the point itacart.cells.cell_to_centroid() returns and itacart.engine.describe() declares. There is no argument choosing another: the anchor is a vertex of the cell, on its boundary rather than within it, and it does not answer the question this function asks.

What a rebuilt vertex promises. It lies within the cell that encoded the original vertex and quantizes back to that cell at the same resolution, in every family, extension zones and polar caps included. Its distance from the original is at most the cell’s reach: the distance from the centroid to the cell’s farthest vertex. For an ordinary parallelogram of side l the reach follows the shear of the projection:

l * max(sqrt(1 + u**2) / 2, sqrt((1 - u / 2)**2 + 1 / 4))
u = |lon * sin(lat)|, with lon in radians, at the centroid

which is 1.118 l on the prime meridian, 0.707 l at its minimum where u = 1, and 1.65 l as u reaches pi. That is the reach to first order in the side, and itacart.metrics.cell_max_uncertainty() returns the reach of any cell. A finite cell departs from the law in proportion to its side, and most near the pole: over the population that function documents, which runs through the last rows before the polar row and past u = pi in Chukotka, the reach of a regular parallelogram exceeds the law by at most 4.2e-3 * l / 10 km below 85 degrees of latitude and 0.2 * l / 10 km from 85 degrees to row 998, plus up to 1e-6 from the rounding of the coordinates.

Three families are not bounded by that law, and are named rather than folded into it. A prime-meridian triangle reaches sqrt(10) / 3 * l to first order, and a finite one falls short of it: by at most 2.7e-3 * l / 10 km below 85 degrees and 0.13 * l / 10 km from 85 degrees to row 998, over the triangles of rows 930 to 998 and down the prime meridian to resolution 13. A cell that absorbs the domain border, a polar-row cell and a cap cell reach further: up to 2.06 l over the last existing column of every resolution-1 row in the four quadrants, together with the border, polar-row and cap cells of a lattice of the four quadrants at five resolutions from 10 km to 1 cm and both caps at every resolution. That is a measurement over the population named, not a bound beyond it.

Precision. Coordinates are returned at full double precision and never rounded. How precisely a rebuilt vertex is known is declared by the resolution of its cell, not by its digits: section 3.1.10 of RFC 7946 says the number of digits of a coordinate does not indicate its uncertainty, so a coordinate cannot carry it and an index can. Rounding would also destroy what it claims to summarise: resolution-13 neighbours lie about 9e-8 degree of latitude apart, and at six decimal places their centroids become one point.

The inverse is exact for a hole-free geometry only. vertex_to_cell() returns one flat sequence with the holes appended to the exterior, and a flat sequence does not say where the exterior ended. A caller needing holes keeps the rings apart and calls this once per ring.

Parameters:
  • cells (list[str]) – Atomic index strings in traversal order.

  • geometry_type (str, default: "Polygon") – OGC SFA type to build: Point, LineString, LinearRing, Polygon or MultiPoint.

Return type:

BaseGeometry

Returns:

A Shapely geometry in EPSG –

Raises:
  • UnsupportedGeometryTypeError – On unsupported types.

  • GeometryError – If the cell count cannot make the type asked for.

  • NonExistentCellError – If any cell of the index names no cell. The predicate is the arbiter and the contract ends there: a spelling it denies is refused rather than answered for the cell it would otherwise fold onto.