pub enum GeoJson {
Geometry(Geometry),
Feature(Feature),
FeatureCollection(FeatureCollection),
}
Expand description
GeoJSON Objects
use std::convert::TryInto;
use geojson::{Feature, GeoJson, Geometry, Value};
use serde_json::json;
let json_value = json!({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
},
"properties": null,
});
let feature: Feature = json_value.try_into().unwrap();
// Easily convert a feature to a GeoJson
let geojson: GeoJson = feature.into();
// and back again
let feature2: Feature = geojson.try_into().unwrap();
Variants§
Implementations§
source§impl GeoJson
impl GeoJson
pub fn from_json_object(object: JsonObject) -> Result<Self>
sourcepub fn from_json_value(value: JsonValue) -> Result<Self>
pub fn from_json_value(value: JsonValue) -> Result<Self>
Converts a JSON Value into a GeoJson object.
Example
use std::convert::TryInto;
use geojson::{Feature, GeoJson, Geometry, Value};
use serde_json::json;
let json_value = json!({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
},
"properties": null,
});
assert!(json_value.is_object());
let geojson: GeoJson = json_value.try_into().unwrap();
assert_eq!(
geojson,
GeoJson::Feature(Feature {
bbox: None,
geometry: Some(Geometry::new(Value::Point(vec![102.0, 0.5]))),
id: None,
properties: None,
foreign_members: None,
})
);
sourcepub fn to_json_value(self) -> JsonValue
pub fn to_json_value(self) -> JsonValue
Convenience method to convert to a JSON Value. Uses From
.
use std::convert::TryFrom;
use geojson::GeoJson;
use serde_json::json;
let geojson = GeoJson::try_from( json!({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
},
"properties": {},
})).unwrap();
let json_value = geojson.to_json_value();
assert_eq!(json_value,
json!({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
},
"properties": {},
})
);
pub fn from_reader<R>(rdr: R) -> Result<Self>where R: Read,
Trait Implementations§
source§impl<'de> Deserialize<'de> for GeoJson
impl<'de> Deserialize<'de> for GeoJson
source§fn deserialize<D>(deserializer: D) -> Result<GeoJson, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<GeoJson, D::Error>where D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<'a> From<&'a GeoJson> for JsonObject
impl<'a> From<&'a GeoJson> for JsonObject
source§fn from(geojson: &'a GeoJson) -> JsonObject
fn from(geojson: &'a GeoJson) -> JsonObject
Converts to this type from the input type.
source§impl From<FeatureCollection> for GeoJson
impl From<FeatureCollection> for GeoJson
source§fn from(feature_collection: FeatureCollection) -> GeoJson
fn from(feature_collection: FeatureCollection) -> GeoJson
Converts to this type from the input type.
source§impl<G: Into<Geometry>> FromIterator<G> for GeoJson
impl<G: Into<Geometry>> FromIterator<G> for GeoJson
source§fn from_iter<I: IntoIterator<Item = G>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = G>>(iter: I) -> Self
Creates a value from an iterator. Read more
source§impl FromStr for GeoJson
impl FromStr for GeoJson
Example
use geojson::GeoJson;
use std::str::FromStr;
let geojson_str = r#"{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-0.13583511114120483,
51.5218870403801
]
}
}
]
}
"#;
let geo_json = GeoJson::from_str(&geojson_str).unwrap();
if let GeoJson::FeatureCollection(collection) = geo_json {
assert_eq!(1, collection.features.len());
} else {
panic!("expected feature collection");
}
source§impl PartialEq<GeoJson> for GeoJson
impl PartialEq<GeoJson> for GeoJson
source§impl TryFrom<GeoJson> for FeatureCollection
impl TryFrom<GeoJson> for FeatureCollection
source§impl<T> TryFrom<GeoJson> for Geometry<T>where
T: CoordFloat,
Available on crate feature geo-types
only.
impl<T> TryFrom<GeoJson> for Geometry<T>where T: CoordFloat,
Available on crate feature
geo-types
only.impl StructuralPartialEq for GeoJson
Auto Trait Implementations§
impl RefUnwindSafe for GeoJson
impl Send for GeoJson
impl Sync for GeoJson
impl Unpin for GeoJson
impl UnwindSafe for GeoJson
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