Skip to main content

Fast lon, lat to and from ETRS89 and BNG (OSGB36) using Rust FFI

Project description

Build Status Windows Build Status Coverage Status PyPI Version MIT licensed

Description

A utility library for converting decimal WGS84 longitude and latitude coordinates into ETRS89 (EPSG:25830) and/or British National Grid (More correctly: OSGB36, or EPSG:27700) Eastings and Northings, and vice versa.

Conversion is handled by a Rust binary using FFI, and is quite fast. Some benchmarks can be found here.

Installation

pip install convertbng
Please use an up-to-date version of pip (8.1.2 as of June 2016)

Supported Platforms

The package has been built for and tested on the following platforms:

  • Linux 64-bit, Python 2.7 and 3.6, as a manylinux1 wheel
  • OS X 64-bit, Python 2.7 and 3.6, as a wheel for versions 10.6 and above
  • Windows 32-bit and 64-bit Python 2.7 and 32-bit Python 3.4, as a wheel.

Windows Binaries

The Rust DLL and the Cython extension used by this package have been built with an MSVC toolchain. You shouldn't need to install any additional runtimes in order for the wheel to work, but please open an issue if you encounter any errors.

Usage

The functions accept either a sequence (such as a list or numpy array) of longitude or easting values and a sequence of latitude or northing values, or a single longitude/easting value and single latitude/northing value. Note the return type:
"returns a list of two lists containing floats, respectively"

NOTE: Coordinate pairs outside the BNG bounding box, or without OSTN15 coverage will return a result of
[[nan], [nan]], which cannot be mapped. Since transformed coordinates are guaranteed to be returned in the same order as the input, it is trivial to check for this value. Alternatively, ensure your data fall within the bounding box before transforming them:

Latitude:
East: 1.7800
West: -7.5600
Longitude:
North: 60.8400
South: 49.9600

All functions try to be liberal about what containers they accept: list, tuple, array.array, numpy.ndarray, and pretty much anything that has the __iter__ attribute should work, including generators.

from convertbng.util import convert_bng, convert_lonlat

# convert a single value
res = convert_bng(lon, lat)

# convert lists of longitude and latitude values to OSGB36 Eastings and Northings, using OSTN15 corrections
lons = [lon1, lon2, lon3]
lats = [lat1, lat2, lat3]
res_list = convert_bng(lons, lats)

# convert lists of BNG Eastings and Northings to longitude, latitude
eastings = [easting1, easting2, easting3]
northings = [northing1, northing2, northing3]
res_list_en = convert_lonlat(eastings, northings)

# assumes numpy imported as np
lons_np = np.array(lons)
lats_np = np.array(lats)
    res_list_np = convert_bng(lons_np, lats_np)

But I Have a List of Coordinate Pairs

coords = [[1.0, 2.0], [3.0, 4.0]]
a, b = list(zip(*coords))
# a is (1.0, 3.0)
# b is (2.0, 4.0)   

Experimental Cython Module

If you're comfortable with restricting yourself to NumPy f64 arrays, you may use the Cython functions instead. These are identical to those listed below, and are selected by changing the import statement
from convertbng.util import to
from convertbng.cutil import

The conversion functions will accept most sequences which implement __iter__, as above (list, tuple, float, array.array, numpy.ndarray), but will always return NumPy f64 ndarray. In addition, you must ensure that your inputs are float, f64, or d in the case of array.array.

Available Conversions (AKA I Want To…)

  • transform longitudes and latitudes to OSGB36 Eastings and Northings very accurately:
    • use convert_bng()
  • transform OSGB36 Eastings and Northings to longitude and latitude, very accurately:
    • use convert_lonlat()
  • transform longitudes and latitudes to ETRS89 Eastings and Northings, very quickly (without OSTN15 corrections):
    • use convert_etrs89()
  • transform ETRS89 Eastings and Northings to ETRS89 longitude and latitude, very quickly (the transformation does not use OSTN15):
    • use convert_etrs89_to_lonlat()
  • convert ETRS89 Eastings and Northings to their most accurate real-world representation, using the OSTN15 corrections:
    • use convert_etrs89_to_osgb36()

Provided for completeness:

  • transform accurate OSGB36 Eastings and Northings to less-accurate ETRS89 Eastings and Northings:
    • use convert_osgb36_to_etrs89()

Relationship between ETRS89 and WGS84

From Transformations and OSGM02™ User guide, p7. Emphasis mine.

[…] ETRS89 is a precise version of the better known WGS84 reference system optimised for use in Europe; however, for most purposes it can be considered equivalent to WGS84. Specifically, the motion of the European continental plate is not apparent in ETRS89, which allows a fixed relationship to be established between this system and Ordnance Survey mapping coordinate systems. Additional precise versions of WGS84 are currently in use, notably ITRS; these are not equivalent to ETRS89. The difference between ITRS and ETRS89 is in the order of 0.25 m (in 1999), and growing by 0.025 m per year in UK and Ireland. This effect is only relevant in international scientific applications. For all navigation, mapping, GIS, and engineering applications within the tectonically stable parts of Europe (including UK and Ireland), the term ETRS89 should be taken as synonymous with WGS84.

