Skip to content

Commit

Permalink
Update intro
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Nov 26, 2024
1 parent 9e01d4e commit d5476f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,36 @@
//! structure, and it allows you to write WKT strings directly from your geometry without any
//! intermediate representation.
//!
//!
//! ### Reading
//!
//! 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.
//! structure. `Wkt` (and all structs defined in [types]) implement traits from [geo_traits]. You
//! can write functions in terms of those traits and you'll be able to work with the parsed WKT
//! without any further overhead.
//!
//! 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;
//! use geo_traits::{GeometryTrait, GeometryType};
//!
//! fn is_line_string(geom: &impl GeometryTrait<T = f64>) {
//! assert!(matches!(geom.as_type(), GeometryType::LineString(_)))
//! }
//!
//! 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!(),
//! };
//! is_line_string(&wktls);
//! ```
//!
//! Working with the trait definition is preferable to working with `wkt::Wkt` directly, as the
//! geometry trait will work with many different geometry representations; not just the one from
//! this crate.
//!
//! ### Writing
//!
//! Consult the functions provided in [`to_wkt`]. Those functions will write any `geo_traits` object to WKT without any intermediate overhead.
//!
//! Implement [`geo_traits`] on your own geometry representation and those functions will work out
//! of the box on your data.
use std::default::Default;
use std::fmt;
use std::str::FromStr;
Expand Down
2 changes: 2 additions & 0 deletions src/to_wkt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Serialize geometries to WKT strings.
use crate::{Wkt, WktNum};

mod geo_trait_impl;
Expand Down

0 comments on commit d5476f1

Please sign in to comment.