1 |
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * The JCS Conflation Suite (JCS) is a library of Java classes that
|
---|
5 | * can be used to build automated or semi-automated conflation solutions.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2003 Vivid Solutions
|
---|
8 | *
|
---|
9 | * This program is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU General Public License
|
---|
11 | * as published by the Free Software Foundation; either version 2
|
---|
12 | * of the License, or (at your option) any later version.
|
---|
13 | *
|
---|
14 | * This program is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with this program; if not, write to the Free Software
|
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
22 | *
|
---|
23 | * For more information, contact:
|
---|
24 | *
|
---|
25 | * Vivid Solutions
|
---|
26 | * Suite #1A
|
---|
27 | * 2328 Government Street
|
---|
28 | * Victoria BC V8T 5G5
|
---|
29 | * Canada
|
---|
30 | *
|
---|
31 | * (250)385-6040
|
---|
32 | * www.vividsolutions.com
|
---|
33 | */
|
---|
34 |
|
---|
35 | package com.vividsolutions.jcs.conflate.polygonmatch;
|
---|
36 |
|
---|
37 | import com.vividsolutions.jts.geom.Geometry;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Uses symmetric difference as the criterion for determining match scores.
|
---|
41 | */
|
---|
42 | public class SymDiffMatcher extends IndependentCandidateMatcher {
|
---|
43 |
|
---|
44 | public SymDiffMatcher() {
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * The score is a linear function of the symmetric difference: 1 if the shapes perfectly
|
---|
49 | * overlap; 0 if the shapes do not overlap at all.
|
---|
50 | * @param target the feature to match
|
---|
51 | * @param candidate the feature to compare with the target
|
---|
52 | * @return candidates with a score greater than 0 (typically all the candidates).
|
---|
53 | */
|
---|
54 | public double match(Geometry target, Geometry candidate) {
|
---|
55 | Geometry targetGeom = (Geometry) target.clone();
|
---|
56 | Geometry candidateGeom = (Geometry) candidate.clone();
|
---|
57 | if (targetGeom.isEmpty() || candidateGeom.isEmpty()) {
|
---|
58 | return 0; //avoid div by 0 in centre-of-mass calc [Jon Aquino]
|
---|
59 | }
|
---|
60 | return MatcherUtil.toScoreFromSymDiffArea(
|
---|
61 | targetGeom.getArea(), candidateGeom.getArea(),
|
---|
62 | targetGeom.symDifference(candidateGeom).getArea());
|
---|
63 | }
|
---|
64 | }
|
---|