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 DiffGeometry {
044:
045: private FeatureCollection[] inputFC = new FeatureCollection[2];
046: private TaskMonitor monitor;
047: private DiffGeometryMatcher diffMatcher = new ExactGeometryMatcher();
048: private boolean splitIntoComponents = false;
049:
050: /*
051: private String sfeatures = I18N.get("com.vividsolutions.jump.qa.diff.DiffGeometry.features");
052: private String sMatchingfeatures = I18N.get("com.vividsolutions.jump.qa.diff.DiffGeometry.Matching-features");
053: */
054: public DiffGeometry(FeatureCollection fc0, FeatureCollection fc1,
055: TaskMonitor monitor) {
056: inputFC[0] = fc0;
057: inputFC[1] = fc1;
058: this .monitor = monitor;
059: }
060:
061: public void setNormalize(boolean normalizeGeometry) {
062: diffMatcher = new NormalizedExactGeometryMatcher();
063: }
064:
065: public void setSplitIntoComponents(boolean splitIntoComponents) {
066: this .splitIntoComponents = splitIntoComponents;
067: }
068:
069: public void setMatcher(DiffGeometryMatcher diffMatcher) {
070: this .diffMatcher = diffMatcher;
071: }
072:
073: public FeatureCollection[] diff() {
074: return compute(inputFC[0], inputFC[1]);
075: }
076:
077: /*
078: private FeatureCollection[] OLDcompute(FeatureCollection fc0, FeatureCollection fc1)
079: {
080: FeatureCollection[] diffFC = new FeatureCollection[2];
081: monitor.report("Matching features in dataset 1");
082: diffFC[0] = findUnmatchedFeatures(fc0, fc1);
083: monitor.report("Matching features in dataset 2");
084: diffFC[1] = findUnmatchedFeatures(fc1, fc0);
085: return diffFC;
086: }
087: */
088:
089: private FeatureCollection[] compute(FeatureCollection fc0,
090: FeatureCollection fc1) {
091: DiffGeometryIndex diffIndex = new DiffGeometryIndex(fc1,
092: diffMatcher, splitIntoComponents);
093:
094: monitor
095: .report(I18N
096: .get("com.vividsolutions.jump.qa.diff.DiffGeometry.Matching-features"));
097: FeatureCollection[] diffFC = new FeatureCollection[2];
098: diffFC[0] = matchFeatures(fc0, diffIndex);
099: diffFC[1] = new FeatureDataset(fc1.getFeatureSchema());
100: diffFC[1].addAll(diffIndex.getUnmatchedFeatures());
101:
102: return diffFC;
103: }
104:
105: private FeatureCollection matchFeatures(FeatureCollection fc0,
106: DiffGeometryIndex diffIndex) {
107: FeatureCollection noMatch = new FeatureDataset(fc0
108: .getFeatureSchema());
109: int count = 1;
110: int totalItems = fc0.size();
111: for (Iterator i = fc0.iterator(); i.hasNext();) {
112:
113: monitor
114: .report(
115: count++,
116: totalItems,
117: I18N
118: .get("com.vividsolutions.jump.qa.diff.DiffGeometry.features"));
119:
120: Feature f = (Feature) i.next();
121: Geometry geom = f.getGeometry();
122:
123: Collection list = DiffGeometryIndex.splitGeometry(geom,
124: splitIntoComponents);
125: for (Iterator j = list.iterator(); j.hasNext();) {
126: Geometry g = (Geometry) j.next();
127: if (!diffIndex.hasMatch(g))
128: noMatch.add(f);
129: }
130: }
131: return noMatch;
132: }
133: }
|