osbng.indexing.geom_to_bng#
- osbng.indexing.geom_to_bng(geom: Geometry, resolution: int | str) list[BNGReference][source]#
Returns a
BNGReferencelist given aShapely Geometryand resolution.The
BNGReferencelist returned represents the grid squares intersected by the input geometry.BNGReferenceobjects are deduplicated in cases where two or more parts of a multi-part geometry intersect the same grid square.This function is useful for spatial indexing and aggregation of geometries against the BNG index system.
Notes
A note on the type of the input geometry. This also applies to the parts within a multi-part geometry:
For
Pointgeometries, the function returns a list comprising a singleBNGReference. ABNGExtentErrorexception is raised if the coordinates fall outside of the BNG index system extent.For
LineStringandPolygongeometry types, the function returns aBNGReferencelist representing the grid squares intersected by the geometry. When a geometry extends beyond the BNG index system extent, the function will show a feature bounding box warning but will still return aBNGReferencefor each of the intersected grid squares within the BNG index system extent.
- Parameters:
- Returns:
BNGReferencelist.- Return type:
- Raises:
BNGResolutionError – If an invalid resolution is provided.
ValueError – If the geometry type is not supported.
BNGExtentError – If the coordinates of a
Pointgeometry are outside of the BNG index system extent.
Examples
>>> geom_to_bng(Point(430000, 110000), "100km") [BNGReference(bng_ref_formatted=SU, resolution_label=100km)] >>> geom_to_bng( ... LineString([[430000, 110000], [430010, 110000], [430010, 110010]]), "5m" ... ) [BNGReference(bng_ref_formatted=SU 3000 1000 SE, resolution_label=5m), BNGReference(bng_ref_formatted=SU 3000 1000 SW, resolution_label=5m), BNGReference(bng_ref_formatted=SU 3000 1000 NE, resolution_label=5m)]
See also
For geometry decomposition by the BNG index system, use
geom_to_bng_intersection()orgdf_to_bng_intersection_explode()instead.