Crate geojson [−] [src]
Examples
This crate uses serde
for serialization.
To get started, add geojson
to your Cargo.toml
:
[dependencies]
geojson= "*"
Reading
use geojson::GeoJson; let geojson_str = r#" { "type": "Feature", "properties": { "name": "Firestone Grill" }, "geometry": { "type": "Point", "coordinates": [-120.66029,35.2812] } } "#; let geojson = geojson_str.parse::<GeoJson>().unwrap();
Writing
Writing geojson
depends on the serialization framework because some structs
(like Feature
) use json values for properties.
extern crate serde_json; use serde_json::{Map, to_value}; let mut properties = Map::new(); properties.insert( String::from("name"), to_value("Firestone Grill").unwrap(), );
GeoJson
can then be serialized by calling to_string
:
use geojson::{Feature, GeoJson, Geometry, Value}; let geometry = Geometry::new( Value::Point(vec![-120.66029,35.2812]) ); let geojson = GeoJson::Feature(Feature { bbox: None, geometry: Some(geometry), id: None, properties: Some(properties), foreign_members: None }); let geojson_string = geojson.to_string();
Structs
Feature |
Feature Objects |
FeatureCollection |
Feature Collection Objects |
Geometry |
Geometry Objects |
Enums
Error |
Error when reading a GeoJSON object from a str or Object |
GeoJson |
GeoJSON Objects |
Value |
The underlying Geometry value |
Type Definitions
Bbox |
Bounding Boxes |
LineStringType | |
PointType | |
PolygonType | |
Position |
Positions |