1个不稳定版本
| 0.1.0-alpha.1 | 2019年11月19日 |
|---|
#9 在 #geojson
32KB
821 行
Geojson 反子午线切割
GeoJSON
GeoJSON 是一种用于在JSON文件中表示地理数据的标准。 Features 和 FeatureCollections 由不同的几何对象组成,包括
LineStringMultiLineStringPolygonMultiPolygonGeometryCollection
一些地理数据可能跨越反子午线(东经180°或西经180°)。 RFC 7946第3.1.9节 规定,此类对象应拆分为两个或更多对象,其中没有任何对象跨越反子午线,且组合起来等效。此包实现了这种拆分。
此包中的类型从 geojson 包 中导出,函数实现了每种类型的相应拆分算法。如果 GeoJSON 对象不跨越反子午线,则返回 None,否则返回包含相关拆分的对象副本。
示例
let given: Geometry = json!({
"type": "LineString",
"coordinates": [[170, 0], [-170, 0]],
})
.try_into()
.unwrap();
let expected: Geometry = json!({
"type": "MultiLineString",
"coordinates": [
[[170, 0], [180, 0]],
[[-180, 0], [-170, 0]],
],
})
.try_into()
.unwrap();
let result = split_geometry(&given);
assert_eq!(Some(expected), result);
依赖项
~0.7–1.1MB
~23K SLoC