1313
1414import org .locationtech .jts .algorithm .distance .DiscreteFrechetDistance ;
1515import org .locationtech .jts .algorithm .distance .DiscreteHausdorffDistance ;
16+ import org .locationtech .jts .algorithm .distance .DirectedHausdorffDistance ;
1617import org .locationtech .jts .geom .Coordinate ;
1718import org .locationtech .jts .geom .Geometry ;
1819import 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}
0 commit comments