001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.qa.diff;
034:
035: import java.util.*;
036: import com.vividsolutions.jts.geom.*;
037: import com.vividsolutions.jump.I18N;
038: import com.vividsolutions.jump.feature.*;
039: import com.vividsolutions.jump.task.TaskMonitor;
040: import com.vividsolutions.jts.index.SpatialIndex;
041: import com.vividsolutions.jts.index.strtree.STRtree;
042:
043: public class DiffGeometryComponents {
044:
045: private FeatureCollection[] inputFC = new FeatureCollection[2];
046: private TaskMonitor monitor;
047: private DiffGeometryMatcher diffMatcher = new ExactGeometryMatcher();
048: private boolean splitIntoComponents = true;
049:
050: final static String sMatchingfeatures = I18N
051: .get("com.vividsolutions.jump.qa.diff.DiffGeometry.Matching-features");
052: final static String sGeometries = I18N
053: .get("com.vividsolutions.jump.qa.diff.DiffGeometryComponents.geometries");
054:
055: public DiffGeometryComponents(FeatureCollection fc0,
056: FeatureCollection fc1, TaskMonitor monitor) {
057: inputFC[0] = fc0;
058: inputFC[1] = fc1;
059: this .monitor = monitor;
060: }
061:
062: public void setNormalize(boolean normalizeGeometry) {
063: diffMatcher = new NormalizedExactGeometryMatcher();
064: }
065:
066: public void setSplitIntoComponents(boolean splitIntoComponents) {
067: this .splitIntoComponents = splitIntoComponents;
068: }
069:
070: public void setMatcher(DiffGeometryMatcher diffMatcher) {
071: this .diffMatcher = diffMatcher;
072: }
073:
074: public FeatureCollection[] diff() {
075: MatchCollection[] mc = {
076: new MatchCollection(inputFC[0], splitIntoComponents),
077: new MatchCollection(inputFC[1], splitIntoComponents) };
078: compute(mc[0], mc[1]);
079:
080: return new FeatureCollection[] { mc[0].getUnmatchedFeatures(),
081: mc[1].getUnmatchedFeatures() };
082:
083: }
084:
085: private void compute(MatchCollection mc0, MatchCollection mc1) {
086: MatchIndex index = new MatchIndex(mc1);
087:
088: monitor.report(sMatchingfeatures);
089: FeatureCollection[] diffFC = new FeatureCollection[2];
090: matchFeatures(mc0, index);
091:
092: // compute feature matches based on own geometries
093: mc0.computeFeatureMatches();
094: mc1.computeFeatureMatches();
095: // compute matches based on matched geometries
096: mc0.propagateUnmatchedFeatures();
097: mc1.propagateUnmatchedFeatures();
098: }
099:
100: private void matchFeatures(MatchCollection matchColl,
101: MatchIndex index) {
102: int count = 1;
103: int totalItems = matchColl.geometrySize();
104: for (Iterator i = matchColl.geometryIterator(); i.hasNext();) {
105: monitor.report(count++, totalItems, sGeometries);
106: MatchGeometry matchGeom = (MatchGeometry) i.next();
107: index.testMatch(matchGeom, diffMatcher);
108: }
109: }
110:
111: }
|