Class AreaSimilarityMeasure

 1 /*
 2  * Copyright (c) 2016 Vivid Solutions.
 3  *
 4  * All rights reserved. This program and the accompanying materials
 5  * are made available under the terms of the Eclipse Public License 2.0
 6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 8  * and the Eclipse Distribution License is available at
 9  *
10  * http://www.eclipse.org/org/documents/edl-v10.php.
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     public static double measure(Geometry a, Geometry b)
33     {
34         AreaSimilarityMeasure gv = new AreaSimilarityMeasure(a, b);
35         return gv.measure();
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