Skip to content
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

Simplify indices #402

Merged
merged 8 commits into from
Dec 27, 2019
Merged

Simplify indices #402

merged 8 commits into from
Dec 27, 2019

Conversation

urschrei
Copy link
Member

This PR adds a new trait to the simplify and simplifyVW modules: SimplifyIdx and SimplifyVwIdx.
Both traits do the same thing: they run the respective simplification algorithm, but return the indices of the simplified LineString, instead of the simplified geometry. This is mostly in response to ongoing requests from FFI consumers: because their use-cases don't necessarily map onto the Simple Features geometry model, returning geometries is less useful than returning indices, which can be used as mask values / input into native filter functions.

The only current drawback to these new traits is that because they return Vec<usize>, they're only implemented for LineString. If there's a more flexible way to do it, I'd love to extend it to some other geometries.

This change introduces some additional indirection for the RDP implementation, but cargo bench hasn't shown a perf hit…

Algorithms that can result in simplified geometries should have
functions that return the indices of the simplified input geometry –
this is particularly useful for users in an FFI context, where the
source geometries may have different data structures – returning only
indices allows these users to use their language-specific filter/mask
functions to construct / mutate their input geometries.

The revised implementation doesn't show a significant benchmark
difference.
This trait allows RDP simplification operations on LineStrings to
return indices instead of the points themselves
Copy link
Member

@frewsxcv frewsxcv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea! lgtm ✅

@@ -63,7 +63,8 @@ pub mod private_utils;
#[macro_use]
extern crate approx;

mod test {
#[cfg(test)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

/// Simplifies a geometry, returning the retained _indices_ of the input.
///
/// This operation uses the [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer–Douglas–Peucker_algorithm)
/// and does not guarantee that the returned geometry is valid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding docs!

&self
.clone()
.into_points()
.iter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of self.clone().into_points().iter(), you can avoid the memory allocation by doing self.points_iter()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're Copy types anyway, so this shouldn't make any difference
perf-wise, and it allows us to do away with lifetime complexity and
avoid an allocation in simplify_idx
@urschrei
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Dec 27, 2019
402: Simplify indices r=urschrei a=urschrei

This PR adds a new trait to the `simplify` and `simplifyVW` modules: `SimplifyIdx` and `SimplifyVwIdx`.
Both traits do the same thing: they run the respective simplification algorithm, but return the _indices_ of the simplified `LineString`, instead of the simplified geometry. This is mostly in response to ongoing requests from FFI consumers: because their use-cases don't necessarily map onto the Simple Features geometry model, returning geometries is less useful than returning indices, which can be used as mask values / input into native filter functions.

The only current drawback to these new traits is that because they return `Vec<usize>`, they're only implemented for `LineString`. If there's a more flexible way to do it, I'd love to extend it to some other geometries.

This change introduces some additional indirection for the RDP implementation, but `cargo bench` hasn't shown a perf hit…

Co-authored-by: Stephan Hügel <shugel@tcd.ie>
Co-authored-by: Stephan Hügel <urschrei@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 27, 2019

Build succeeded

@bors bors bot merged commit 879e58f into georust:master Dec 27, 2019
bors bot added a commit that referenced this pull request Dec 29, 2019
403: Doc updates r=urschrei a=urschrei

(To be merged after #402)

This PR adds top-level docs (mostly the same as what's currently in the README), and the following changes:

- Revised `LineString` docs
- Revised `Point` docs
- Revised module docs to better distinguish `closest_point` and `euclidean_distance`
- Revised `chamberlain_duquette` docs
- Revised `haversine_destination` module doc
- Note existence of some non-euclidean distance algorithms
- Detail optional features
- Make GeoJSON interop more obvious. This is somewhat redundant, since the GeoJSON crate says the same thing, but we don't know what crate people will see first, so I think it's OK
- Hidden the `PointsIter` struct from docs.rs

Co-authored-by: Stephan Hügel <shugel@tcd.ie>
@urschrei urschrei deleted the simplify_indices branch February 14, 2025 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants