Skip to contents

Create British National Grid reference from bounding boxes or convert grid reference objects into bounding boxes.

Usage

bbox_to_bng(...)

# S3 method for numeric
bbox_to_bng(xmin, ymin, xmax, ymax, resolution, ...)

# S3 method for matrix
bbox_to_bng(x, resolution, ...)

bng_to_bbox(bng_ref, ...)

bng_to_grid_geom(bng_ref, format = c("geos", "sf", "wkt"), ...)

Arguments

...

additional parameters, not currently used

xmin, ymin, xmax, ymax

numeric vector of bounding box coordinates

resolution

the resolution of the BNG reference expressed either as a metre-based integer or as a string label

x

optional input of the bounding box as a matrix of values

bng_ref

vector of type BNGReference objects

format

character indicating the type of geometry object to return. Default is "geos" while "sf" returns an object of class sfc.

Value

  • bng_to_bbox: numeric vector of bounding easting and northing coordinates. If multiple references are supplied to bng_ref then a matrix of coordinates is returned.

  • bbox_to_bng: list containing vectors of BNGReference objects.

  • bng_to_grid_geom converts the bounding box coordinates into a polygon geometry object.

Details

The relationship between the bounding box and the returned BNG grid squares depends on the alignment of the bounding box with the BNG index system:

If the bounding box edges align with the BNG system (e.g. xmin, ymin, xmax, ymax are multiples of the specified resolution), only the grid squares entirely contained within the bounding box are returned. Grid squares that intersect but are not fully contained within the bounding box are excluded.

If the bounding box edges are not aligned with the BNG system, grid squares that are partially overlapped by the bounding box are also included. In this case, the function ensures all relevant grid squares that the bounding box touches are returned, including those at the edges.

Validates and normalises the bounding box coordinates to the BNG index system extent. If bounding box coordinates fall outside of the BNG system extent, the coordinates are snapped to the bounds of the BNG system.

Bounding boxes are expressed as four coordinates (min x, min y, max x, max y). Coordinates must be in British National Grid projection (EPSG:27700). These functions do not support coordinate transformations.

Examples

bbox_to_bng(400000, 100000, 500000, 200000, "50km")
#> [[1]]
#> <BNGReference[4] with Resolution=50km>
#> [1] <SU SW> <SU SE> <SU NW> <SU NE>
#> 

bbox_to_bng(285137.06, 78633.75, 299851.01, 86427.96, 5000)
#> [[1]]
#> <BNGReference[9] with Resolution=5km>
#> [1] <SX 8 7 NE> <SX 9 7 NW> <SX 9 7 NE> <SX 8 8 SE> <SX 9 8 SW> <SX 9 8 SE>
#> [7] <SX 8 8 NE> <SX 9 8 NW> <SX 9 8 NE>
#> 

bng_to_bbox(as_bng_reference("SU"))
#>       [,1]  [,2]  [,3]  [,4]
#> [1,] 4e+05 1e+05 5e+05 2e+05

bng_to_bbox(as_bng_reference("SU 3 1"))
#>        [,1]   [,2]   [,3]   [,4]
#> [1,] 430000 110000 440000 120000

bng_to_bbox(as_bng_reference("SU 3 1 NE"))
#>        [,1]   [,2]   [,3]   [,4]
#> [1,] 435000 115000 440000 120000

bng_to_bbox(as_bng_reference("SU 37289 15541"))
#>        [,1]   [,2]   [,3]   [,4]
#> [1,] 437289 115541 437290 115542

bng_to_grid_geom(as_bng_reference("SU"))
#> <geos_geometry[1]>
#> [1] <POLYGON ((400000 100000, 500000 100000, 500000 200000, 400000 200000, 400000 100000))>

bng_to_grid_geom(as_bng_reference("SU 3 1"))
#> <geos_geometry[1]>
#> [1] <POLYGON ((430000 110000, 440000 110000, 440000 120000, 430000 120000, 430000 110000))>

bng_to_grid_geom(as_bng_reference("SU 3 1 NE"))
#> <geos_geometry[1]>
#> [1] <POLYGON ((435000 115000, 440000 115000, 440000 120000, 435000 120000, 435000 115000))>

bng_to_grid_geom(as_bng_reference("SU 37289 15541"))
#> <geos_geometry[1]>
#> [1] <POLYGON ((437289 115541, 437290 115541, 437290 115542, 437289 115542, 437289 115541))>