Struct geojson::Geometry[][src]

pub struct Geometry {
    pub bbox: Option<Bbox>,
    pub value: Value,
    pub foreign_members: Option<Map<String, JsonValue>>,
}

Geometry Objects

GeoJSON Format Specification § 3.1

Examples

Constructing a Geometry:

use geojson::{Geometry, Value};

let geometry = Geometry::new(Value::Point(vec![7.428959, 1.513394]));

Geometries can be created from Values.

let geometry1: Geometry = Value::Point(vec![7.428959, 1.513394]).into();

Serializing a Geometry to a GeoJSON string:

use geojson::{GeoJson, Geometry, Value};
use serde_json;

let geometry = Geometry::new(Value::Point(vec![7.428959, 1.513394]));

let geojson_string = geometry.to_string();

assert_eq!(
    "{\"coordinates\":[7.428959,1.513394],\"type\":\"Point\"}",
    geojson_string,
);

Deserializing a GeoJSON string into a Geometry:

use geojson::{GeoJson, Geometry, Value};

let geojson_str = "{\"coordinates\":[7.428959,1.513394],\"type\":\"Point\"}";

let geometry = match geojson_str.parse::<GeoJson>() {
    Ok(GeoJson::Geometry(g)) => g,
    _ => return,
};

assert_eq!(
    Geometry::new(Value::Point(vec![7.428959, 1.513394]),),
    geometry,
);

Fields

bbox: Option<Bbox>value: Valueforeign_members: Option<Map<String, JsonValue>>

Implementations

impl Geometry[src]

pub fn new(value: Value) -> Self[src]

Returns a new Geometry with the specified value. bbox and foreign_members will be set to None.

impl Geometry[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]

Trait Implementations

impl Clone for Geometry[src]

impl Debug for Geometry[src]

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

impl Display for Geometry[src]

impl<'a> From<&'a Geometry> for Map<String, JsonValue>[src]

impl From<Geometry> for GeoJson[src]

impl<V> From<V> for Geometry where
    V: Into<Value>, 
[src]

impl PartialEq<Geometry> for Geometry[src]

impl Serialize for Geometry[src]

impl StructuralPartialEq for Geometry[src]

impl TryFrom<GeoJson> for Geometry[src]

type Error = Error

The type returned in the event of a conversion error.

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

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Value> for Geometry[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

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.