Rust support for reading and writing KML with a focus on conversion to geo-types
primitives.
```rust use std::path::Path; use kml::{Kml, KmlReader};
let kml_str = r#"
// Parse from a string let kml: Kml = kml_str.parse().unwrap();
// Read from a file path let kmlpath = Path::new(env!("CARGOMANIFESTDIR")) .join("tests") .join("fixtures") .join("polygon.kml"); let mut kmlreader = KmlReader::<_, f64>::fromfile(kmlpath).unwrap(); let kmldata = kmlreader.parse().unwrap();
// Read KMZ files with the zip
feature or default features enabled
let kmzpath = Path::new(env!("CARGOMANIFESTDIR"))
.join("tests")
.join("fixtures")
.join("polygon.kmz");
let mut kmzreader = KmlReader::<_, f64>::fromkmzfile(kmzpath).unwrap();
let kmzdata = kmz_reader.parse().unwrap();
```
```rust use std::str; use quick_xml; use kml::{Kml, KmlWriter, types::{AltitudeMode, Coord, Point}};
let kml = Kml::Point(Point { coord: Coord { x: 1., y: 1., z: Some(1.), }, ..Default::default() });
let mut buf = Vec::new(); let mut writer = KmlWriter::new(quick_xml::Writer::new(&mut buf)); writer.write(&kml).unwrap(); ```
```rust use geotypes::{self, GeometryCollection}; use kml::{quickcollection, Kml, types::Point};
let kmlpoint = Point::new(1., 1., None); // Convert into geotypes primitives let geopoint = geotypes::Point::from(kmlpoint); // Convert back into kml::types structs let kmlpoint = Point::from(geo_point);
let kmlfolderstr = r#"
// Use the quickcollection helper to convert Kml to a geotypes::GeometryCollection
let geomcoll: GeometryCollection