Code Monkey home page Code Monkey logo

pybng's Introduction

PyBNG

Build Status pypi Python License

An Ordinance-Survey National Grid coordinates converter


Getting Started

PyBNG is built on top of OSGridConverter and is used to convert coordinates from the Ordnance Survey National Grid system (often called the British National Grid -- BNG) to latitude and longitude using WGS84 (other geodetic reference systems available).

While OSGridConverter can convert BNG to latitude and longitude, it does not support all-numeric grid references, which is the primary feature in this library.

Installation

PIP (recommended)

pip install PyBNG

Manual Installation

Simply clone the entire repo and extract the files in the PyBNG folder, then copy all the content to your project folder

Or use one of the shorthand methods below

GIT
  • cd into your project directory
  • Use sparse-checkout to pull the library files only into your project directory
    git init PyBNG
    cd PyBNG
    git remote add -f origin https://github.com/ThunderStruct/PyBNG.git
    git config core.sparseCheckout true
    echo "PyBNG/*" >> .git/info/sparse-checkout
    git pull --depth=1 origin master
  • Import the newly pulled files into your project folder
SVN
  • cd into your project directory
  • checkout the library files
    svn checkout https://github.com/ThunderStruct/PyBNG/trunk/PyBNG
  • Import the newly checked out files into your project folder

Usage

Initialization

A PyBNG object can be instantiated as follows:

from PyBNG import PyBNG

bng = PyBNG(easting=519080, northing=185050)

latlon = PyBNG(lat=51.55178424773851, lon= -0.2835125528796557)

The initializer expects easting and northing OR lat and lon parameters, depending on the required conversion

Methods

  • get_latlon(datum='WGS84'):
    • Description: calculates the latitude and logitude based on the given BNG coordinates
    • Parameters: none (passed to constructor)
    • Return Value: tuple -- (latitude, longitude)
    • Usage:
      from PyBNG import PyBNG
      
      bng = PyBNG(easting=519080, northing=185050)
      bng.get_latlon()     # (51.55178424773851, -0.2835125528796557)
  • get_bng(datum='WGS84'):
    • Description: calculates the BNG coordinates given a latitude and a longitude
    • Parameters: none (passed to constructor)
    • Return Value: typle -- (easting, northing)
    • Usage:
      from PyBNG import PyBNG
      
      latlon = PyBNG(lat=51.55178424773851, lon= -0.2835125528796557)
      latlon.get_bng()     # (519107, 185051)

Please note that converting BNG coordinates to latitude/longitude and back to BNG will yield different results due to internal float rounding

Acknowledgment

I would like to thank Dr. Lakshmi Babu-Saheer for her unwavering support, encouragement, and advice.

License

This project is licensed under the MIT License - see the LICENSE file for details

pybng's People

Contributors

thunderstruct avatar

Stargazers

 avatar  avatar

Watchers

 avatar

pybng's Issues

incorrect error case handling for OSGridError

The following code incorrectly results in an error flag:

from PyBNG import PyBNG
PyBNG(easting = 328993, northing = 97946).get_latlon()

Error code:

File "{USER}\AppData\Roaming\Python\Python39\site-packages\OSGridConverter\grid.py", line 71, in init
factor=pow(10,5)
OSGridConverter.base.OSGridError: OSGridConverter error: Invalid grid reference

It seems any BNG grid ref with 6 digits in one coordinate and 5 digits in the other is rejected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.