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 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!(
"{\"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>
Bounding Box
value: Value
§foreign_members: Option<JsonObject>
Foreign Members
Implementations§
source§impl Geometry
impl Geometry
pub fn from_json_object(object: JsonObject) -> Result<Self>
pub fn from_json_value(value: JsonValue) -> Result<Self>
Trait Implementations§
source§impl<'de> Deserialize<'de> for Geometry
impl<'de> Deserialize<'de> for Geometry
source§fn deserialize<D>(deserializer: D) -> Result<Geometry, D::Error>where
D: Deserializer<'de>,
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<'a> From<&'a Geometry> for JsonObject
impl<'a> From<&'a Geometry> for JsonObject
source§fn from(geometry: &'a Geometry) -> JsonObject
fn from(geometry: &'a Geometry) -> JsonObject
Converts to this type from the input type.
source§impl<T> TryFrom<&Geometry> for GeometryCollection<T>where
T: CoordFloat,
impl<T> TryFrom<&Geometry> for GeometryCollection<T>where
T: CoordFloat,
source§impl<T> TryFrom<&Geometry> for LineString<T>where
T: CoordFloat,
impl<T> TryFrom<&Geometry> for LineString<T>where
T: CoordFloat,
source§impl<T> TryFrom<&Geometry> for MultiLineString<T>where
T: CoordFloat,
impl<T> TryFrom<&Geometry> for MultiLineString<T>where
T: CoordFloat,
source§impl<T> TryFrom<&Geometry> for MultiPoint<T>where
T: CoordFloat,
impl<T> TryFrom<&Geometry> for MultiPoint<T>where
T: CoordFloat,
source§impl<T> TryFrom<&Geometry> for MultiPolygon<T>where
T: CoordFloat,
impl<T> TryFrom<&Geometry> for MultiPolygon<T>where
T: CoordFloat,
source§impl<T> TryFrom<Geometry> for GeometryCollection<T>where
T: CoordFloat,
impl<T> TryFrom<Geometry> for GeometryCollection<T>where
T: CoordFloat,
source§impl<T> TryFrom<Geometry> for LineString<T>where
T: CoordFloat,
impl<T> TryFrom<Geometry> for LineString<T>where
T: CoordFloat,
source§impl<T> TryFrom<Geometry> for MultiLineString<T>where
T: CoordFloat,
impl<T> TryFrom<Geometry> for MultiLineString<T>where
T: CoordFloat,
source§impl<T> TryFrom<Geometry> for MultiPoint<T>where
T: CoordFloat,
impl<T> TryFrom<Geometry> for MultiPoint<T>where
T: CoordFloat,
source§impl<T> TryFrom<Geometry> for MultiPolygon<T>where
T: CoordFloat,
impl<T> TryFrom<Geometry> for MultiPolygon<T>where
T: CoordFloat,
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)