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

Implement Point to multipart geometry distance methods #104

Merged
5 commits merged into from
Mar 18, 2017

Conversation

urschrei
Copy link
Member

@urschrei urschrei commented Mar 17, 2017

This adds distance methods and tests from Point to:

  • MultiPoint
  • MultiLineString
  • MultiPolygon

For large MultiPolygons in particular, this could potentially be very slow. One approach would be the use of a spatial index storing the Polygon BoundingBoxes. Retrieving the closest one to the point, then calculating Point-to-Polygon distance would be much faster. There are a number of {quad-, r-, n-}tree implementations around in various states of maintenance, e.g. acacia, or (much heavier, extensively tested) Spade, so it'd be mostly a case of gluing things together.

(It might also be good to have a spatial index crate backed by one of those implementations in geo-rust, but that's a separate issue)

impl<T> Distance<T, MultiPolygon<T>> for Point<T>
where T: Float
{
fn distance(&self, mpolygon: &MultiPolygon<T>) -> T {
Copy link
Member

Choose a reason for hiding this comment

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

I think if you did:

    /// Minimum distance from a Point to a MultiPolygon
    fn distance(&self, mpolygon: &MultiPolygon<T>) -> T {

It would show up in documentation (via rustdoc), just to be explicit about the behavior here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -167,7 +168,8 @@ impl<T> Distance<T, Polygon<T>> for Point<T>
// Minimum distance from a Point to a MultiPolygon
impl<T> Distance<T, MultiPolygon<T>> for Point<T>
where T: Float
{
{
Copy link
Member

Choose a reason for hiding this comment

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

Nit: whitespace

@@ -180,7 +182,8 @@ impl<T> Distance<T, MultiPolygon<T>> for Point<T>
// Minimum distance from a Point to a MultiLineString
impl<T> Distance<T, MultiLineString<T>> for Point<T>
where T: Float
{
{
Copy link
Member

Choose a reason for hiding this comment

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

Nit: whitespace

@frewsxcv
Copy link
Member

LGTM after whitespace is addressed

@frewsxcv
Copy link
Member

bors r+

ghost pushed a commit that referenced this pull request Mar 18, 2017
104: Implement Point to multipart geometry distance methods r=frewsxcv
This adds distance methods and tests from Point to:
- MultiPoint
- MultiLineString
- MultiPolygon

For large MultiPolygons in particular, this could potentially be very slow. One approach would be the use of a spatial index storing the Polygon BoundingBoxes. Retrieving the closest one to the point, then calculating Point-to-Polygon distance would be much faster. There are a number of {quad-, r-, n-}tree implementations around in various states of maintenance, e.g. [acacia](https://github.com/aepsil0n/acacia), or (much heavier, extensively tested) [Spade](https://stoeoef.github.io/spade/spade/struct.RTree.html), so it'd be mostly a case of gluing things together.

(It might also be good to have a spatial index crate backed by one of those implementations in geo-rust, but that's a separate issue)
@ghost
Copy link

ghost commented Mar 18, 2017

Build succeeded

@ghost ghost merged commit 33795c7 into georust:master Mar 18, 2017
@urschrei urschrei deleted the multipart_geometry_distance branch March 18, 2017 00:24
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