Macro geo::wkt

source ·
macro_rules! wkt {
    ($($wkt:tt)+) => { ... };
}
Expand description

Creates a crate::geometry from a WKT literal.

This is evaluated at compile time, so you don’t need to worry about runtime errors from inavlid WKT syntax.

Note that POINT EMPTY is not accepted because it is not representable as a geo_types::Point.

use geo_types::wkt;
let point = wkt! { POINT(1.0 2.0) };
assert_eq!(point.x(), 1.0);
assert_eq!(point.y(), 2.0);

let geometry_collection = wkt! {
    GEOMETRYCOLLECTION(
        POINT(1.0 2.0),
        LINESTRING EMPTY,
        POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 0.0))
    )
};
assert_eq!(geometry_collection.len(), 3);