/spatial_utilities

🌍 Spatial utilities in Python

Primary LanguagePythonOtherNOASSERTION

Spatial Tools and Utilities

The United Kingdom postcodes to British National Grid References

File: postcode_to_british_national_grid.ipynb

CSV and Parquet files can be generated using postcode_to_british_national_grid.ipynb notebook.

Maps UK postcodes to British national grid references and produces parquet and CSV files containing 100, 50, 20, 10, 5, 1km grid references and latitude and longitude in WGS84 projection (EPSG 4326) for each postcode.

Output has the following structure:

Postcode 100km_grid 50km_grid 20km_grid 10km_grid 5km_grid 1km_grid lat lon
XX0 1XX XX XXSE XX80 XX80 XX80SE XX8501 50.1234 -0.1234
XX012XX XX XXNW XX64 XX74 XX74NW XX7449 50.5678 -0.5678

British National Grid to Easting and Northing Converter

File: bng2en.py

Adapted to Python from the original Perl code by Ben Soares for EDINA national datacentre.

Sample Usage:

> python bng2en.py NZ20NE SW
425000, 505000

British National Grid Utilities

File: bng_utilities.py

Various utilities for the British National Grid.

  • get_grid_references: Map UK postcodes to British National Grid (100, 50, 20, 10, 5, 2*, 1km grid references) and coordinates (as WGS84) in lat and lon columns. This function depends on the output of postcode_to_british_national_grid.ipynb (in parquet format) which contains grid references indexed by postcodes.

💡 Works with pandas series and dataframes.

  • get_grid_matrix: Returns a dict of 500km, 100km, 5km British National Grids as a 2D numpy array. Numpy array contains the grid reference.

  • get_five_km_index: Returns the row and column indices for the given 5km grid reference. Reference matrix is generated through get_grid_matrix

  • get_uk_5km_grid_matrix: Returns a subsection (from HL09NW in the northeast to TW90SE in the southwest) of the British National Grid to cover the United Kindom.

Please refer to each function's own documentation for more details.

* 2km grid is not a standard ONS grid. Therefore returning 2km grid references is optional. These can be generated by merging two consecutive 1km grids horizontally and vertically. 2km grid references follow 1km grid reference naming convention where easing and northing numbers are always odd.

Resources

License

Required data to run scripts and notebooks are subject to the following licenses:

  • Contains OS data © Crown copyright and database right 2019-2022
  • Contains Royal Mail data © Royal Mail copyright and database right 2019-2022
  • Source: Office for National Statistics licensed under the Open Government Licence v.3.0

Shared code and notebooks licensed under MIT License.

© 2022 - Bubo.AI