26 releases
0.11.1 | Oct 10, 2024 |
---|---|
0.11.0 | Jul 25, 2024 |
0.10.3 | Jun 22, 2022 |
0.10.0 | Feb 25, 2022 |
0.0.3 | Feb 1, 2015 |
#67 in Parser implementations
60,575 downloads per month
Used in 30 crates
(21 directly)
185KB
3.5K
SLoC
wkt
Rust read/write support for well-known text (WKT).
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
The wkt
crate provides conversions to and from the WKT (Well Known Text)
geometry format.
Conversions are available via the TryFromWkt
and ToWkt
traits, with implementations for
geo_types
primitives enabled by default.
For advanced usage, see the types
module for a list of internally used types.
This crate has optional serde
integration for deserializing fields containing WKT. See
deserialize
for an example.
Examples
Read geo_types
from a WKT string
// This example requires the geo-types feature (on by default). use wkt::TryFromWkt; use geo_types::Point;
let point: Point = Point::try_from_wkt_str("POINT(10 20)").unwrap(); assert_eq!(point.y(), 20.0);
## Write `geo_types` to a WKT string
// This example requires the geo-types feature (on by default).
use wkt::ToWkt;
use geo_types::Point;
let point: Point<f64> = Point::new(1.0, 2.0);
assert_eq!(point.wkt_string(), "POINT(1 2)");
Read or write your own geometry types
Not using geo-types
for your geometries? No problem!
You can use Wkt::from_str
to parse a WKT string into this crate's intermediate geometry
structure. You can use that directly, or if have your own geometry types that you'd prefer to
use, utilize that [Wkt
] struct to implement the ToWkt
or TryFromWkt
traits for your
own types.
In doing so, you'll likely want to match on one of the WKT types
(Point, Linestring, etc.)
stored in its item
field
use std::str::FromStr;
use wkt::Wkt;
let wktls: Wkt<f64> = Wkt::from_str("LINESTRING(10 20, 20 30)").unwrap();
let ls = match wktls {
Wkt::LineString(line_string) => {
// you now have access to the `wkt::types::LineString`.
assert_eq!(line_string.0[0].x, 10.0);
}
_ => unreachable!(),
};
Dependencies
~1–1.6MB
~34K SLoC