geoserde/
lib.rs

1#![cfg_attr(all(doc, not(doctest)), feature(doc_auto_cfg))]
2
3//! Geoserde is an adapter between geographic feature structs and GIS file formats.
4//!
5//! # Getting started
6//!
7//! ```sh
8//! cargo add geoserde
9//! ```
10//!
11//! # Cargo features
12//!
13//! * `geozero` - Implement geoserde sink for geozero processors. Enabled by default.
14//!
15//! # Examples
16//!
17//! ```
18//! use geo_types::Point;
19//! use geoserde::FeatureSerializer;
20//! use geozero::geojson::GeoJsonWriter;
21//! use serde::Serialize;
22//!
23//! // Print two features to the console in GeoJson format
24//! fn main() -> anyhow::Result<()> {
25//!     // If you want to write to a file, use BufWriter<File> instead
26//!     let mut buf = vec![];
27//!
28//!     // Any format that has an implementation of geozero::FeatureProcessor can be used,
29//!     // such as wkt, shp, fgb, etc. See also https://docs.rs/geozero/latest/geozero/
30//!     let mut geojson = GeoJsonWriter::new(&mut buf);
31//!
32//!     // Serialize features to GeoJson format
33//!     let mut ser = FeatureSerializer::new(&mut geojson);
34//!     my_features().serialize(&mut ser)?;
35//!
36//!     println!("{}", std::str::from_utf8(&buf)?);
37//!     Ok(())
38//! }
39//!
40//! // Create feature array
41//! fn my_features() -> impl Serialize {
42//!     [
43//!         Station {
44//!             name: "King's Cross",
45//!             europe: true,
46//!             loc: Point::new(51.5321, -0.1233),
47//!         },
48//!         Station {
49//!             name: "Tokyo",
50//!             europe: false,
51//!             loc: Point::new(139.7661, 35.6812),
52//!         },
53//!     ]
54//! }
55//!
56//! // Geographic feature
57//! #[derive(Serialize)]
58//! struct Station {
59//!     // Property
60//!     name: &'static str,
61//!
62//!     // Property
63//!     europe: bool,
64//!
65//!     // Geometry
66//!     loc: Point,
67//! }
68//! ```
69
70mod ser;
71
72pub use crate::ser::*;