-
Notifications
You must be signed in to change notification settings - Fork 449
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
Add DiscreteFrechetDistance #764
Add DiscreteFrechetDistance #764
Conversation
Signed-off-by: Felix Obermaier <[email protected]>
* Fix HausdorffSimilarityMeasure to handle equal `POINT` geometries by using fast exit if `DiscreteHausdorffDistance.distance` returns 0d. * Add/extend unit tests
* | ||
* @author Felix Obermaier | ||
*/ | ||
public interface DistanceFunction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term "function" is fairly overloaded in the JTS codebase. Can this be changed to DistanceMetric
?
Frechet Distance is a nice addition to JTS. How do you see the |
It is very useful to have distance algorithms also be able to return the two points at which the calculated distance is obtained. This is for confirmation and visualization purposes. (For example see the implementation in Is it possible to add this capability to the Frechet Distance code? |
I thought about an implementation using |
In geodetic space the locus of boundary segments between vertices is a great circle arc, rather than a straight line. So usually it requires more than just using a geodetic distance metric to produce accurate results. Of course, geometries can be densified to mitigate this somewhat. i have had some thoughts about bundling up the various pieces of metadata about the geometry coordinate system (including geodetic information and precision model) into a single object (perhaps called Given this, I'd prefer to defer introducing the |
@FObermaier is there a bug in this algorithm? What should the Frechet Distance be between the following:
The implementation gives the distance as 2.23606797749979. But since the distance between the two start points is 3, shouldn't that be the overall Frechet Distance? A fix has been developed in #783. |
Yes, I'm working on it. |
* Add getCoordinates() to DiscreteFrechetDistance * Add DiscreteFrechetDistanceLinear for validation of unit tests * Add unit test * Add code documentation to PointPairDistance
* Add DiscreteFrechetDistanceLinear to tests for verification. * Add MatrixStorage and implementations CsrMatrix, RectMatrix and HashMapMatrix * Add unit tests for MatrixStorage * Add unit tests
8db79ca
to
9aaa5ba
Compare
@dr-jts, I fixed the algorithm, sorry for doing PR too early. |
int max = Math.max(rows, cols); | ||
// NOTE: these constraints need to be verified | ||
if (max < 64) | ||
return new HashMapMatrix(rows, cols, Double.POSITIVE_INFINITY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this faster? If not, why not just use a RectMatrix
, since storage isn't a problem for small dimensions?
/** | ||
* Abstract base class for storing 2d matrix data | ||
*/ | ||
private abstract static class MatrixStorage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unusual to duplicate implementation code in unit tests, since this doesn't actually test the code in the library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not see another way to test and verify that MatrixStorage
implementations work correctly while keeping it private in jts-core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a bit of a limitation in the Java package model. I usually make things like this package-private, so they can be unit tested.
* remove code duplication in unit test * remove constraint for HashMapMatrix
/** | ||
* Linear Discrete Fréchet Distance computation | ||
*/ | ||
public class DiscreteFrechetDistanceLinear { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this class do differently to DiscreteFrechetDistance
? Are they both needed?
Computing the distance between the following geometries causes an
It looks like the error occurs in the Bresenham diagonal generating method, when geometry B has fewer than half the vertices of geometry A. |
* | ||
* @param numCols the number of columns | ||
* @param numRows the number of rows | ||
* @return an array of column and row indices bitwise-or combined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? Or is the returned array a "flattened" set of X,Y indices?
Like
Hausdorff
distance theFréchet
distance is a measure of similarity between curves.Its metric is better than
Hausdorff
's because it takes the flow of the curves into account.It is possible that two curves have a small
Hausdorff
but a largeFréchet
distance.This implementation is based on the following optimized Fréchet distance algorithm:
It attempts to compute only relevant coordinate distances for perfromance.
It provides a minimal
MatrixStorage
base class and implementations that trade off memory consumption and performance.Signed-off-by: Felix Obermaier [email protected]