Skip to content

Commit af11591

Browse files
authored
Add DirectedHausdorffDistance class (#1182)
1 parent e425b96 commit af11591

12 files changed

Lines changed: 1829 additions & 63 deletions

File tree

modules/app/src/main/java/org/locationtech/jtstest/function/DistanceFunctions.java

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import org.locationtech.jts.algorithm.distance.DiscreteFrechetDistance;
1515
import org.locationtech.jts.algorithm.distance.DiscreteHausdorffDistance;
16+
import org.locationtech.jts.algorithm.distance.DirectedHausdorffDistance;
1617
import org.locationtech.jts.geom.Coordinate;
1718
import org.locationtech.jts.geom.Geometry;
1819
import org.locationtech.jts.geom.LineString;
@@ -45,53 +46,61 @@ public static Geometry frechetDistanceLine(Geometry a, Geometry b)
4546
return a.getFactory().createLineString(dist.getCoordinates());
4647
}
4748

48-
public static double hausdorffDistance(Geometry a, Geometry b)
49+
@Metadata(description="Oriented discrete Hausdorff distance from A to B")
50+
public static double orientedDiscreteHausdorffDistance(Geometry a, Geometry b)
51+
{
52+
return DiscreteHausdorffDistance.orientedDistance(a, b);
53+
}
54+
55+
@Metadata(description="Oriented discrete Hausdorff distance line from A to B, densified")
56+
public static Geometry orientedDiscreteHausdorffLineDensify(Geometry a, Geometry b,
57+
@Metadata(title="Densify fraction")
58+
double frac)
4959
{
50-
return DiscreteHausdorffDistance.distance(a, b);
60+
return DiscreteHausdorffDistance.orientedDistanceLine(a, b, frac);
61+
}
62+
63+
@Metadata(description="Clipped directed Hausdorff distance from A to B")
64+
public static Geometry clippedDirectedHausdorffLine(Geometry a, Geometry b)
65+
{
66+
Geometry clippedLine = LinearReferencingFunctions.project(a, b);
67+
Coordinate[] pts = DirectedHausdorffDistance.distancePoints(clippedLine, b);
68+
return a.getFactory().createLineString(pts);
5169
}
5270

