geometry_io_ewkt/lib.rs
1//! `PostGIS` Extended Well-Known Text (EWKT) reader and writer.
2//!
3//! Not part of Boost.Geometry; follows the `PostGIS` manual, sections
4//! "4.1.3. WKT and WKB" and "4.2.1. `PostGIS` EWKB and EWKT", and the
5//! `PostGIS` reader in `liblwgeom/lwin_wkt_lex.l`. EWKT is the dialect
6//! `ST_AsEWKT` emits and `ST_GeomFromEWKT` accepts: OGC WKT plus an
7//! optional `SRID=<digits>;` prefix and the glued dimension-suffix
8//! spellings. `ST_AsEWKT` glues only `M` (`POINTM(1 2 3)`); `PostGIS`
9//! reads the glued `Z`, `M`, and `ZM` forms and the OGC-spaced
10//! `POINT Z` / `POINT M` / `POINT ZM` forms alike, and this crate reads
11//! all of them.
12//!
13//! The geometry body is delegated to [`geometry_io_wkt`]. This crate
14//! scans the prefix, overwrites a glued suffix with spaces in place — a
15//! same-length rewrite, so every byte offset it reports indexes the
16//! string the caller passed — and hands the body over. [`from_ewkt`]
17//! therefore emits a [`geometry_model::DynGeometry`], and the six
18//! `parse_*` conveniences return concrete model types; each is paired
19//! with the spatial-reference id in an [`Ewkt`].
20//!
21//! `PostGIS` treats SRID 0 as unknown ([`Srid::UNKNOWN`]) and omits the
22//! prefix for it. This crate reads `SRID=0;` as `Some(Srid::UNKNOWN)`
23//! and writes it back as `SRID=0;`; callers pass `None` to omit the
24//! prefix.
25//!
26//! Every ordinate past the second is discarded, as in
27//! [`geometry_io_wkt`], and nothing above 2D is ever written — so a
28//! dimension suffix carries no information this model can hold.
29//!
30//! ## Read and write a prefixed geometry
31//!
32//! ```
33//! use geometry_io_ewkt::{Srid, from_ewkt, to_ewkt};
34//!
35//! let e = from_ewkt("SRID=4326;POINTM(1 2 3)").unwrap();
36//! assert_eq!(e.srid, Some(Srid::new(4326)));
37//! assert_eq!(to_ewkt(&e.geometry, e.srid), "SRID=4326;POINT(1 2)");
38//! ```
39
40#![cfg_attr(not(feature = "std"), no_std)]
41#![forbid(unsafe_code)]
42
43extern crate alloc;
44
45mod dimension_suffix;
46mod ewkt;
47mod ewkt_error;
48mod srid;
49mod srid_prefix;
50
51pub use ewkt_error::EwktError;
52pub use geometry_io_wkt::WktError;
53#[doc(hidden)]
54pub use geometry_io_wkt::WriteWkt;
55pub use srid::Srid;
56// feature-group: I/O — Extended Well-Known Text
57// feature-desc: Parse and write PostGIS EWKT (WKT with an SRID prefix)
58pub use ewkt::{
59 Ewkt, from_ewkt, parse_linestring, parse_multi_linestring, parse_multi_point,
60 parse_multi_polygon, parse_point, parse_polygon,
61};
62// feature-group: I/O — Extended Well-Known Text
63pub use ewkt::{to_ewkt, to_ewkt_polygon, write_ewkt};