Crates.io | kml |
lib.rs | kml |
version | |
source | src |
created_at | 2020-12-18 14:35:09.634601 |
updated_at | 2024-12-28 19:33:35.075001 |
description | KML support for Rust |
homepage | |
repository | https://github.com/georust/kml |
max_upload_size | |
id | 324347 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Rust support for reading and writing KML with a focus on conversion to geo-types
primitives.
use std::path::Path;
use kml::{Kml, KmlReader};
let kml_str = r#"
<Polygon>
<outerBoundaryIs>
<LinearRing>
<tessellate>1</tessellate>
<coordinates>
-1,2,0
-1.5,3,0
-1.5,2,0
-1,2,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
"#;
// Parse from a string
let kml: Kml = kml_str.parse().unwrap();
// Read from a file path
let kml_path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("fixtures")
.join("polygon.kml");
let mut kml_reader = KmlReader::<_, f64>::from_path(kml_path).unwrap();
let kml_data = kml_reader.read().unwrap();
// Read KMZ files with the `zip` feature or default features enabled
let kmz_path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("fixtures")
.join("polygon.kmz");
let mut kmz_reader = KmlReader::<_, f64>::from_kmz_path(kmz_path).unwrap();
let kmz_data = kmz_reader.read().unwrap();
use kml::{Kml, KmlWriter, types::Point};
let kml = Kml::Point(Point::new(1., 1., None));
let mut buf = Vec::new();
let mut writer = KmlWriter::from_writer(&mut buf);
writer.write(&kml).unwrap();
use geo_types::{self, GeometryCollection};
use kml::{Kml, types::Point};
let kml_point = Point::new(1., 1., None);
// Convert into geo_types primitives
let geo_point = geo_types::Point::from(kml_point);
// Convert back into kml::types structs
let kml_point = Point::from(geo_point);
let kml_folder_str = r#"
<Folder>
<Point>
<coordinates>1,1,1</coordinates>
<altitudeMode>relativeToGround</altitudeMode>
</Point>
<LineString>
<coordinates>1,1 2,1 3,1</coordinates>
<altitudeMode>relativeToGround</altitudeMode>
</LineString>
</Folder>"#;
let kml_folder: Kml<f64> = kml_folder_str.parse().unwrap();
let geom_coll: GeometryCollection<f64> = kml_folder.try_into().unwrap();
All contributors are expected to follow the GeoRust Code of Conduct
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.