In essence, this means that anywhere you see ETRS89 in this README, you can substitute WGS84.

What CRS Are My Data In

  • if you have latitude and longitude coordinates:
    • They're probably WGS84. Everything's fine!
  • if you got your coordinates from a smartphone or a consumer GPS:
    • They're probably WGS84. Everything's fine!
  • if you have x and y coordinates, or you got your coordinates from Google Maps or Bing Maps and they look something like (-626172.1357121646, 6887893.4928337997), or the phrase "Spherical Mercator" is mentioned anywhere:
    • they're probably in Web Mercator. You must convert them to WGS84 first. Use convert_epsg3857_to_wgs84([x_coordinates], [y_coordinates]) to do so.

Accuracy

convert_bng and convert_lonlat first use the standard seven-step Helmert transform to convert coordinates. This is fast, but not particularly accurate – it can introduce positional error up to approximately 5 metres. For most applications, this is not of particular concern – the input data (especially those originating with smartphone GPS) probably exceed this level of error in any case. In order to adjust for this, the OSTN15 adjustments for the kilometer-grid the ETRS89 point falls in are retrieved, and a linear interpolation to give final, accurate coordinates is carried out. This process happens in reverse for convert_lonlat.

OSTN15

OSTN15 data are used for highly accurate conversions from ETRS89 latitude and longitude, or ETRS89 Eastings and Northings to OSGB36 Eastings and Northings, and vice versa. These data will usually have been recorded using the National GPS Network:

Accuracy of Your Data

Conversion of your coordinates using OSTN15 transformations will be accurate, but if you're using consumer equipment, or got your data off the web, be aware that you're converting coordinates which probably weren't accurately recorded in the first place. That's because accurate surveying is difficult.

Accuracy of the OSTN15 transformation used in this library

  • ETRS89 longitude and latitude / Eastings and Northings to OSGB36 conversion agrees with the provided Ordnance Survey test data in 31 of the 42 test coordinates (excluding two coordinates designed to return no data; these correctly fail).
  • The 11 discrepancies are of 1mm in each case.
  • OSGB36 to ETRS89 longitude and latitude conversion is accurate to within 8 decimal places, or 1.1mm.

A Note on Ellipsoids

WGS84 and ETRS89 coordinates use the GRS80 ellipsoid, whereas OSGB36 uses the Airy 1830 ellipsoid, which provides a regional best fit for Britain. Positions for coordinates in Great Britain can differ by over 100m as a result. It is thus inadvisable to attempt calculations using mixed ETRS89 and OSGB36 coordinates.

OSTN15

Implementation

The main detail of interest is the FFI interface between Python and Rust, the Python side of which can be found in util.py (the ctypes implementation), cutil.pyx (the cython implementation), and the Rust side of which can be found in ffi.rs.
The ctypes library expects C-compatible data structures, which we define in Rust (see above). We then define methods which allow us to receive, safely access, return, and free data across the FFI boundary.
Finally, we link the Rust conversion functions from util.py again. Note the errcheck assignments, which convert the FFI-compatible ctypes data structures to tuple lists.

Building the binary for local development

Tests

You can run the Python module tests by running "make test".
Tests require both numpy and nose.

License

MIT

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

convertbng-0.6.4-cp36-cp36m-win_amd64.whl (13.7 MB view details)

Uploaded CPython 3.6mWindows x86-64

convertbng-0.6.4-cp36-cp36m-win32.whl (13.7 MB view details)

Uploaded CPython 3.6mWindows x86

convertbng-0.6.4-cp36-cp36m-manylinux1_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.6m

convertbng-0.6.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.6mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.11+ Intel (x86-64, i386)macOS 10.11+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

convertbng-0.6.4-cp35-cp35m-win_amd64.whl (13.7 MB view details)

Uploaded CPython 3.5mWindows x86-64

convertbng-0.6.4-cp35-cp35m-win32.whl (13.7 MB view details)

Uploaded CPython 3.5mWindows x86

convertbng-0.6.4-cp35-cp35m-manylinux1_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.5m

convertbng-0.6.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.5mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.11+ Intel (x86-64, i386)macOS 10.11+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

convertbng-0.6.4-cp34-cp34m-manylinux1_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.4m

convertbng-0.6.4-cp27-cp27mu-manylinux1_x86_64.whl (13.9 MB view details)

Uploaded CPython 2.7mu

convertbng-0.6.4-cp27-cp27m-win_amd64.whl (13.7 MB view details)

Uploaded CPython 2.7mWindows x86-64

convertbng-0.6.4-cp27-cp27m-win32.whl (13.7 MB view details)

