Hierarchy#
Navigate the hierarchical structure of the BNG index system.
The British National Grid (BNG) is structured using a hierarchical system of grid
squares at various resolutions. At its highest level, the grid divides GB into 100 km by
100 km squares, each identified by a two-letter code. Successive levels of resolution
further subdivide the grid squares into finer detail, down to individual 1-meter
squares. This module allows for the traversal of this hierarchy by providing methods to
return the parent and children of BNGReference objects at
specified resolutions.
- Parent and child definitions:
Parent: The parent of a
BNGReferenceobject is the grid square at the next higher (coarser) resolution level that contains the current reference. For example, the parent of a 1km grid square reference would be the 5km grid square that contains it.Children: The children of a
BNGReferenceobject are the grid squares at the next lower (finer) resolution level that are contained within the current reference. For example, the children of a 10km grid square reference would be the 5km grid squares that it contains.
Notes
While parent and child derivation defaults to the next higher and lower resolution, any supported resolution in the hierarchy can be specified.
- Supported Resolutions:
The module supports the ‘standard’ and ‘intermediate’ quadtree resolutions, including
100km,50km,10km,5km,1km,500m,100m,50m,10m,5mand1m.These resolutions passed to hierarchy functions are validated and normalised using the resolution mapping defined in the Resolution module.
- osbng.hierarchy.bng_to_children(bng_ref: BNGReference, *, resolution: int | str | None = None) list[BNGReference][source]#
Returns a list of child
BNGReferenceobjects of aBNGReference.By default, the children of the
BNGReferenceobject is defined as theBNGReferenceobjects in the next resolution down from the inputBNGReferenceresolution . For example, 100km -> 50km.Notes
Any valid resolution can be provided as the child resolution, provided it is less than the resolution of the input
BNGReference.- Parameters:
bng_ref (BNGReference) – The
BNGReferenceobject to derive children from.- Keyword Arguments:
resolution (int | str | None, optional) – The resolution of the children
BNGReferenceobjects expressed either as a metre-based integer or as a string label. Defaults to None.- Returns:
A list of
BNGReferenceobjects that are children of the inputBNGReferenceobject .- Return type:
- Raises:
BNGReferenceError – If the first positional argument is not a
BNGReferenceobject.BNGHierarchyError – If the resolution of the input
BNGReferenceobject is 1m.BNGHierarchyError – If the resolution is greater than or equal to the resolution of the input
BNGReferenceobject.BNGResolutionError – If an invalid resolution is provided.
Examples
>>> bng_to_children(BNGReference("SU")) [BNGReference(bng_ref_formatted=SU SW, resolution_label=50km), BNGReference(bng_ref_formatted=SU SE, resolution_label=50km), BNGReference(bng_ref_formatted=SU NW, resolution_label=50km), BNGReference(bng_ref_formatted=SU NE, resolution_label=50km)] >>> bng_to_children(BNGReference("SU36")) [BNGReference(bng_ref_formatted=SU 3 6 SW, resolution_label=5km), BNGReference(bng_ref_formatted=SU 3 6 SE, resolution_label=5km), BNGReference(bng_ref_formatted=SU 3 6 NW, resolution_label=5km), BNGReference(bng_ref_formatted=SU 3 6 NE, resolution_label=5km)]
See also
The equivalent
osbng.bng_reference.BNGReference.bng_to_children()instance method.bng_to_parentto derive theBNGReferenceobject in the next resolution up.
- osbng.hierarchy.bng_to_parent(bng_ref: BNGReference, *, resolution: int | str | None = None) BNGReference[source]#
Returns the BNGReference`that is the parent of a ``BNGReference`.
By default, the parent of the
BNGReferenceobject is defined as theBNGReferencein the next BNG resolution up from the inputBNGReferenceresolution. For example , 50km -> 100km.Notes
Any valid resolution can be provided as the parent resolution, provided it is greater than the resolution of the input
BNGReference.- Parameters:
bng_ref (BNGReference) – The
BNGReferenceobject to derive parent from.- Keyword Arguments:
resolution (int | str | None, optional) – The resolution of the parent
BNGReferenceobjects expressed either as a metre-based integer or as a string label. Defaults to None.- Returns:
A
BNGReferenceobject that is the parent of the inputBNGReferenceobject.- Return type:
- Raises:
BNGReferenceError – If the first positional argument is not a
BNGReferenceobject.BNGHierarchyError – If the resolution of the input
BNGReferenceobject is 100km.BNGHierarchyError – If the resolution is less than or equal to the resolution of the input
BNGReferenceobject.BNGResolutionError – If an invalid resolution is provided.
Examples
>>> bng_to_parent(BNGReference("SU 3 6 SW")) BNGReference(bng_ref_formatted=SU 3 6, resolution_label=10km) >>> bng_to_parent(BNGReference("SU 342 567")) BNGReference(bng_ref_formatted=SU 34 56 NW, resolution_label=500m) >>> bng_to_parent(BNGReference("SU 342 567"), resolution=10000) BNGReference(bng_ref_formatted=SU 3 5, resolution_label=10km)
See also
The equivalent
osbng.bng_reference.BNGReference.bng_to_parent()instance method.bng_to_childrento derive theBNGReferenceobjects in the next resolution down.