Skip to content

Commit

Permalink
clean up errors
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Oct 22, 2023
1 parent c77e1de commit 482c2ae
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 62 deletions.
18 changes: 8 additions & 10 deletions geo-features/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ impl FeatureBuilder {
FeatureBuilder { properties, ..self }
}

pub fn build(self) -> Result<Feature, BoundingRectError> {
pub fn build(self) -> Feature {
let bounding_rect = self
.geometry
.as_ref()
.and_then(|geometry| geometry.bounding_rect());
Ok(Feature {
Feature {
id: FeatureId::new(),
geometry: self.geometry,
properties: self.properties,
bounding_rect,
})
}
}
}

Expand Down Expand Up @@ -93,12 +93,11 @@ pub enum Value {
pub type Properties = collections::HashMap<String, Value>;

impl Feature {
pub fn recalculate_bounding_rect(&mut self) -> Result<(), BoundingRectError> {
pub fn recalculate_bounding_rect(&mut self) {
self.bounding_rect = self
.geometry
.as_ref()
.and_then(|geometry| geometry.bounding_rect());
Ok(())
}
}

Expand Down Expand Up @@ -182,9 +181,9 @@ impl fmt::Display for BoundingRectError {
impl std::error::Error for BoundingRectError {}

impl FeatureCollection {
pub fn from_geometry(geometry: geo::Geometry) -> Result<Self, BoundingRectError> {
let feature = FeatureBuilder::new().with_geometry(geometry).build()?;
Ok(Self::from_feature(feature))
pub fn from_geometry(geometry: geo::Geometry) -> Self {
let feature = FeatureBuilder::new().with_geometry(geometry).build();
Self::from_feature(feature)
}

pub fn from_feature(feature: Feature) -> Self {
Expand Down Expand Up @@ -216,9 +215,8 @@ impl FeatureCollection {
)
}

pub fn recalculate_bounding_rect(&mut self) -> Result<(), BoundingRectError> {
pub fn recalculate_bounding_rect(&mut self) {
self.bounding_rect = bounding_rect_from_features(&self.features);
Ok(())
}
}

Expand Down
6 changes: 2 additions & 4 deletions geo-file-loader/src/geojson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ pub enum LoadGeoJsonError {
#[error("{0}")]
SerdeJson(#[from] serde_json::Error),
#[error("{0}")]
BoundingRect(#[from] geo_features::BoundingRectError),
#[error("{0}")]
JsonNumberToFloat(#[from] JsonNumberToFloatError),
}

Expand Down Expand Up @@ -94,7 +92,7 @@ fn geojson_geometry_to_geo_feature_collection(
let geo_geometry: geo::Geometry = geojson_geometry.try_into().map_err(Box::new)?;
let feature = geo_features::FeatureBuilder::new()
.with_geometry(geo_geometry)
.build()?;
.build();
Ok(geo_features::FeatureCollection::from_feature(feature))
}

Expand All @@ -110,7 +108,7 @@ fn geojson_feature_to_geo_feature(
{
feature_builder = feature_builder.with_geometry(geo_geometry);
}
Ok(feature_builder.build()?)
Ok(feature_builder.build())
}

fn geojson_feature_properties_to_geo_features_properties(
Expand Down
2 changes: 1 addition & 1 deletion geo-file-loader/src/shapefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ impl crate::FileLoader for ShapefileSource {
let mut geo_writer = geozero::geo_types::GeoWriter::new();
for _ in shapefile_reader.iter_geometries(&mut geo_writer) {}
let geometry = geo_writer.take_geometry().unwrap();
Ok(geo_features::FeatureCollection::from_geometry(geometry).unwrap())
Ok(geo_features::FeatureCollection::from_geometry(geometry))
}
}
4 changes: 1 addition & 3 deletions geo-file-loader/src/wkt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use geozero::GeozeroDatasource;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("{0}")]
BoundingRect(#[from] geo_features::BoundingRectError),
#[error("{0}")]
Geozero(#[from] geozero::error::GeozeroError),
}
Expand All @@ -29,7 +27,7 @@ impl crate::FileLoader for WktSource {
let mut geo_writer = geozero::geo_types::GeoWriter::new();
wkt_reader.process(&mut geo_writer)?;
match geo_writer.take_geometry() {
Some(geometry) => Ok(geo_features::FeatureCollection::from_geometry(geometry)?),
Some(geometry) => Ok(geo_features::FeatureCollection::from_geometry(geometry)),
None => Ok(geo_features::FeatureCollection::default()),
}
}
Expand Down
4 changes: 2 additions & 2 deletions geo-projected/src/feature_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ macro_rules! feature_collection_impl {
impl $outer_ty<$specific_inner_ty> {
pub fn from_geometry(
geometry: geo::Geometry,
) -> Result<$outer_ty<$general_inner_ty>, geo_features::BoundingRectError> {
<$general_inner_ty>::from_geometry(geometry).map($outer_ty)
) -> $outer_ty<$general_inner_ty> {
$outer_ty(<$general_inner_ty>::from_geometry(geometry))
}

pub fn features_iter(&self) -> impl Iterator<Item = $outer_ty<&geo_features::Feature>> {
Expand Down
2 changes: 1 addition & 1 deletion rgis-geo-ops/src/convex_hull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Operation for ConvexHull {
let outcome = geo::GeometryCollection(geometries).convex_hull();

Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new(
geo_features::FeatureCollection::from_geometry(outcome.into())?,
geo_features::FeatureCollection::from_geometry(outcome.into()),
)))
}
}
2 changes: 1 addition & 1 deletion rgis-geo-ops/src/outliers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Operation for Outliers {
let new_multi_point = geo::MultiPoint::new(non_outliers);

Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new(
geo_features::FeatureCollection::from_geometry(new_multi_point.into())?,
geo_features::FeatureCollection::from_geometry(new_multi_point.into()),
)))
}
}
2 changes: 1 addition & 1 deletion rgis-geo-ops/src/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Operation for Simplify {
Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new(
geo_features::FeatureCollection::from_geometry(geo::Geometry::GeometryCollection(
simplified,
))?,
)),
)))
}
}
2 changes: 1 addition & 1 deletion rgis-geo-ops/src/smoothing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Operation for Smoothing {
Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new(
geo_features::FeatureCollection::from_geometry(geo::Geometry::GeometryCollection(
smoothed,
))?,
)),
)))
}
}
2 changes: 1 addition & 1 deletion rgis-geo-ops/src/triangulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Operation for Triangulate {
);

