Crates.io | geojson-antimeridian-cut |
lib.rs | geojson-antimeridian-cut |
version | 0.1.0-alpha.1 |
source | src |
created_at | 2019-11-19 22:16:48.667004 |
updated_at | 2019-11-19 22:16:48.667004 |
description | Cuts GeoJSON Objects according to RFC 7946 § 3.1.9 |
homepage | |
repository | https://gitlab.com/avandesa/geojson-antimeridian-cut-rs |
max_upload_size | |
id | 182547 |
size | 34,002 |
GeoJSON is a standard for representing geographic data in a JSON file. Features
and
FeatureCollections
are composed of different geometry objects, including:
LineString
sMultiLineString
sPolygon
sMultiPolygon
sGeometryCollection
sIt is very likely that some geographic data may cross the Antimeridian (180° E or 180° W). RFC 7946 Section 3.1.9 specifies that such objects SHOULD be broken up into two or more objects, none of which cross the antimeridian, and which together are all equivalent. This crate implements that splitting.
The types in this crate are re-exported from the geojson
crate, and the functions
implement the relevant splitting algorithms for each type. If a GeoJSON
object does not cross the antimeridian, None
is returned, otherwise a copy of the object with the relevant splits is returned.
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);