#geojson #json

geojson-antimeridian-cut

Cuts GeoJSON Objects according to RFC 7946 § 3.1.9

1 unstable release

0.1.0-alpha.1 Nov 19, 2019

#9 in #geojson

MIT license

32KB
821 lines

Geojson Antimeridian Cutting

Crates.io Gitlab pipeline status

GeoJSON

GeoJSON is a standard for representing geographic data in a JSON file. Features and FeatureCollections are composed of different geometry objects, including:

  • LineStrings
  • MultiLineStrings
  • Polygons
  • MultiPolygons
  • GeometryCollections

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.7–1.1MB
~24K SLoC