Expand description
The wkt crate provides conversions to and from WKT primitive types.
See the types module for a list of available types.
Conversions (using std::convert::From and std::convert::TryFrom) to and from geo_types primitives are enabled by default, but the feature is optional.
Enable the serde feature if you need to deserialise data into custom structs containing WKT geometry fields.
Examples
use std::str::FromStr;
use wkt::Wkt;
let point: Wkt<f64> = Wkt::from_str("POINT(10 20)").unwrap();ⓘ
// Convert to a geo_types primitive from a Wkt struct
use std::convert::TryInto;
use wkt::Wkt;
use geo_types::Point;
let point: Wkt<f64> = Wkt::from_str("POINT(10 20)").unwrap();
let g_point: geo_types::Point<f64> = (10., 20.).into();
let converted: Point<f64> = point.try_into().unwrap();
assert_eq!(g_point, converted);Direct Access to the item Field
If you wish to work directly with one of the WKT types you can match on the item field
use std::convert::TryInto;
use std::str::FromStr;
use wkt::Wkt;
use wkt::Geometry;
let wktls: Wkt<f64> = Wkt::from_str("LINESTRING(10 20, 20 30)").unwrap();
let ls = match wktls.item {
Geometry::LineString(line_string) => {
// you now have access to the types::LineString
}
_ => unreachable!(),
};
Modules
This module provides conversions between WKT primitives and geo_types primitives.
WKT primitive types and collections
Structs
Container for WKT primitives and collections