{ "info": { "author": "Dr John A Stevenson", "author_email": "johnalexanderstevenson@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3" ], "description": "# BNG\n\n> Convert between BNG grid refs (e.g. NT123456) and OSGB36 (EPSG:27700) coords\n\nCoordinates in the [Ordnance Survey National Grid](https://en.wikipedia.org/wiki/Ordnance_Survey_National_Grid) or British National Grid are often defined by alphanumeric grid references that refer to grid squares.\nThese are based on the `osgb36` (EPSG:27700) coordinate reference system but are not understood by most GIS software.\nThis module contains Python functions to convert 4, 6, 8, or 10 figure alphanumeric grid references to/from pure `osgb36` coordinates.\n\nThis code was originally published on a blog post: [Easily change coordinate projection systems in Python with pyproj](http://all-geo.org/volcan01010/2012/11/change-coordinates-with-pyproj/).\nThe blog post contains more information and instructions for converting between coordinate systems using Python.\n\n## Installation\n\nBNG can be installed for Python 2.7 or Python 3 using pip:\n\n```\npip install bng\n```\n\n## Instructions\n\nThe `to_osbg36` and `from_osbg36` functions are used to convert between tuples of OSGB36 (x, y) coordinates and alphanumeric grid references.\n\n### to_osbg36\n\nBNG grid references can be converted to `osbg36` coordinates as follows.\n\nSingle values:\n\n```python\nimport bng\nbng.to_osgb36('NT2755072950')\n# (327550, 672950)\n```\n\nThe coordinates correspond to the southwest corner of the grid square described by the grid reference.\n\nFor multiple values, use Python's zip function and list comprehension:\n\n```python\nimport bng\ngridrefs = ['HU431392', 'SJ637560', 'TV374354']\nx, y = zip(*[bng.to_osgb36(g) for g in gridrefs])\nx\n# (443100, 363700, 537400)\ny\n# (1139200, 356000, 35400)\n```\n\n### from_osbg36\n\nBNG grid references can be created from`osbg36` coordinates as follows.\n\nSingle values:\n```python\nimport bng\nbng.from_osgb36((327550, 672950), figs=6)\n# 'NT275729'\n```\n\nThe number of figures in the grid reference can be specified.\nThe coordinates correspond to the southwest corner of the grid square containing the (x, y) coordinates.\n\nFor multiple values, use Python's zip function and list comprehension:\n```python\nimport bng\nx = [443143, 363723, 537395]\ny = [1139158, 356004, 35394]\n[bng.from_osgb36(coords, figs=4) for coords in zip(x, y)]\n# ['HU4339', 'SJ6356', 'TV3735']\n```\n\n### Converting grid references to GPS coordinates\n\n`BNG` can be combined with `pyproj` (see [blog post](http://all-geo.org/volcan01010/2012/11/change-coordinates-with-pyproj/)) to convert grid references to many different coordinate systems.\n\nBNG grid references can be converted to lat/lon as used by GPS systems (EPSG:4326) as follows:\n\n```python\nimport bng\nimport pyproj\n\n# Define coordinate systems\nwgs84=pyproj.Proj(\"+init=EPSG:4326\") # LatLon with WGS84 datum used by GPS units and Google Earth\nosgb36=pyproj.Proj(\"+init=EPSG:27700\") # UK Ordnance Survey, 1936 datum\n\n# Transform\nx, y = bng.to_osgb36('NT2755072950')\npyproj.transform(osgb36, wgs84, x, y)\n# (-3.1615548588213667, 55.944109545140932)\n```\n\nGPS coordinates can be converted to BNG grid references as follows:\n\n```python\nimport bng\nimport pyproj\n\n# Define coordinate systems\nwgs84=pyproj.Proj(\"+init=EPSG:4326\") # LatLon with WGS84 datum used by GPS units and Google Earth\nosgb36=pyproj.Proj(\"+init=EPSG:27700\") # UK Ordnance Survey, 1936 datum\n\n# Transform\nlon = -3.1615548588213667\nlat = 55.944109545140932\nx, y = pyproj.transform(wgs84, osgb36, lon, lat)\nbng.from_osgb36((x, y))\n# 'NT275729'\n```\n\nNote that for surveying work (i.e. < 1 m accuracy) it is necessary to make a geoid correction.\nProj [uses](https://proj4.org/resource_files.html) grid correction files in NTv2 format to make this correction.\nThe Ordnance Survey provide these files (OSTN2 transformation model) [on their website](https://www.ordnancesurvey.co.uk/business-and-government/help-and-support/navigation-technology/os-net/formats-for-developers.html).\n\n\n## For Developers\n\nInstall developer dependencies:\n\n```bash\npip install -r requirements.txt\n```\n\nRun tests:\n\n```bash\npytest -vs test_bng.py\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/volcan01010/bng", "keywords": "", "license": "GPLv3.0", "maintainer": "", "maintainer_email": "", "name": "bng", "package_url": "https://pypi.org/project/bng/", "platform": "", "project_url": "https://pypi.org/project/bng/", "project_urls": { "Homepage": "https://github.com/volcan01010/bng" }, "release_url": "https://pypi.org/project/bng/1.0.3/", "requires_dist": null, "requires_python": "", "summary": "Convert between BNG grid refs (e.g. NT123456) and OSGB36 (EPSG:27700) coords", "version": "1.0.3" }, "last_serial": 4666719, "releases": { "1.0.2": [ { "comment_text": "", "digests": { "md5": "68c59db09df37a6c3942bf4f0d6de26a", "sha256": "1d4ad895144ddcd5a6614a414092c7f0eaff2371655b5205713cd35feb3d68f1" }, "downloads": -1, "filename": "bng-1.0.2.tar.gz", "has_sig": false, "md5_digest": "68c59db09df37a6c3942bf4f0d6de26a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4813, "upload_time": "2019-01-05T21:52:05", "url": "https://files.pythonhosted.org/packages/91/65/36a3e5633e906c305d99d57e2603ab6e829edd459d02cabd39e1493e8b18/bng-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "b7caed84a55ac4905c0fd93ab90cc70d", "sha256": "cab6e6e0e47d82adf25c963a6e9f073384ceb1b766be8b3f92de90f2a88efde9" }, "downloads": -1, "filename": "bng-1.0.3.tar.gz", "has_sig": false, "md5_digest": "b7caed84a55ac4905c0fd93ab90cc70d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4904, "upload_time": "2019-01-06T22:26:57", "url": "https://files.pythonhosted.org/packages/ec/3f/3c8992252ea4ebc576e6c024ae961d325b39b3289f2659c8fd2ae2f67a56/bng-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b7caed84a55ac4905c0fd93ab90cc70d", "sha256": "cab6e6e0e47d82adf25c963a6e9f073384ceb1b766be8b3f92de90f2a88efde9" }, "downloads": -1, "filename": "bng-1.0.3.tar.gz", "has_sig": false, "md5_digest": "b7caed84a55ac4905c0fd93ab90cc70d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4904, "upload_time": "2019-01-06T22:26:57", "url": "https://files.pythonhosted.org/packages/ec/3f/3c8992252ea4ebc576e6c024ae961d325b39b3289f2659c8fd2ae2f67a56/bng-1.0.3.tar.gz" } ] }