itacart.serialization.geometry_blob.encode_geometry
- itacart.serialization.geometry_blob.encode_geometry(rings, geometry_type='POLYGON', edge_model='WGS84_GEODESIC', densification_model='ORTHODROMIC_VINCENTY', max_segment_m=1000, resolution=13, canonicalize=True)[source]
Encode ordered vertex rings as a GeometryBlob.
Ring orientation is significant and is preserved exactly. Canonicalisation may rotate a closed ring to its least starting vertex; it never reverses one, because rotating is a change of spelling and reversing is a change of meaning.
Which ring is the exterior and which are holes is carried here by part order — the first ring of a component is its exterior — and not by reading the winding. Winding is preserved to the byte all the same, because many producers and consumers use direction to carry that same distinction, and a ring handed on reversed may be read downstream as the opposite kind of ring. The common convention is counter-clockwise for an exterior boundary and clockwise for a hole:
exterior = [A, B, C, D] # counter-clockwise hole = [E, H, G, F] # clockwise: E, F, G, H reversed
Reversing either sequence changes its identity: the bytes differ and so does the hash. Nothing here reverses a ring to make it agree with a convention, and nothing here checks that it does.
- Parameters:
rings (
Sequence[Any]) – Rings as lists of atomic index strings, exterior first. MULTIPOLYGON nests one level deeper, as a list of polygons, because a flat list cannot say which hole belongs to which polygon.geometry_type (
str, default:"POLYGON") – One of POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON.edge_model (
str, default:"WGS84_GEODESIC") – How edges between vertices are interpreted.densification_model (
str, default:"ORTHODROMIC_VINCENTY") – Whether the producer ran Vincenty densification or merely guarantees the segment bound.max_segment_m (
int, default:1000) – Densification bound in metres, 0 to 65 535.resolution (
int, default:13) – Uniform resolution of every vertex cell.canonicalize (
bool, default:True) – Apply minimum lexicographic cyclic rotation to closed rings. Directional types are never rotated.
- Return type:
- Returns:
The binary blob.
- Raises:
UnsupportedGeometryTypeError – On unsupported types.
GeometryError – If ring structure contradicts the declared type.
IncompatibleProfileError – On an invalid edge model and densification model combination.
Example
>>> blob = encode_geometry([["NE(0625/0451)"]], "POINT", resolution=1) >>> read_geometry_type(blob) 'POINT'
Rotation is a spelling; reversal is not:
>>> ring = ["NE(0625/0451(1))", "NE(0625/0451(2))", "NE(0625/0451(3))"] >>> encode_geometry([ring], resolution=2) == encode_geometry( ... [ring[1:] + ring[:1]], resolution=2 ... ) True >>> encode_geometry([ring], resolution=2) == encode_geometry( ... [list(reversed(ring))], resolution=2 ... ) False