Git Product home page Git Product logo

ostn15_phf's Introduction

Build Status MIT licensed

Description

A Rust Crate which provides fast lookup of OSTN15 adjustments, for the conversion of ETRS89 grid coordinates to OSGB36, natively or via FFI.

Important

This library only provides the adjustment values. For a complete solution, see the lonlat_bng crate, which provides the OSTN15 transform via FFI, and / or the convertbng Python package.

Rust Crate Example

use ostn15_phf::ostn15_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 = e_grid + (n_grid * 701) + 1
// key is 220065
// don't use unwrap() in production
let result = ostn15_lookup(&key).unwrap();
// result should be (102.787, -78.242, 44.236)
assert_eq!(result, (102.787, -78.242, 44.236));

FFI Examples

Python

import sys, ctypes
from ctypes import c_int32, c_double, Structure


class GridRefs(Structure):
    _fields_ = [("eastings", c_int32),
                ("northings", c_int32)]

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


class Shifts(Structure):
    _fields_ = [("x_shift", c_double),
                ("y_shift", c_double),
                ("z_shift", c_double)]

    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 + "ostn15_phf" + extension)

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

result = GridRefs(651, 313)

print(lib.get_shifts_ffi(result))

C

// compile with e.g. `clang -lostn15_phf -L target/release -o ostn15_shifts  src/ostn15.c` from project root
// run with `LD_LIBRARY_PATH=target/release ./ostn15_shifts` from project root
#include <stdio.h>
#include <stdint.h>

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

typedef struct {
  double x_shift;
  double y_shift;
  double z_shift;
} adjustment;

extern adjustment get_shifts_ffi(gridrefs);

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

Building the Shared Library

  • Ensure that Rust is installed
  • Clone this repo
  • In the repo root, run cargo build --release
  • The dylib or DLL will be available as target/release/libostn15_phf.{dylib, dll}
  • If you need to build a .so for Linux:
    1. ar -x target/release/libostn15_phf.a
    2. gcc -shared *.o -o target/release/libostn15_phf.so

License

MIT

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

ostn15_phf's People

Contributors

urschrei avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.