1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! RFC 7946 `GeoJSON` reader and writer.
//!
//! Not part of Boost.Geometry; follows RFC 7946. The parser emits a
//! [`geometry_model::DynGeometry`] (a `GeoJSON` `GeometryCollection` is
//! heterogeneous); the writer serialises concrete model geometries with
//! [`to_geojson`] and any user-defined polygon implementing the geometry
//! traits with [`to_geojson_polygon`]. Feature objects and property bags
//! are out of scope — only the `geometry` member's OGC-equivalent kinds.
//!
//! ## Serialize a user-defined polygon
//!
//! Application types can implement the lightweight [`geometry_trait`] traits
//! directly; they do not need to be converted to a `geometry_model` polygon.
//!
//! ```
//! use geometry_cs::Cartesian;
//! use geometry_io_geojson::{from_geojson, to_geojson_polygon};
//! use geometry_tag::{PointTag, PolygonTag, RingTag};
//! use geometry_trait::{Geometry, Point, Polygon, Ring};
//!
//! struct Coordinate(f64, f64);
//!
//! impl Geometry for Coordinate {
//! type Kind = PointTag;
//! type Point = Self;
//! }
//!
//! impl Point for Coordinate {
//! type Scalar = f64;
//! type Cs = Cartesian;
//! const DIM: usize = 2;
//!
//! fn get<const D: usize>(&self) -> f64 {
//! match D {
//! 0 => self.0,
//! 1 => self.1,
//! _ => unreachable!("a Coordinate has two dimensions"),
//! }
//! }
//! }
//!
//! struct Boundary(Vec<Coordinate>);
//!
//! impl Geometry for Boundary {
//! type Kind = RingTag;
//! type Point = Coordinate;
//! }
//!
//! impl Ring for Boundary {
//! fn points(&self) -> impl ExactSizeIterator<Item = &Coordinate> + Clone {
//! self.0.iter()
//! }
//! }
//!
//! struct Parcel {
//! exterior: Boundary,
//! holes: Vec<Boundary>,
//! }
//!
//! impl Geometry for Parcel {
//! type Kind = PolygonTag;
//! type Point = Coordinate;
//! }
//!
//! impl Polygon for Parcel {
//! type Ring = Boundary;
//!
//! fn exterior(&self) -> &Boundary {
//! &self.exterior
//! }
//!
//! fn interiors(&self) -> impl ExactSizeIterator<Item = &Boundary> {
//! self.holes.iter()
//! }
//! }
//!
//! let parcel = Parcel {
//! exterior: Boundary(vec![
//! Coordinate(0.0, 0.0),
//! Coordinate(0.0, 2.0),
//! Coordinate(2.0, 2.0),
//! Coordinate(2.0, 0.0),
//! Coordinate(0.0, 0.0),
//! ]),
//! holes: vec![],
//! };
//!
//! let geojson = to_geojson_polygon(&parcel);
//! assert_eq!(
//! geojson,
//! r#"{"type":"Polygon","coordinates":[[[0,0],[0,2],[2,2],[2,0],[0,0]]]}"#
//! );
//! assert!(from_geojson(&geojson).is_ok());
//! ```
extern crate alloc;
pub use GeoJsonError;
// feature-group: I/O — GeoJSON
// feature-desc: Parse and write GeoJSON (RFC 7946)
pub use from_geojson;
// feature-group: I/O — GeoJSON
pub use ;