| Crates.io | serde_geozero |
| lib.rs | serde_geozero |
| version | 0.1.2 |
| created_at | 2025-01-16 10:11:56.792552+00 |
| updated_at | 2025-02-20 09:39:59.112743+00 |
| description | A Rust library for serializing and deserializing geospatial data using serde and geozero. |
| homepage | https://github.com/awmath/serde_geozero |
| repository | https://github.com/awmath/serde_geozero |
| max_upload_size | |
| id | 1519141 |
| size | 308,894 |
A Rust library for serializing and deserializing geospatial data using serde and geozero.
serde-geozero provides functionality to convert between geospatial data sources and Rust types using serde's serialization framework and geozero's processing capabilities. It enables seamless integration of various geospatial formats like GeoJSON and FlatGeobuf with Rust's type system.
Add this to your Cargo.toml:
[dependencies]
serde-geozero = "0.1.0"
use serde::Deserialize;
use geo::Geometry;
use serde_geozero::from_datasource;
#[derive(Deserialize)]
struct City {
geometry: Geometry,
name: String,
population: i64,
}
let geojson = r#"{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [13.4, 52.5]
},
"properties": {
"name": "Berlin",
"population": 3669495
}
}"#;
let mut reader = geozero::geojson::GeoJsonReader(geojson.as_bytes());
let cities: Vec<City> = from_datasource(&mut reader).unwrap();
assert_eq!(cities[0].name, "Berlin");
use geo::point;
use geozero::geojson::GeoJsonWriter;
use serde_geozero::to_geozero_datasource;
use hashbrown::HashMap;
use serde_geozero::de::Feature;
// Create a feature
let feature = Feature::new(
(point! { x: 123.4, y: 345.6 }).into(),
HashMap::from_iter(vec![
("name".to_string(), serde_json::to_value("Location A").unwrap()),
("value".to_string(), serde_json::to_value(42).unwrap()),
]),
);
// Serialize to GeoJSON
let mut output = Vec::new();
let mut writer = GeoJsonWriter::new(&mut output);
to_geozero_datasource(&[feature], &mut writer).unwrap();
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.