pub struct Geometry {
pub bbox: Option<Vec<f64>>,
pub value: GeometryValue,
pub foreign_members: Option<Map<String, Value>>,
}Expand description
Geometry Object
GeoJSON Format Specification § 3.1
§Examples
Constructing a Geometry (the long way):
use geojson::{Geometry, GeometryValue, Position};
let geometry = Geometry {
// `value` corresponds to the 'type' and 'coordinates' field.
value: GeometryValue::Point {
coordinates: Position::from([7.428959, 1.513394]),
},
bbox: None,
foreign_members: None,
};Constructors make this more concise.
let geometry = Geometry::new_point([1.23, 3.45]);Serializing a Geometry to a GeoJSON string:
use geojson::Geometry;
let geometry = Geometry::new_point([1.23, 3.45]);
let geojson_string = geometry.to_string();
assert_eq!(
geojson_string,
r#"{"type":"Point","coordinates":[1.23,3.45]}"#
);Deserializing a GeoJSON string into a Geometry:
use geojson::Geometry;
let geojson_str = r#"{"type":"Point", "coordinates":[7.428959,1.513394]}"#;
let geometry = geojson_str
.parse::<Geometry>()
.expect("valid Geometry GeoJSON");
assert_eq!(Geometry::new_point([7.428959, 1.513394]), geometry,);Transforming a Geometry into a geo_types::Point<f64> (which requires the geo-types
feature):
use geojson::Geometry;
use std::convert::TryInto;
let geometry = Geometry::new_point([1.23, 4.56]);
let geom: geo_types::Point = geometry.try_into().unwrap();
assert_eq!(geom.x(), 1.23);
assert_eq!(geom.y(), 4.56);Fields§
§bbox: Option<Vec<f64>>Bounding Box
value: GeometryValue§foreign_members: Option<Map<String, Value>>Foreign Members
GeoJSON Format Specification § 6
See the crate-level foreign members documentation for details, including limitations on key names.
Implementations§
Source§impl Geometry
impl Geometry
Sourcepub fn new(value: GeometryValue) -> Geometry
pub fn new(value: GeometryValue) -> Geometry
Returns a new Geometry with the specified value. bbox and foreign_members will be
set to None.
pub fn new_point(value: impl Into<Position>) -> Geometry
pub fn new_line_string( value: impl IntoIterator<Item = impl Into<Position>>, ) -> Geometry
pub fn new_multi_point( value: impl IntoIterator<Item = impl Into<Position>>, ) -> Geometry
pub fn new_multi_line_string( value: impl IntoIterator<Item = impl IntoIterator<Item = impl Into<Position>>>, ) -> Geometry
pub fn new_polygon( value: impl IntoIterator<Item = impl IntoIterator<Item = impl Into<Position>>>, ) -> Geometry
pub fn new_multi_polygon( value: impl IntoIterator<Item = impl IntoIterator<Item = impl IntoIterator<Item = impl Into<Position>>>>, ) -> Geometry
pub fn new_geometry_collection( value: impl IntoIterator<Item = impl Into<Geometry>>, ) -> Geometry
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 UnsafeUnpin for Geometry
impl UnwindSafe for Geometry
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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