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();

GeoJSON Format Specification § 3

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]

Trait Implementations

impl Clone for GeoJson[src]

impl Debug for GeoJson[src]

impl<'de> Deserialize<'de> for GeoJson[src]

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]

impl<G: Into<Geometry>> From<G> for GeoJson[src]

impl From<GeoJson> for JsonValue[src]

impl<G: Into<Geometry>> FromIterator<G> for GeoJson[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.

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.

impl TryFrom<GeoJson> for Feature[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<GeoJson> for FeatureCollection[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Map<String, Value>> for GeoJson[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for GeoJson[src]

type Error = Error

The type returned in the event of a conversion error.

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.