Build Status MIT licensed

Description

A Rust Crate which provides fast lookup of OSTN02 adjustments, for the conversion of ETRS89 grid coordinates to OSGB36.

The crate provides base shifts. In order to obtain the actual shifts, divide each shift by 1000., then subtract the minimum Easting, Northing, and Height shift. All calculations should be carried out using double-precision floating point.

Minimum Easting shift = 86.275
Minimum Northing shift = -81.603
Minimum height shift = 43.982

Base shifts for 651, 313: (16500, 3359, 270)
Actual shifts: (102.775, -78.244, 44.252)

The FFI function does not require the calculation above; it returns the actual shifts, or (NAN, NAN, NAN)

Rust Crate Example

rust // The key is the combined hex-transformed (03x) kilometer-grid reference of the ETRS89 Northings and Eastings coordinates use ostn02_phf::ostn02_lookup; // Caister Tower Eastings and Northings: 651307.003, 313255.686 let e_grid = (651307.003 / 1000.) as i32; let n_grid = (313255.686 / 1000.) as i32; let key = format!("{:03x}{:03x}", n_grid, e_grid); // key is 13928b let result = ostn02_lookup(&*key).unwrap(); // result should be (16500, 3359, 270) assert_eq!(result, (16500, 3359, 270)); // remember that the actual adjustment for a coordinate is a bilinear transform, using a square // see ostn02_shifts in https://github.com/urschrei/lonlat_bng/blob/master/src/ostn02/mod.rs

FFI Examples

Python

``` python import sys, ctypes from ctypes import cint32, cdouble, Structure

class GridRefs(Structure): fields = [("eastings", cint32), ("northings", cint32)]

def __str__(self):
    return "({}, {})".format(self.eastings, self.northings)

class Shifts(Structure): fields = [("xshift", cdouble), ("yshift", cdouble), ("zshift", cdouble)]

def __str__(self):
    return "({}, {}, {})".format(self.x_shift, self.y_shift, self.z_shift)

prefix = {'win32': ''}.get(sys.platform, 'lib') extension = {'darwin': '.dylib', 'win32': '.dll'}.get(sys.platform, '.so') lib = ctypes.cdll.LoadLibrary(prefix + "ostn02_phf" + extension)

lib.getshiftsffi.argtypes = (GridRefs,) lib.getshiftsffi.restype = Shifts

result = GridRefs(651, 313)

print(lib.getshiftsffi(result)) ```

C

``c // compile with e.g.clang -lostn02phf -L target/release -o ostn02shifts src/ostn02.cfrom project root // run withLDLIBRARYPATH=target/release ./ostn02_shifts` from project root

include

include

typedef struct { int32t easting; int32t northing; } gridrefs;

typedef struct { double xshift; double yshift; double z_shift; } adjustment;

extern adjustment getshiftsffi(gridrefs);

int main(void) { gridrefs initial = { .easting = 651, .northing = 313 }; adjustment adj = getshiftsffi(initial); printf("(%f, %f, %f)\n", adj.xshift, adj.yshift, adj.z_shift); return 0; } ```

Building the Shared Library

License

MIT

This software makes use of OSTN02 data, which is © Crown copyright, Ordnance Survey and the Ministry of Defence (MOD) 2002. All rights reserved. Provided under the BSD 2-clause license.