geojson-antimeridian-cut

Crates.iogeojson-antimeridian-cut
lib.rsgeojson-antimeridian-cut
version0.1.0-alpha.1
sourcesrc
created_at2019-11-19 22:16:48.667004
updated_at2019-11-19 22:16:48.667004
descriptionCuts GeoJSON Objects according to RFC 7946 § 3.1.9
homepage
repositoryhttps://gitlab.com/avandesa/geojson-antimeridian-cut-rs
max_upload_size
id182547
size34,002
Alex van de Sandt (avandesa)

documentation

README

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);
Commit count: 7

cargo fmt