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
//! `PostGIS` Extended Well-Known Binary (EWKB) reader and writer.
//!
//! EWKB is OGC Well-Known Binary with a `PostGIS` header dialect: four
//! flag bits in the 32-bit type word, and an optional 32-bit
//! spatial-reference id between the type word and the body. Everything
//! after that header is byte-identical OGC WKB, so this crate is a
//! header codec — it delegates every body to `geometry-io-wkb` rather
//! than carrying a second parser.
//!
//! Only the **outermost** record carries an SRID, which is what
//! `PostGIS` writes. This is a strictly-2D reader: the `Z`, `M` and
//! bounding-box flags are refused by name rather than silently dropped.
//!
//! Empty polygons use zero rings, including inside collections. Other
//! geometry structure is preserved without validation; consumers can
//! reject short or unclosed rings and holes without an exterior.
//!
//! ```
//! use geometry_cs::Cartesian;
//! use geometry_io_ewkb::{ByteOrder, Srid, from_ewkb, to_ewkb, to_ewkb_hex};
//! use geometry_model::Point2D;
//!
//! let p = Point2D::<f64, Cartesian>::new(1.0, 2.0);
//! let bytes = to_ewkb(&p, Some(Srid::new(4326)), ByteOrder::LittleEndian);
//!
//! let read = from_ewkb(&bytes).unwrap();
//! assert_eq!(read.srid, Some(Srid::new(4326)));
//! assert_eq!(read.byte_order, ByteOrder::LittleEndian);
//!
//! // The text form of a PostGIS `geometry` column is hex EWKB.
//! assert_eq!(
//! to_ewkb_hex(&p, Some(Srid::new(4326)), ByteOrder::LittleEndian),
//! "0101000020E6100000000000000000F03F0000000000000040",
//! );
//! ```
//!
//! # Bringing your own polygon
//!
//! ```
//! use geometry_cs::Cartesian;
//! use geometry_io_ewkb::{ByteOrder, Srid, to_ewkb_polygon};
//! use geometry_model::{Point2D, Polygon, Ring};
//!
//! type Pt = Point2D<f64, Cartesian>;
//! let pg = Polygon::<Pt>::new(Ring::from_vec(vec![
//! Pt::new(0.0, 0.0),
//! Pt::new(0.0, 1.0),
//! Pt::new(1.0, 1.0),
//! Pt::new(0.0, 0.0),
//! ]));
//! let bytes = to_ewkb_polygon(&pg, Some(Srid::new(4326)), ByteOrder::BigEndian);
//! assert_eq!(bytes[0], 0x00); // big-endian
//! ```
extern crate alloc;
pub use Ewkb;
pub use EwkbError;
pub use WriteWkb;
pub use ;
pub use Srid;
// feature-group: I/O — Extended Well-Known Binary
// feature-desc: Parse and write PostGIS EWKB (WKB with an SRID header), binary and hex
pub use from_ewkb;
// feature-group: I/O — Extended Well-Known Binary
pub use ;
// feature-group: I/O — Extended Well-Known Binary
pub use ;