| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package org.locationtech.jts.index.strtree; |
| 14 |
|
| 15 |
import org.locationtech.jts.geom.Geometry; |
| 16 |
|
| 17 |
/** |
| 18 |
* An {@link ItemDistance} function for |
| 19 |
* items which are {@link Geometry}s, |
| 20 |
* using the {@link Geometry#distance(Geometry)} method. |
| 21 |
* <p> |
| 22 |
* To make this distance function suitable for |
| 23 |
* using to query a single index tree, |
| 24 |
* the distance metric is <i>anti-reflexive</i>. |
| 25 |
* That is, if the two arguments are the same Geometry object, |
| 26 |
* the distance returned is {@link Double.MAX_VALUE}. |
| 27 |
* |
| 28 |
* @author Martin Davis |
| 29 |
* |
| 30 |
*/ |
| 31 |
public class GeometryItemDistance |
| 32 |
implements ItemDistance |
| 33 |
{ |
| 34 |
/** |
| 35 |
* Computes the distance between two {@link Geometry} items, |
| 36 |
* using the {@link Geometry#distance(Geometry)} method. |
| 37 |
* |
| 38 |
* @param item1 an item which is a Geometry |
| 39 |
* @param item2 an item which is a Geometry |
| 40 |
* @return the distance between the geometries |
| 41 |
* @throws ClassCastException if either item is not a Geometry |
| 42 |
*/ |
| 43 |
public double distance(ItemBoundable item1, ItemBoundable item2) { |
| 44 |
if (item1 == item2) return Double.MAX_VALUE; |
| 45 |
Geometry g1 = (Geometry) item1.getItem(); |
| 46 |
Geometry g2 = (Geometry) item2.getItem(); |
| 47 |
return g1.distance(g2); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
|