#geospatial #geography #gis

bin+lib geographiclib-rs

Rust 中的 geographiclib 的移植

6 个版本

0.2.4 2024 年 2 月 6 日
0.2.3 2023 年 3 月 2 日
0.2.2 2022 年 12 月 30 日
0.2.1 2022 年 3 月 30 日
0.1.0 2020 年 4 月 29 日

#7 in 地理空间

Download history 34995/week @ 2024-04-16 33010/week @ 2024-04-23 37224/week @ 2024-04-30 40803/week @ 2024-05-07 45369/week @ 2024-05-14 55388/week @ 2024-05-21 56074/week @ 2024-05-28 55315/week @ 2024-06-04 59686/week @ 2024-06-11 58235/week @ 2024-06-18 59495/week @ 2024-06-25 44182/week @ 2024-07-02 38070/week @ 2024-07-09 34371/week @ 2024-07-16 40263/week @ 2024-07-23 41970/week @ 2024-07-30

162,939 每月下载量
209 个crate(3 个直接)中使用

MIT 许可证

170KB
3.5K SLoC

geographiclib-rs

在 Rust 中实现 geographiclib 的一个子集。

文档

目前,它实现了直接和反地球测线计算。

如果您正在寻找 Rust 对 Karney 的 C++ 实现 的绑定,请参阅 https://crates.io/geographiclib

示例

// Determine the point 10000 km NE of JFK - the "direct" geodesic calculation.
use geographiclib_rs::{Geodesic, DirectGeodesic};

let g = Geodesic::wgs84();
let jfk_lat = 40.64;
let jfk_lon = -73.78;
let northeast_azimuth = 45.0;

let (lat, lon, az) = g.direct(jfk_lat, jfk_lon, northeast_azimuth, 10e6);

use approx::assert_relative_eq;
assert_relative_eq!(lat, 32.621100463725796);
assert_relative_eq!(lon, 49.05248709295982);
assert_relative_eq!(az,  140.4059858768007);
// Determine the distance between two points - the "inverse" geodesic calculation.
use geographiclib_rs::{Geodesic, InverseGeodesic};

let g = Geodesic::wgs84();
let p1 = (34.095925, -118.2884237);
let p2 = (59.4323439, 24.7341649);
let s12: f64 = g.inverse(p1.0, p1.1, p2.0, p2.1);

use approx::assert_relative_eq;
assert_relative_eq!(s12, 9094718.72751138);
// Determine the perimeter and area of a polygon.
use geographiclib_rs::{Geodesic, PolygonArea, Winding};

let g = Geodesic::wgs84();
let mut pa = PolygonArea::new(&g, Winding::CounterClockwise);
pa.add_point(0.0, 0.0);
pa.add_point(0.0, 1.0);
pa.add_point(1.0, 1.0);
pa.add_point(1.0, 0.0);

let (perimeter_m, area_m_squared, num_points) = pa.compute(false);

use approx::assert_relative_eq;
assert_relative_eq!(perimeter_m, 443770.91724830196);
assert_relative_eq!(area_m_squared, 12308778361.469452);
assert_eq!(num_points, 4);
// Determine the distance between rovers Pathfinder and Curiosity on Mars
use geographiclib_rs::{Geodesic, InverseGeodesic};

let mars = Geodesic::new(3396190.0, 1.0 / 169.8944472);
let pathfinder = (19.26, 326.75);
let curiosity = (-4.765700445, 137.39820983);
let distance_m: f64 = mars.inverse(curiosity.0, curiosity.1, pathfinder.0, pathfinder.1);

assert_eq!(distance_m.round(), 9639113.0);

功能

  1. accurate:默认启用。使用 accurate crate 在 PolygonArea 中提供高精度的多边形面积和周长。可以禁用以提高性能或当不使用 PolygonArea 时。

基准测试

要比较直接和反地球测线计算与 geographiclib c 绑定,运行

cargo bench

这将产生如下输出

direct (c wrapper)/default
                        time:   [24.046 µs 24.071 µs 24.099 µs]

direct (rust impl)/default
                        time:   [26.129 µs 26.168 µs 26.211 µs]

inverse (c wrapper)/default
                        time:   [45.061 µs 45.141 µs 45.227 µs]

inverse (rust impl)/default
                        time:   [67.739 µs 67.796 µs 67.865 µs]

表明,至少在这个基准测试中,Rust 实现比 C 绑定慢 10-50%。

依赖项

~695KB
~14K SLoC