Uploaded CPython 2.7mWindows x86

convertbng-0.6.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl (13.8 MB view details)

Uploaded CPython 2.7mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.11+ Intel (x86-64, i386)macOS 10.11+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

File details

Details for the file convertbng-0.6.4-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 ea0d53c1dfa5a673c19a753cdb7bfb6ded314e75c53b77e032de2f7e923c7bb0
MD5 580e8a4db2accec89be26d1141bbf1bf
BLAKE2b-256 4d93ee37fa55e1f716aa1f281abc7738d75e556200818bb9e04e03b945c9dcc8

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp36-cp36m-win32.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 a31754efaf54d32370e7215a1683d1add653c00869589af9483576dd26c00499
MD5 6791f7a40d28e60199c39f8a22328246
BLAKE2b-256 6ee0af8697f17cfceac57a50f6db8d73ad72819365b9c53ef48b9c39a686c92a

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 13.9 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 45b007da53761bc76abd0fd1f85d21ac0e3672a314a7f157dc2bd78529d8abce
MD5 c19dda4ee83107948124f8a09d934b44
BLAKE2b-256 54c608587783e902ceae2afb89e3dcfb821b8a7fbf12b8c54bb5d21096c898ee

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for convertbng-0.6.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 b4d65be13476b9d1613927e47b6e1a69c3c025cb749760ae9815fef6c9c9363f
MD5 c13b1a68cd2da5a02c22e6ecd55a042b
BLAKE2b-256 72a5f39b67da21d3038247e458e0469e4a51017366336488ba2bb6da6c86851d

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 9b5ad85a1d0c4e654096081415387b37641ef4151dec136b94a755dbeeb10f7f
MD5 6cdd687a574d6011d973dfdb652c1347
BLAKE2b-256 2545b7b8f734c14eac1cfd1a73b71d30010f6970a4c0271c7740ea9752d696e5

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp35-cp35m-win32.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 cac7e873eed03e7edcec569c8fa5064d94f6277465a45a1f79ee50496306b06c
MD5 4fe3c598d4977f79c3da4144cbcc0bf2
BLAKE2b-256 b43c633c2c776164a6d6b73f8340dcc506a5f3154e75c2abd6de5f2be661b147

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 13.9 MB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b426fd493be4c13fced88c160542645ddabec411830959b5b61b057067d64786
MD5 93c38a2273cd433f4a544ad6af8746b1
BLAKE2b-256 8c687253401dc0c05a3c835574690c44652f339e7e72f4439892ec09b46bfc2c

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for convertbng-0.6.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 7ad0eed8d9a74ce401f249522ab622f912a7903756414e1fba510176e6281819
MD5 e0db1d0b73d761ea8f2314e93b623a99
BLAKE2b-256 b1e3aa8cda4089f48b28f68b968887cb715084224b87612392e77284ba80fc6e

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp34-cp34m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 13.9 MB
  • Tags: CPython 3.4m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 89c274eb2ffb2c1d2ce27184c964e705641d4af0c180ff9a9171188249194dfb
MD5 affc526a4722725de708c91fed4b0d29
BLAKE2b-256 cd35adea42edf425904aac79020ed3c01717c5ced4b847a823c08b5654eadc2e

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 13.9 MB
  • Tags: CPython 2.7mu
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 679683b0bf8dc78795bc85fd52f209c84a3e43b75c2ffedb91fe98ebae6fc0d2
MD5 7b73afe949a7e5e3a3df5cba71df9d9f
BLAKE2b-256 34f46d9ac5c32834d9eaa5579e258a78d889dc52f546f296197ed73116f452ed

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 57770a071255b2652fb63f478b3d2d172ca4f397330e7532d1648541db074053
MD5 1ce0a7efc89b29db171f994c4b928d52
BLAKE2b-256 4575a675543757b243e39878397434fab0ec31b6c4d620682dc478ece82dd261

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp27-cp27m-win32.whl.

File metadata

  • Download URL: convertbng-0.6.4-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.15

File hashes

Hashes for convertbng-0.6.4-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 dc3ef8960f6fe0c621bede3fa60be5a5ac4f6d9b6d7589bd2c089fa5dd22b52b
MD5 ab8a68bbfe1412d7f15610cc7e84487d
BLAKE2b-256 af3e23863c3a6fb39f4e674984db8d9d532d6b344d5c9978bbc2771b2697d6bc

See more details on using hashes here.

File details

Details for the file convertbng-0.6.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for convertbng-0.6.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.macosx_10_11_intel.macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 b9bb53dedf9469d39bdd3717df9d957c350e2ee384d2b7e0268ff9ad27b11e38
MD5 961fed9fd28e33f9472733b4a17e329a
BLAKE2b-256 240bb4bdbafa36f8ba561cae7f387ad9cfa5c4d3553d6afa3d7e3ae50ea066a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page