53-
@Metadata(description="Hausdorff distance between A and B")
54-
public static Geometry hausdorffDistanceLine(Geometry a, Geometry b)
71+
@Metadata(description="Directed Hausdorff distance from A to B, up to tolerance")
72+
public static double directedHausdorffDistance(Geometry a, Geometry b,
73+
@Metadata(title="Distance tolerance")
74+
double distTol)
5575
{
56-
return DiscreteHausdorffDistance.distanceLine(a, b);
76+
return DirectedHausdorffDistance.distance(a, b, distTol);
5777
}
58-
59-
@Metadata(description="Hausdorff distance between A and B, densified")
60-
public static Geometry hausdorffDistanceLineDensify(Geometry a, Geometry b,
61-
@Metadata(title="Densify fraction")
62-
double frac)
63-
{
64-
return DiscreteHausdorffDistance.distanceLine(a, b, frac);
65-
}
66-
67-
@Metadata(description="Oriented Hausdorff distance from A to B")
68-
public static Geometry orientedHausdorffDistanceLine(Geometry a, Geometry b)
78+
79+
@Metadata(description="Directed Hausdorff distance line from A to B, up to tolerance")
80+
public static Geometry directedHausdorffLineTol(Geometry a, Geometry b,
81+
@Metadata(title="Distance tolerance")
82+
double distTol)
6983
{
70-
return DiscreteHausdorffDistance.orientedDistanceLine(a, b);
84+
Coordinate[] pts = DirectedHausdorffDistance.distancePoints(a, b, distTol);
85+
return a.getFactory().createLineString(pts);
7186
}
72-
73-
@Metadata(description="Oriented Hausdorff distance from A to B")
74-
public static Geometry clippedOrientedHausdorffDistanceLine(Geometry a, Geometry b)
87+
88+
@Metadata(description="Directed Hausdorff distance line from A to B")
89+
public static Geometry directedHausdorffLine(Geometry a, Geometry b)
7590
{
76-
//TODO: would this be more efficient done as part of DiscreteHausdorffDistance?
77-
Geometry clippedLine = LinearReferencingFunctions.project(a, b);
78-
return DiscreteHausdorffDistance.orientedDistanceLine(clippedLine, b);
91+
Coordinate[] pts = DirectedHausdorffDistance.distancePoints(a, b);
92+
return a.getFactory().createLineString(pts);
7993
}
80-
81-
@Metadata(description="Oriented Hausdorff distance from A to B")
82-
public static double orientedHausdorffDistance(Geometry a, Geometry b)
83-
{
84-
return DiscreteHausdorffDistance.orientedDistance(a, b);
85-
}
86-
87-
@Metadata(description="Oriented Hausdorff distance from A to B, densified")
88-
public static Geometry orientedHausdorffDistanceLineDensify(Geometry a, Geometry b,
89-
@Metadata(title="Densify fraction")
90-
double frac)
94+
95+
@Metadata(description="Hausdorff distance between A and B, up to tolerance")
96+
public static Geometry hausdorffLine(Geometry a, Geometry b)
9197
{
92-
return DiscreteHausdorffDistance.orientedDistanceLine(a, b, frac);
98+
Coordinate[] pts = DirectedHausdorffDistance.hausdorffDistancePoints(a, b);
99+
return a.getFactory().createLineString(pts);
93100
}
94-
101+
102+
//--------------------------------------------
103+
95104
public static double distanceIndexed(Geometry a, Geometry b) {
96105
return IndexedFacetDistance.distance(a, b);
97106
}
@@ -117,4 +126,5 @@ public static Geometry nearestPointsIndexedEachB(Geometry a, Geometry b) {
117126

118127
return a.getFactory().createMultiLineString(lines);
119128
}
129+
120130
}

modules/app/src/main/java/org/locationtech/jtstest/function/SelectionFunctions.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717

1818
import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle;
19+
import org.locationtech.jts.algorithm.distance.DirectedHausdorffDistance;
1920
import org.locationtech.jts.geom.Geometry;
2021
import org.locationtech.jts.geom.prep.PreparedGeometry;
2122
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
@@ -238,6 +239,25 @@ public boolean isTrue(Geometry g) {
238239
});
239240
}
240241

242+
public static Geometry fullyWithinDistance(Geometry a, final Geometry mask, double maximumDistance)
243+
{
244+
return select(a, new GeometryPredicate() {
245+
public boolean isTrue(Geometry g) {
246+
return DirectedHausdorffDistance.isFullyWithinDistance(g, mask, maximumDistance);
247+
}
248+
});
249+
}
250+
251+
public static Geometry fullyWithinDistancePrep(Geometry a, final Geometry mask, double maximumDistance)
252+
{
253+
DirectedHausdorffDistance dhd = new DirectedHausdorffDistance(mask);
254+
return select(a, new GeometryPredicate() {
255+
public boolean isTrue(Geometry g) {
256+
return dhd.isFullyWithinDistance(g, maximumDistance);
257+
}
258+
});
259+
}
260+
241261
public static Geometry maxInCircleRadiusWithin(Geometry a,
242262
@Metadata(title="Max Radius Length")
243263
double maximumRadius)

modules/core/src/main/java/org/locationtech/jts/algorithm/construct/IndexedDistanceToPoint.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
package org.locationtech.jts.algorithm.construct;
1313

14+
import org.locationtech.jts.algorithm.locate.IndexedPointInPolygonsLocator;
1415
import org.locationtech.jts.geom.Coordinate;
1516
import org.locationtech.jts.geom.Geometry;
1617
import org.locationtech.jts.geom.Location;

0 commit comments

Comments
 (0)