1 unstable release
0.1.0-alpha.1 | Nov 19, 2019 |
---|
#9 in #geojson
32KB
821 lines
Geojson Antimeridian Cutting
GeoJSON
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
s
It 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.
Example
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);
Dependencies
~0.8–1.4MB
~27K SLoC