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.jump.feature.*;
037: import com.vividsolutions.jts.geom.Geometry;
038:
039: public class MatchCollection {
040:
041: private FeatureCollection inputFC;
042: private Collection matchFeatures = new ArrayList();
043: private Collection matchGeometries = new ArrayList();
044:
045: public MatchCollection(FeatureCollection fc,
046: boolean splitIntoComponents) {
047: this .inputFC = fc;
048: init(fc, splitIntoComponents);
049: }
050:
051: private void init(FeatureCollection fc, boolean splitIntoComponents) {
052: for (Iterator i = fc.iterator(); i.hasNext();) {
053: Feature feat = (Feature) i.next();
054: MatchFeature matchFeat = new MatchFeature(feat);
055: matchFeatures.add(matchFeat);
056: Geometry geom = feat.getGeometry();
057: Collection list = MatchGeometry.splitGeometry(geom,
058: splitIntoComponents);
059: for (Iterator j = list.iterator(); j.hasNext();) {
060: Geometry g = (Geometry) j.next();
061: MatchGeometry matchGeom = new MatchGeometry(matchFeat,
062: g);
063: matchGeometries.add(matchGeom);
064: }
065: }
066: }
067:
068: public Iterator geometryIterator() {
069: return matchGeometries.iterator();
070: }
071:
072: /**
073: * An iterator over all MatchFeatures in the collection.
074: */
075: public Iterator iterator() {
076: return matchFeatures.iterator();
077: }
078:
079: public int size() {
080: return matchFeatures.size();
081: }
082:
083: public int geometrySize() {
084: return matchGeometries.size();
085: }
086:
087: /**
088: * Updates the match flag for features based on the matches
089: */
090: public void computeFeatureMatches() {
091: // set all feature matches to true
092: for (Iterator i = matchFeatures.iterator(); i.hasNext();) {
093: MatchFeature mf = (MatchFeature) i.next();
094: mf.setMatched(true);
095: }
096: // clear feature matches if any feature geometry is unmatched
097: for (Iterator j = matchGeometries.iterator(); j.hasNext();) {
098: MatchGeometry mg = (MatchGeometry) j.next();
099: if (!mg.isMatched())
100: mg.getFeature().setMatched(false);
101: }
102: }
103:
104: /**
105: * Ensures that if a feature is unmatched,
106: * any features matched to its geometries are also unmatched
107: */
108: public void propagateUnmatchedFeatures() {
109: for (Iterator j = matchGeometries.iterator(); j.hasNext();) {
110: MatchGeometry mg = (MatchGeometry) j.next();
111: if (!mg.getFeature().isMatched()) {
112: MatchGeometry mgOpposite = mg.getMatch();
113: if (mgOpposite != null)
114: mgOpposite.getFeature().setMatched(false);
115: }
116: }
117: }
118:
119: public FeatureCollection getUnmatchedFeatures() {
120: FeatureCollection noMatch = new FeatureDataset(inputFC
121: .getFeatureSchema());
122: for (Iterator i = matchFeatures.iterator(); i.hasNext();) {
123: MatchFeature mf = (MatchFeature) i.next();
124: if (!mf.isMatched())
125: noMatch.add(mf.getFeature());
126: }
127: return noMatch;
128: }
129: }
|