14个版本
使用旧的Rust 2015
0.1.13 | 2016年7月24日 |
---|---|
0.1.12 | 2016年6月23日 |
0.1.11 | 2016年4月4日 |
0.1.10 | 2016年3月16日 |
0.1.8 | 2016年2月23日 |
#121 in #geo
用于 lonlat_bng
14MB
372K SLoC
包含 (Mach-o exe, 9KB) ostn02_shifts
描述
一个Rust包,提供快速查找OSTN02调整,用于将ETRS89网格坐标转换为OSGB36。
该包提供基本偏移量。为了获得实际偏移量,将每个偏移量除以1000.
,然后减去最小东经、北纬和高度偏移量。所有计算应使用双精度浮点数进行。
最小东经偏移量 = 86.275
最小北纬偏移量 = -81.603
最小高度偏移量 = 43.982
对于 651, 313
的基本偏移量: (16500, 3359, 270)
实际偏移量: (102.775, -78.244, 44.252)
FFI函数 不需要上述计算;它返回实际偏移量,或(NAN, NAN, NAN)
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
// don't use unwrap() in production
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示例
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 + "ostn02_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 -lostn02_phf -L target/release -o ostn02_shifts src/ostn02.c` from project root
// run with `LD_LIBRARY_PATH=target/release ./ostn02_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;
}
构建共享库
- 确保已安装Rust
- 克隆此仓库
- 在仓库根目录中,运行
cargo build --release
- dylib或DLL将作为
target/release/libostn02_phf.{dylib, dll}
可用 - 如果您需要为Linux构建
.so
ar-x target/发布/liblonlat_bng.a
gcc -共享 *.o -otarget/release/libostn02_phf.so
许可证
此软件使用 OSTN02 数据,版权所有 © 英国王冠,英国测量局和英国国防部 (MOD) 2002。保留所有权利。在 BSD 2-clause 许可下提供 许可证。