24个版本

0.8.5 2024年1月2日
0.8.4 2023年11月7日
0.8.3 2023年8月5日
0.8.2 2023年6月28日
0.0.5 2020年12月30日

#59 in 地理空间

Download history 249/week @ 2024-03-13 227/week @ 2024-03-20 226/week @ 2024-03-27 263/week @ 2024-04-03 204/week @ 2024-04-10 181/week @ 2024-04-17 310/week @ 2024-04-24 208/week @ 2024-05-01 244/week @ 2024-05-08 311/week @ 2024-05-15 266/week @ 2024-05-22 271/week @ 2024-05-29 248/week @ 2024-06-05 282/week @ 2024-06-12 247/week @ 2024-06-19 256/week @ 2024-06-26

每月1,059
用于 7 crate

MIT/Apache

155KB
4K SLoC

kml

crates.io Build status Documentation

Rust对阅读和写入KML的支持,重点在于转换为geo-types原语。

示例

读取

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::{quick_collection, 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();

// Use the quick_collection helper to convert Kml to a geo_types::GeometryCollection
let geom_coll: GeometryCollection<f64> = quick_collection(kml_folder).unwrap();

行为准则

所有贡献者都应遵守GeoRust行为准则

许可

许可如下

任选其一。

贡献

除非你明确声明,否则根据Apache-2.0许可证定义,你提交的任何有意提交以包含在工作中的贡献,都应双许可如上所述,不附加任何额外条款或条件。

依赖项

~8MB
~144K SLoC