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.geom;
034:
035: import java.util.*;
036:
037: import com.vividsolutions.jts.geom.*;
038: import com.vividsolutions.jump.util.CoordinateArrays;
039:
040: /**
041: * Magnifies a given area of a set of Geometry's.
042: */
043: public class GeometryMicroscope {
044: private List geomList;
045: private Envelope env;
046: private double minSep;
047:
048: public GeometryMicroscope(List geomList, Envelope env, double minSep) {
049: this .geomList = geomList;
050: this .env = env;
051: this .minSep = minSep;
052: }
053:
054: public List getAdjusted() {
055: List segList = getSegList();
056: MicroscopePointAdjuster mpa = new MicroscopePointAdjuster(
057: segList, env, minSep);
058: Map ptMap = mpa.getAdjustedPointMap();
059: applyAdjustment(ptMap);
060:
061: return geomList;
062: }
063:
064: private void applyAdjustment(Map ptMap) {
065: CoordinateAdjusterFilter coordAdjFilter = new CoordinateAdjusterFilter(
066: ptMap);
067:
068: for (Iterator i = geomList.iterator(); i.hasNext();) {
069: Geometry geom = (Geometry) i.next();
070: geom.apply(coordAdjFilter);
071: }
072: }
073:
074: private List getSegList() {
075: List segList = new ArrayList();
076:
077: for (Iterator i = geomList.iterator(); i.hasNext();) {
078: Geometry geom = (Geometry) i.next();
079: List coordArrayList = CoordinateArrays.toCoordinateArrays(
080: geom, false);
081: addSegments(coordArrayList, segList);
082: }
083:
084: return segList;
085: }
086:
087: private void addSegments(List coordArrayList, List segList) {
088: LineSegmentEnvelopeIntersector linesegEnvInt = new LineSegmentEnvelopeIntersector();
089:
090: // for now just return all segs
091: // in future, only return segs which intersect env
092: for (Iterator i = coordArrayList.iterator(); i.hasNext();) {
093: Coordinate[] coord = (Coordinate[]) i.next();
094:
095: for (int j = 0; j < (coord.length - 1); j++) {
096: LineSegment seg = new LineSegment(coord[j],
097: coord[j + 1]);
098:
099: if (linesegEnvInt.touches(seg, env)) {
100: segList.add(seg);
101: }
102: }
103: }
104: }
105:
106: public class CoordinateAdjusterFilter implements CoordinateFilter {
107: Map ptMap;
108:
109: CoordinateAdjusterFilter(Map ptMap) {
110: this .ptMap = ptMap;
111: }
112:
113: public void filter(Coordinate p) {
114: Coordinate adj = (Coordinate) ptMap.get(p);
115:
116: if (adj != null) {
117: p.x = adj.x;
118: p.y = adj.y;
119: }
120: }
121: }
122: }
|