Skip to main content

Crate geometry_io_ewkt

Crate geometry_io_ewkt 

Source
Expand description

PostGIS Extended Well-Known Text (EWKT) reader and writer.

Not part of Boost.Geometry; follows the PostGIS manual, sections “4.1.3. WKT and WKB” and “4.2.1. PostGIS EWKB and EWKT”, and the PostGIS reader in liblwgeom/lwin_wkt_lex.l. EWKT is the dialect ST_AsEWKT emits and ST_GeomFromEWKT accepts: OGC WKT plus an optional SRID=<digits>; prefix and the glued dimension-suffix spellings. ST_AsEWKT glues only M (POINTM(1 2 3)); PostGIS reads the glued Z, M, and ZM forms and the OGC-spaced POINT Z / POINT M / POINT ZM forms alike, and this crate reads all of them.

The geometry body is delegated to geometry_io_wkt. This crate scans the prefix, overwrites a glued suffix with spaces in place — a same-length rewrite, so every byte offset it reports indexes the string the caller passed — and hands the body over. from_ewkt therefore emits a geometry_model::DynGeometry, and the six parse_* conveniences return concrete model types; each is paired with the spatial-reference id in an Ewkt.

PostGIS treats SRID 0 as unknown (Srid::UNKNOWN) and omits the prefix for it. This crate reads SRID=0; as Some(Srid::UNKNOWN) and writes it back as SRID=0;; callers pass None to omit the prefix.

Every ordinate past the second is discarded, as in geometry_io_wkt, and nothing above 2D is ever written — so a dimension suffix carries no information this model can hold.

§Read and write a prefixed geometry

use geometry_io_ewkt::{Srid, from_ewkt, to_ewkt};

let e = from_ewkt("SRID=4326;POINTM(1 2 3)").unwrap();
assert_eq!(e.srid, Some(Srid::new(4326)));
assert_eq!(to_ewkt(&e.geometry, e.srid), "SRID=4326;POINT(1 2)");

Structs§

Ewkt
A geometry together with the spatial-reference id that prefixed it.
Srid
A PostGIS spatial-reference id: the integer after SRID=.

Enums§

EwktError
Everything that can go wrong reading EWKT.
WktError
Everything that can go wrong reading WKT.

Functions§

from_ewkt
Read EWKT of any kind into a DynGeometry and its SRID.
parse_linestring
Read EWKT known to be a LINESTRING.
parse_multi_linestring
Read EWKT known to be a MULTILINESTRING.
parse_multi_point
Read EWKT known to be a MULTIPOINT.
parse_multi_polygon
Read EWKT known to be a MULTIPOLYGON.
parse_point
Read EWKT known to be a POINT.
parse_polygon
Read EWKT known to be a POLYGON.
to_ewkt
Serialise a geometry and its SRID to canonical EWKT.
to_ewkt_polygon
Serialise any polygon implementing the geometry traits, plus its SRID, to canonical EWKT.
write_ewkt
Serialise a geometry and its SRID into any core::fmt::Write sink.