wkt
Read and write Well-Known Text (WKT) geospatial geometries in Rust
Repository Health
Technical Analysis
wkt is a Rust library from the GeoRust ecosystem that provides read and write support for Well-Known Text (WKT), the standard textual encoding for geospatial geometries such as points, lines, polygons, and their multi- and collection variants.
It parses WKT strings into strongly-typed geometry values and serializes geometries back to WKT, with optional integration into the geo-types and geo-traits ecosystem and optional Serde support, making it a small, dependency-light building block for geospatial applications.
What You Get
- A parser that reads WKT strings into typed geometry values
- Serialization of geometries back to valid WKT text
- Optional conversions to and from
geo-typesandgeo-traits - A
wkt!macro for embedding geometry literals directly in Rust code - Optional Serde support and a lightweight, dependency-conscious design
Common Use Cases
- Parsing WKT geometry strings from databases, files, or APIs into typed values
- Exporting in-memory geometries to WKT for storage or interchange
- Bridging WKT data into the GeoRust
geo-typesecosystem for further processing - Embedding geometry literals in tests or code via the
wkt!macro
Under The Hood
Architecture — Reading flows through tokenizer.rs (lexing WKT text) into from_wkt.rs and infer_type.rs, producing the typed geometries defined under src/types/; geo_types_from_wkt.rs and geo_types_to_wkt.rs plus conversion.rs bridge to the GeoRust geo-types model, while to_wkt/ handles serialization back to text. wkt_macro.rs implements the wkt! literal macro and error.rs centralizes parse errors via thiserror.
Tech Stack — Rust (edition 2021) with a deliberately small dependency set: geo-traits, num-traits, thiserror, and log, plus optional geo-types (default) and serde. Criterion benchmarks under benches/ cover parse and write paths.
Code Quality — The crate is cleanly modularized by direction (parse vs. write) and by target type, uses typed errors, and ships parse/write benchmarks and a change log. Recent maintenance cadence is low, but the code is mature and widely used (8M+ downloads) with a stable API.
API Design — The API is straightforward: parse via FromStr/from_wkt into typed geometries, write via display/to_wkt, and construct literals with the wkt! macro. Feature flags keep the default surface lean while enabling geo-types and serde when needed, giving a gentle learning curve.