Ok(Outcome::FeatureCollection(geo_projected::Unprojected::new(
geo_features::FeatureCollection::from_geometry(multi_polygon.into())?,
geo_features::FeatureCollection::from_geometry(multi_polygon.into()),
)))
}
}
4 changes: 2 additions & 2 deletions rgis-layers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Layers {
unprojected: geo_projected::Unprojected<geo_features::FeatureCollection>,
name: String,
source_crs: String,
) -> Result<rgis_layer_id::LayerId, geo_features::BoundingRectError> {
) -> rgis_layer_id::LayerId {
let layer_id = self.next_layer_id();
let geom_type = geo_geom_type::determine(unprojected.as_raw().geometry_iter());
let layer = Layer {
Expand All @@ -175,7 +175,7 @@ impl Layers {
geom_type,
};
self.data.push(layer);
Ok(layer_id)
layer_id
}

pub fn clear_projected(&mut self) {
Expand Down
8 changes: 2 additions & 6 deletions rgis-layers/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,8 @@ fn handle_create_layer_events(
mut layers: ResMut<crate::Layers>,
) {
for event in create_layer_events.drain() {
match layers.add(event.feature_collection, event.name, event.source_crs) {
Ok(layer_id) => {
layer_created_event_writer.send(rgis_events::LayerCreatedEvent(layer_id))
}
Err(e) => bevy::log::error!("Encountered error when creating layer: {:?}", e),
}
let layer_id = layers.add(event.feature_collection, event.name, event.source_crs);
layer_created_event_writer.send(rgis_events::LayerCreatedEvent(layer_id))
}
}

Expand Down
4 changes: 2 additions & 2 deletions rgis-transform/src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ impl bevy_jobs::Job for ReprojectGeometryJob {
transformer.transform(geometry)?;
}

feature.0.recalculate_bounding_rect()?;
feature.0.recalculate_bounding_rect();
}

self.feature_collection.0.recalculate_bounding_rect()?;
self.feature_collection.0.recalculate_bounding_rect();

Ok(ReprojectGeometryJobOutcome {
feature_collection: self.feature_collection.into_projected(),
Expand Down
2 changes: 0 additions & 2 deletions rgis-transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ pub enum TransformError {
#[cfg(not(target_arch = "wasm32"))]
#[error("{0}")]
Proj(#[from] geo::algorithm::proj::TransformError),
#[error("{0}")]
BoundingRect(#[from] geo_features::BoundingRectError),
}

pub trait Transformer {
Expand Down
46 changes: 21 additions & 25 deletions rgis-ui/src/side_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,46 +130,42 @@ impl<'a, 'w> SidePanel<'a, 'w> {
if let Ok(bounding_rect) =
layer.unprojected_feature_collection.bounding_rect()
{
if let Ok(feature_collection) = geo_projected::Unprojected::<
let feature_collection = geo_projected::Unprojected::<
geo_features::FeatureCollection,
>::from_geometry(
bounding_rect.0.into()
) {
self.events.create_layer_event_writer.send(
rgis_events::CreateLayerEvent {
feature_collection, // todo
name: "Bounding rect".into(), // todo
source_crs: layer.crs.clone(),
},
);
}
);
self.events.create_layer_event_writer.send(
rgis_events::CreateLayerEvent {
feature_collection, // todo
name: "Bounding rect".into(), // todo
source_crs: layer.crs.clone(),
},
);
}
}

OperationButton::<rgis_geo_ops::ConvexHull>::new(
self.events,
layer,
).ui(ui);
OperationButton::<rgis_geo_ops::Outliers>::new(
self.events,
layer,
).ui(ui);
OperationButton::<rgis_geo_ops::Simplify>::new(
self.events,
layer,
).ui(ui);
OperationButton::<rgis_geo_ops::Smoothing>::new(
self.events,
layer,
).ui(ui);
)
.ui(ui);
OperationButton::<rgis_geo_ops::Outliers>::new(self.events, layer)
.ui(ui);
OperationButton::<rgis_geo_ops::Simplify>::new(self.events, layer)
.ui(ui);
OperationButton::<rgis_geo_ops::Smoothing>::new(self.events, layer)
.ui(ui);
OperationButton::<rgis_geo_ops::Triangulate>::new(
self.events,
layer,
).ui(ui);
)
.ui(ui);
OperationButton::<rgis_geo_ops::UnsignedArea>::new(
self.events,
layer,
).ui(ui);
)
.ui(ui);
});
});
});
Expand Down

0 comments on commit 482c2ae

Please sign in to comment.