pub struct Geometry {
pub bbox: Option<Vec<f64>>,
pub value: Value,
pub foreign_members: Option<Map<String, Value>>,
}
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 Value
s.
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!(
"{\"type\":\"Point\",\"coordinates\":[7.428959,1.513394]}",
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<Vec<f64>>
Bounding Box
value: Value
§foreign_members: Option<Map<String, Value>>
Foreign Members
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Geometry
impl<'de> Deserialize<'de> for Geometry
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Geometry, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Geometry, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Geometry
impl Serialize for Geometry
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for Geometry
Auto Trait Implementations§
impl Freeze for Geometry
impl RefUnwindSafe for Geometry
impl Send for Geometry
impl Sync for Geometry
impl Unpin for Geometry
impl UnwindSafe for Geometry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FromJson for Twhere
T: DeserializeOwned,
impl<T> FromJson for Twhere
T: DeserializeOwned,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more