Enum geojson::GeoJson [−][src]
pub enum GeoJson { Geometry(Geometry), Feature(Feature), FeatureCollection(FeatureCollection), }
GeoJSON Objects
use std::convert::TryInto; use geojson::{Feature, GeoJson, Geometry, Value}; use serde_json::json; let json_value = json!({ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "properties": null, }); let feature: Feature = json_value.try_into().unwrap(); // Easily convert a feature to a GeoJson let geojson: GeoJson = feature.into(); // and back again let feature2: Feature = geojson.try_into().unwrap();
Variants
Geometry(Geometry)
Feature(Feature)
FeatureCollection(FeatureCollection)
Implementations
impl GeoJson
[src]
pub fn from_json_object(object: Map<String, JsonValue>) -> Result<Self, Error>
[src]
pub fn from_json_value(value: JsonValue) -> Result<Self, Error>
[src]
Converts a JSON Value into a GeoJson object.
Example
use std::convert::TryInto; use geojson::{Feature, GeoJson, Geometry, Value}; use serde_json::json; let json_value = json!({ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "properties": null, }); assert!(json_value.is_object()); let geojson: GeoJson = json_value.try_into().unwrap(); assert_eq!( geojson, GeoJson::Feature(Feature { bbox: None, geometry: Some(Geometry::new(Value::Point(vec![102.0, 0.5]))), id: None, properties: None, foreign_members: None, }) );
pub fn to_json_value(self) -> JsonValue
[src]
Convience method to convert to a JSON Value. Uses From
.
use std::convert::TryFrom; use geojson::GeoJson; use serde_json::json; let geojson = GeoJson::try_from( json!({ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "properties": {}, })).unwrap(); let json_value = geojson.to_json_value(); assert_eq!(json_value, json!({ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "properties": {}, }) );
pub fn from_reader<R>(rdr: R) -> Result<Self, Error> where
R: Read,
[src]
R: Read,
Trait Implementations
impl Clone for GeoJson
[src]
impl Debug for GeoJson
[src]
impl<'de> Deserialize<'de> for GeoJson
[src]
fn deserialize<D>(deserializer: D) -> Result<GeoJson, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl Display for GeoJson
[src]
impl<'a> From<&'a GeoJson> for Map<String, JsonValue>
[src]
impl From<Feature> for GeoJson
[src]
impl From<FeatureCollection> for GeoJson
[src]
fn from(feature_collection: FeatureCollection) -> GeoJson
[src]
impl<G: Into<Geometry>> From<G> for GeoJson
[src]
impl From<GeoJson> for JsonValue
[src]
impl<G: Into<Geometry>> FromIterator<G> for GeoJson
[src]
fn from_iter<I: IntoIterator<Item = G>>(iter: I) -> Self
[src]
impl FromStr for GeoJson
[src]
Example
use geojson::GeoJson; use std::str::FromStr; let geojson_str = r#"{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [ -0.13583511114120483, 51.5218870403801 ] } } ] } "#; let geo_json = GeoJson::from_str(&geojson_str).unwrap(); if let GeoJson::FeatureCollection(collection) = geo_json { assert_eq!(1, collection.features.len()); } else { panic!("expected feature collection"); }
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl PartialEq<GeoJson> for GeoJson
[src]
impl Serialize for GeoJson
[src]
impl StructuralPartialEq for GeoJson
[src]
impl TryFrom<GeoJson> for Geometry
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: GeoJson) -> Result<Self, Self::Error>
[src]
impl TryFrom<GeoJson> for Feature
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: GeoJson) -> Result<Self, Self::Error>
[src]
impl TryFrom<GeoJson> for FeatureCollection
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(value: GeoJson) -> Result<Self, Self::Error>
[src]
impl TryFrom<Map<String, Value>> for GeoJson
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(object: Map<String, JsonValue>) -> Result<Self, Self::Error>
[src]
impl TryFrom<Value> for GeoJson
[src]
Auto Trait Implementations
impl RefUnwindSafe for GeoJson
impl Send for GeoJson
impl Sync for GeoJson
impl Unpin for GeoJson
impl UnwindSafe for GeoJson
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,