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: package com.vividsolutions.jump.plugin.edit;
033:
034: import java.util.*;
035: import com.vividsolutions.jump.feature.*;
036: import com.vividsolutions.jump.geom.*;
037: import com.vividsolutions.jts.geom.*;
038: import com.vividsolutions.jts.geom.LineSegment;
039: import com.vividsolutions.jump.util.CoordinateArrays;
040: import com.vividsolutions.jump.task.*;
041:
042: /**
043: * Extracts the unique segments from a FeatureCollection.
044: *
045: * This class has been replaced by SegmentExtracter, which is able to return segments
046: * occuring between minOccur and maxOccur times in the dataset [Michael Michaud 2007-05-15]
047: *
048: * @author Martin Davis
049: * @version 1.0
050: */
051: public class UniqueSegmentsExtracter {
052: private static final GeometryFactory factory = new GeometryFactory();
053:
054: private Set segmentSet = new TreeSet();
055: private LineSegment querySegment = new LineSegment();
056: private boolean countZeroLengthSegments = true;
057: private TaskMonitor monitor;
058: private Geometry fence = null;
059:
060: // private LineSegmentEnvelopeIntersector lineEnvInt;
061:
062: public UniqueSegmentsExtracter() {
063: }
064:
065: /**
066: * Creates a new counter.
067: *
068: * @param monitor
069: */
070: public UniqueSegmentsExtracter(TaskMonitor monitor) {
071: this .monitor = monitor;
072: }
073:
074: /*
075: public void setFence(Geometry fence)
076: {
077: this.fence = fence;
078: //lineEnvInt = new LineSegmentEnvelopeIntersector();
079: }
080: */
081:
082: public void add(FeatureCollection fc) {
083: monitor.allowCancellationRequests();
084: int totalFeatures = fc.size();
085: int j = 0;
086: for (Iterator i = fc.iterator(); i.hasNext()
087: && !monitor.isCancelRequested();) {
088: Feature feature = (Feature) i.next();
089: j++;
090: monitor.report(j, totalFeatures, "features");
091: add(feature);
092: }
093: }
094:
095: public void add(Feature f) {
096: Geometry g = f.getGeometry();
097: // skip if using fence and feature is not in fence
098: if (fence != null && !g.intersects(fence))
099: return;
100:
101: List coordArrays = CoordinateArrays.toCoordinateArrays(g, true);
102: for (Iterator i = coordArrays.iterator(); i.hasNext();) {
103: Coordinate[] coord = (Coordinate[]) i.next();
104: for (int j = 0; j < coord.length - 1; j++) {
105: // skip if using fence AND seg is not in fence
106: /*
107: if (fence != null) {
108: LineString segLine = factory.createLineString(new Coordinate[] { coord[j], coord[j + 1] });
109: if (! fence.intersects(segLine))
110: continue;
111: }
112: */
113: add(coord[j], coord[j + 1]);
114: }
115: }
116: }
117:
118: public void add(Coordinate p0, Coordinate p1) {
119: // check for zero-length segment
120: boolean isZeroLength = p0.equals(p1);
121: if (!countZeroLengthSegments && isZeroLength)
122: return;
123:
124: LineSegment lineseg = new LineSegment(p0, p1);
125: lineseg.normalize();
126:
127: segmentSet.add(lineseg);
128: }
129:
130: public Collection getSegments() {
131: return segmentSet;
132: }
133:
134: }
|