Struct geojson::Geometry

source ·
pub struct Geometry {
    pub bbox: Option<Bbox>,
    pub value: Value,
    pub foreign_members: Option<JsonObject>,
}
Expand description

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

Transforming a Geometry into a geo_types::Geometry<f64> (which requires the geo-types feature):

use geojson::{Geometry, Value};
use std::convert::TryInto;

let geometry = Geometry::new(Value::Point(vec![7.428959, 1.513394]));
let geom: geo_types::Geometry<f64> = geometry.try_into().unwrap();

Fields§

§bbox: Option<Bbox>§value: Value§foreign_members: Option<JsonObject>

Implementations§

source§

impl Geometry

source

pub fn new(value: Value) -> Self

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

source§

impl Geometry

source

pub fn from_json_object(object: JsonObject) -> Result<Self>

source

pub fn from_json_value(value: JsonValue) -> Result<Self>

Trait Implementations§

source§

impl Clone for Geometry

source§

fn clone(&self) -> Geometry

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Geometry

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Geometry

source§

fn deserialize<D>(deserializer: D) -> Result<Geometry, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Geometry

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> From<&'a Geometry> for JsonObject

source§

fn from(geometry: &'a Geometry) -> JsonObject

Converts to this type from the input type.
source§

impl From<Geometry> for Feature

source§

fn from(geom: Geometry) -> Feature

Converts to this type from the input type.
source§

impl<V> From<V> for Geometrywhere V: Into<Value>,

source§

fn from(v: V) -> Geometry

Converts to this type from the input type.
source§

impl FromStr for Geometry

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq<Geometry> for Geometry

source§

fn eq(&self, other: &Geometry) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Geometry

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T> TryFrom<&Geometry> for Geometry<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: &Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<&Geometry> for GeometryCollection<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: &Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<&Geometry> for LineString<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: &Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<&Geometry> for MultiLineString<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: &Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<&Geometry> for MultiPoint<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: &Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<&Geometry> for MultiPolygon<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: &Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<&Geometry> for Point<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: &Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<&Geometry> for Polygon<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: &Geometry) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<GeoJson> for Geometry

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: GeoJson) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<Geometry> for Geometry<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<Geometry> for GeometryCollection<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<Geometry> for LineString<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<Geometry> for MultiLineString<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<Geometry> for MultiPoint<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<Geometry> for MultiPolygon<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<Geometry> for Point<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: Geometry) -> Result<Self>

Performs the conversion.
source§

impl<T> TryFrom<Geometry> for Polygon<T>where T: CoordFloat,

Available on crate feature geo-types only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(geometry: Geometry) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Map<String, Value>> for Geometry

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(object: JsonObject) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Value> for Geometry

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: JsonValue) -> Result<Self>

Performs the conversion.
source§

impl StructuralPartialEq for Geometry

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,