Skip to content

Remove geojson::Crs. #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name = "geojson"
description = "Library for serializing the GeoJSON vector GIS file format"
version = "0.7.1"
version = "0.8.0"
authors = ["Corey Farwell <[email protected]>",
"Blake Grotewold <[email protected]>"]
license = "MIT/Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ properties.insert(
);

let geojson = GeoJson::Feature(Feature {
crs: None,
bbox: None,
geometry: Some(geometry),
id: None,
properties: Some(properties),
foreign_members: None,
});

let geojson_string = geojson.to_string();
Expand Down
120 changes: 0 additions & 120 deletions src/crs.rs

This file was deleted.

11 changes: 1 addition & 10 deletions src/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use json::{Serialize, Deserialize, Serializer, Deserializer, JsonValue, JsonObject};
use serde_json;
use {Bbox, Crs, Error, FromObject, Geometry, util};
use {Bbox, Error, FromObject, Geometry, util};


/// Feature Objects
Expand All @@ -24,7 +24,6 @@ use {Bbox, Crs, Error, FromObject, Geometry, util};
#[derive(Clone, Debug, PartialEq)]
pub struct Feature {
pub bbox: Option<Bbox>,
pub crs: Option<Crs>,
pub geometry: Option<Geometry>,
pub id: Option<JsonValue>,
pub properties: Option<JsonObject>,
Expand All @@ -45,9 +44,6 @@ impl<'a> From<&'a Feature> for JsonObject {
map.insert(String::from("properties"),
serde_json::to_value(properties).unwrap());
}
if let Some(ref crs) = feature.crs {
map.insert(String::from("crs"), serde_json::to_value(crs).unwrap());
}
if let Some(ref bbox) = feature.bbox {
map.insert(String::from("bbox"), serde_json::to_value(bbox).unwrap());
}
Expand All @@ -69,7 +65,6 @@ impl FromObject for Feature {
geometry: try!(util::get_geometry(object)),
properties: try!(util::get_properties(object)),
id: try!(util::get_id(object)),
crs: try!(util::get_crs(object)),
bbox: try!(util::get_bbox(object)),
foreign_members: try!(util::get_foreign_members(object, "Feature"))
});
Expand Down Expand Up @@ -115,12 +110,10 @@ mod tests {
::Feature {
geometry: Some(Geometry {
value: Value::Point(vec![1.1, 2.1]),
crs: None,
bbox: None,
foreign_members: None
}),
properties: properties(),
crs: None,
bbox: None,
id: None,
foreign_members: None
Expand Down Expand Up @@ -187,12 +180,10 @@ mod tests {
let feature = ::Feature {
geometry: Some(Geometry {
value: Value::Point(vec![1.1, 2.1]),
crs: None,
bbox: None,
foreign_members: None
}),
properties: properties(),
crs: None,
bbox: None,
id: None,
foreign_members: Some(foreign_members)
Expand Down
9 changes: 1 addition & 8 deletions src/feature_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use json::{Serialize, Deserialize, Serializer, Deserializer, JsonObject};
use serde_json;

use {Bbox, Crs, Error, Feature, FromObject, util};
use {Bbox, Error, Feature, FromObject, util};


/// Feature Collection Objects
Expand All @@ -35,7 +35,6 @@ use {Bbox, Crs, Error, Feature, FromObject, util};
///
/// let feature_collection = FeatureCollection {
/// bbox: None,
/// crs: None,
/// features: vec![],
/// foreign_members: None,
/// };
Expand All @@ -51,7 +50,6 @@ use {Bbox, Crs, Error, Feature, FromObject, util};
#[derive(Clone, Debug, PartialEq)]
pub struct FeatureCollection {
pub bbox: Option<Bbox>,
pub crs: Option<Crs>,
pub features: Vec<Feature>,
/// Foreign Members
///
Expand All @@ -67,10 +65,6 @@ impl<'a> From<&'a FeatureCollection> for JsonObject {
map.insert(String::from("features"),
serde_json::to_value(&fc.features).unwrap());

if let Some(ref crs) = fc.crs {
map.insert(String::from("crs"), serde_json::to_value(crs).unwrap());
}

if let Some(ref bbox) = fc.bbox {
map.insert(String::from("bbox"), serde_json::to_value(bbox).unwrap());
}
Expand All @@ -90,7 +84,6 @@ impl FromObject for FeatureCollection {
return Ok(FeatureCollection {
bbox: try!(util::get_bbox(object)),
features: try!(util::get_features(object)),
crs: try!(util::get_crs(object)),
foreign_members: try!(util::get_foreign_members(object, "FeatureCollection"))
});
}
Expand Down
21 changes: 6 additions & 15 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use json::{Serialize, Deserialize, Serializer, Deserializer, JsonValue, JsonObject};

use {Bbox, Crs, Error, LineStringType, PointType, PolygonType, FromObject, util};
use {Bbox, Error, LineStringType, PointType, PolygonType, FromObject, util};


/// The underlying Geometry value
Expand Down Expand Up @@ -94,7 +94,6 @@ impl Serialize for Value {
pub struct Geometry {
pub bbox: Option<Bbox>,
pub value: Value,
pub crs: Option<Crs>,
/// Foreign Members
///
/// [RFC7946 § 6]
Expand All @@ -103,13 +102,12 @@ pub struct Geometry {
}

impl Geometry {
/// Returns a new `Geometry` with the specified `value`. `bbox` and `crs` will be set to
/// `None`.
/// Returns a new `Geometry` with the specified `value`. `bbox` and `foreign_members` will be
/// set to `None`.
pub fn new(value: Value) -> Self {
Geometry {
bbox: None,
value: value,
crs: None,
foreign_members: None
}
}
Expand All @@ -118,9 +116,6 @@ impl Geometry {
impl<'a> From<&'a Geometry> for JsonObject {
fn from(geometry: &'a Geometry) -> JsonObject {
let mut map = JsonObject::new();
if let Some(ref crs) = geometry.crs {
map.insert(String::from("crs"), ::serde_json::to_value(crs).unwrap());
}
if let Some(ref bbox) = geometry.bbox {
map.insert(String::from("bbox"), ::serde_json::to_value(bbox).unwrap());
}
Expand Down Expand Up @@ -166,13 +161,11 @@ impl FromObject for Geometry {
};

let bbox = try!(util::get_bbox(object));
let crs = try!(util::get_crs(object));
let foreign_members = try!(util::get_foreign_members(object, "Geometry"));

return Ok(Geometry {
bbox: bbox,
value: value,
crs: crs,
foreign_members: foreign_members
});
}
Expand Down Expand Up @@ -220,7 +213,6 @@ mod tests {
let geometry_json_str = "{\"coordinates\":[1.1,2.1],\"type\":\"Point\"}";
let geometry = Geometry {
value: Value::Point(vec![1.1, 2.1]),
crs: None,
bbox: None,
foreign_members: None
};
Expand All @@ -244,7 +236,6 @@ mod tests {
foreign_members.insert(String::from("other_member"), serde_json::to_value(true).unwrap());
let geometry = Geometry {
value: Value::Point(vec![1.1, 2.1]),
crs: None,
bbox: None,
foreign_members: Some(foreign_members)
};
Expand All @@ -266,10 +257,10 @@ mod tests {
let geometry_collection = Geometry {
bbox: None,
value: Value::GeometryCollection(vec![
Geometry { bbox: None, value: Value::Point(vec![100.0, 0.0]), crs: None, foreign_members: None },
Geometry { bbox: None, value: Value::Point(vec![100.0, 0.0]), foreign_members: None },
Geometry { bbox: None, value: Value::LineString(vec![vec![101.0, 0.0], vec![102.0, 1.0]]),
crs: None, foreign_members: None }]),
crs: None, foreign_members: None };
foreign_members: None }]),
foreign_members: None };

let geometry_collection_string = "{\"geometries\":[{\"coordinates\":[100.0,0.0],\"type\":\"Point\"},{\"coordinates\":[[101.0,0.0],[102.0,1.0]],\"type\":\"LineString\"}],\"type\":\"GeometryCollection\"}";
// Test encode
Expand Down
13 changes: 0 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
//! );
//!
//! let geojson = GeoJson::Feature(Feature {
//! crs: None,
//! bbox: None,
//! geometry: Some(geometry),
//! id: None,
Expand Down Expand Up @@ -126,9 +125,6 @@ mod macros;

mod util;

mod crs;
pub use crs::Crs;

mod geojson;
pub use geojson::GeoJson;

Expand All @@ -150,8 +146,6 @@ pub mod conversion;
pub enum Error {
BboxExpectedArray,
BboxExpectedNumericValues,
CrsExpectedObject,
CrsUnknownType(String),
GeoJsonExpectedObject,
GeoJsonUnknownType,
GeometryUnknownType,
Expand All @@ -176,11 +170,6 @@ impl std::fmt::Display for Error {
Error::BboxExpectedNumericValues =>
// FIXME: inform what type we actually found
write!(f, "Encountered non-numeric value within 'bbox' array."),
Error::CrsExpectedObject =>
// FIXME: inform what type we actually found
write!(f, "Encountered non-object type for a 'crs' object."),
Error::CrsUnknownType(ref t) =>
write!(f, "Encountered unknown type '{}' for a 'crs' object.", t),
Error::GeoJsonExpectedObject =>
// FIXME: inform what type we actually found
write!(f, "Encountered non-object type for GeoJSON."),
Expand Down Expand Up @@ -219,8 +208,6 @@ impl std::error::Error for Error {
match *self {
Error::BboxExpectedArray => "non-array 'bbox' type",
Error::BboxExpectedNumericValues => "non-numeric 'bbox' array",
Error::CrsExpectedObject => "non-object 'crs' type",
Error::CrsUnknownType(..) => "unknown 'crs' type",
Error::GeoJsonExpectedObject => "non-object GeoJSON type",
Error::GeoJsonUnknownType => "unknown GeoJSON object type",
Error::GeometryUnknownType => "unknown 'geometry' object type",
Expand Down
Loading