| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package org.locationtech.jts.algorithm.match; |
| 14 |
|
| 15 |
import org.locationtech.jts.geom.Geometry; |
| 16 |
|
| 17 |
/** |
| 18 |
* Measures the degree of similarity between two {@link Geometry}s |
| 19 |
* using the area of intersection between the geometries. |
| 20 |
* The measure is normalized to lie in the range [0, 1]. |
| 21 |
* Higher measures indicate a great degree of similarity. |
| 22 |
* <p> |
| 23 |
* NOTE: Currently experimental and incomplete. |
| 24 |
* |
| 25 |
* @author mbdavis |
| 26 |
* |
| 27 |
*/ |
| 28 |
public class AreaSimilarityMeasure |
| 29 |
implements SimilarityMeasure |
| 30 |
{ |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
/** |
| 40 |
* Creates a new instance. |
| 41 |
*/ |
| 42 |
public AreaSimilarityMeasure() |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
public double measure(Geometry g1, Geometry g2) |
| 47 |
{ |
| 48 |
double areaInt = g1.intersection(g2).getArea(); |
| 49 |
double areaUnion = g1.union(g2).getArea(); |
| 50 |
return areaInt / areaUnion; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
} |
| 55 |
|