Skip to contents

Returns a set of BNG Reference objects given a geometry and a specified resolution.

Usage

geom_to_bng(geom, resolution, ...)

# S3 method for geos_geometry
geom_to_bng(geom, resolution, ...)

# S3 method for sf
geom_to_bng(geom, resolution, ...)

geom_to_bng_intersection(
  geom,
  resolution,
  format = c("geos", "sf", "wkt"),
  ...
)

# S3 method for geos_geometry
geom_to_bng_intersection(
  geom,
  resolution,
  format = c("geos", "sf", "wkt"),
  ...
)

# S3 method for sf
geom_to_bng_intersection(
  geom,
  resolution,
  format = c("geos", "sf", "wkt"),
  ...
)

Arguments

geom

geometry object of type geos-geometry or sf

resolution

spatial resolution of the BNG cell expressed in string or integer values

...

additional parameters. Not currently used.

format

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

Value

geom_to_bng: list of vectors of BNGReference objects where the number of items in the list equal length(geom).

geom_to_bng_intersection: list of nested lists with length(geom). Each nested list contains three named items:

  • "BNGReference" - BNGReference objects representing the grid squares corresponding to the decomposition.

  • "is_core" - logical vector indicating whether the grid square geometry is entirely contained by the input geometry. This is relevant for Polygon geometries and helps distinguish between "core" (fully inside) and "edge" (partially overlapping) grid squares.

  • "geom" - The geometry representing the intersection between the input geometry and the grid square. This can one of a number of geometry types depending on the overlap. When "is_core" is TRUE, "geom" is the same as the grid square geometry.

Details

The BNG Reference objects returned represent the grid squares intersected by the input geometry. BNG Reference objects are de-duplicated in cases where two or more parts of a multi-part geometry intersect the same grid square.

Unlike geom_to_bng which only returnS BNG Reference objects representing the grid squares intersected by the input geometry, geom_to_bng_intersection returns list objects that store the intersection between the input geometry and the grid square geometries.

These functions are useful for spatial indexing and aggregation of geometries against the BNG. For geometry decomposition by the BNG index system, use geom_to_bng_intersection instead.

Examples

geom_to_bng(geos::geos_make_point(430000, 110000), "100km")
#> <BNGReference[1] with Resolution=100km>
#> [1] <SU>

geom_to_bng(geos::geos_make_linestring(c(430000, 430010, 430010), c(110000,
110000, 110010)), "5m")
#> [[1]]
#> <BNGReference[3] with Resolution=5m>
#> [1] <SU 3000 1000 SW> <SU 3000 1000 SE> <SU 3000 1000 NE>
#> 

geom_to_bng_intersection(geos::geos_make_point(430000, 110000), "100km")
#> [[1]]
#> [[1]]$BNGReference
#> <BNGReference[1] with Resolution=100km>
#> [1] <SU>
#> 
#> [[1]]$is_core
#> [1] FALSE
#> 
#> [[1]]$geom
#> <geos_geometry[1]>
#> [1] <POINT (430000 110000)>
#> 
#> 

geom_to_bng_intersection(geos::geos_make_linestring(c(430000, 430010,
430010), c(110000, 110000, 110010)), "5m")
#> [[1]]
#> [[1]]$BNGReference
#> <BNGReference[3] with Resolution=5m>
#> [1] <SU 3000 1000 SW> <SU 3000 1000 SE> <SU 3000 1000 NE>
#> 
#> [[1]]$is_core
#> [1] FALSE FALSE FALSE
#> 
#> [[1]]$geom
#> <geos_geometry[3]>
#> [1] <LINESTRING (430000 110000, 430005 110000)>                                       
#> [2] <MULTILINESTRING ((430005 110000, 430010 110000), (430010 110000, 430010 110005))>
#> [3] <LINESTRING (430010 110005, 430010 110010)>                                       
#> 
#> 

geom_to_bng_intersection(geos::geos_make_polygon(c(375480.64511692,
426949.67604058, 465166.20199588, 453762.88376729, 393510.2158297,
375480.64511692), c(144999.23691181, 160255.02751493, 153320.57724078,
94454.79935802, 91989.21703833, 144999.23691181)), "50km")
#> [[1]]
#> [[1]]$BNGReference
#> <BNGReference[9] with Resolution=50km>
#> [1] <SY NE> <SZ NW> <SZ NE> <ST SE> <SU SW> <SU SE> <ST NE> <SU NW> <SU NE>
#> 
#> [[1]]$is_core
#> [1] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
#> 
#> [[1]]$geom
#> <geos_geometry[9]>
#> [1] <POLYGON ((393510.21583 91989.21704, 390785.61814 100000, 400000 100000, 400000 92254.78365, 393510.21583 91989.21704))>
#> [2] <POLYGON ((400000 92254.78365, 400000 100000, 450000 100000, 450000 94300.81946, 400000 92254.78365))>                  
#> [3] <POLYGON ((453762.88377 94454.79936, 450000 94300.81946, 450000 100000, 454837.08494 100000, 453762.88377 94454.79936))>
#> [4] <POLYGON [375481 100000...400000 150000]>                                                                               
#> [5] <POLYGON ((400000 100000, 450000 100000, 450000 150000, 400000 150000, 400000 100000))>                                 
#> [6] <POLYGON ((454837.08494 100000, 450000 100000, 450000 150000, 464522.94881 150000, 454837.08494 100000))>               
#> [7] <POLYGON ((400000 152266.94989, 400000 150000, 392351.90644 150000, 400000 152266.94989))>                              
#> [8] <POLYGON [400000 150000...450000 160255]>                                                                               
#> [9] <POLYGON ((465166.202 153320.57724, 464522.94881 150000, 450000 150000, 450000 156072.50905, 465166.202 153320.57724))> 
#> 
#>