svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / aggregate / AbstractMultiLine.java @ 42281
History | View | Annotate | Download (6.41 KB)
1 | 42267 | fdiaz | /* gvSIG. Desktop Geographic Information System.
|
---|---|---|---|
2 | *
|
||
3 | * Copyright ? 2007-2015 gvSIG Association
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
18 | * MA 02110-1301, USA.
|
||
19 | *
|
||
20 | * For any additional information, do not hesitate to contact us
|
||
21 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
22 | */
|
||
23 | package org.gvsig.fmap.geom.jts.aggregate; |
||
24 | |||
25 | 42278 | fdiaz | import java.awt.Shape; |
26 | 42274 | fdiaz | import java.awt.geom.AffineTransform; |
27 | import java.awt.geom.PathIterator; |
||
28 | import java.util.ArrayList; |
||
29 | import java.util.Iterator; |
||
30 | import java.util.List; |
||
31 | |||
32 | import com.vividsolutions.jts.geom.LineString; |
||
33 | |||
34 | 42267 | fdiaz | import org.gvsig.fmap.geom.aggregate.MultiLine; |
35 | 42274 | fdiaz | import org.gvsig.fmap.geom.jts.GeometryJTS; |
36 | 42277 | fdiaz | import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
37 | 42274 | fdiaz | import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator; |
38 | import org.gvsig.fmap.geom.jts.util.JTSUtils; |
||
39 | 42281 | fdiaz | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
40 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
41 | 42274 | fdiaz | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
42 | import org.gvsig.fmap.geom.primitive.Primitive; |
||
43 | 42267 | fdiaz | |
44 | |||
45 | /**
|
||
46 | * @author fdiaz
|
||
47 | *
|
||
48 | */
|
||
49 | public abstract class AbstractMultiLine extends AbstractMultiCurve implements MultiLine { |
||
50 | |||
51 | /**
|
||
52 | *
|
||
53 | */
|
||
54 | private static final long serialVersionUID = 3585059833766514177L; |
||
55 | |||
56 | /**
|
||
57 | * @param type
|
||
58 | */
|
||
59 | public AbstractMultiLine(int subtype) { |
||
60 | super(subtype);
|
||
61 | } |
||
62 | |||
63 | 42274 | fdiaz | |
64 | /* (non-Javadoc)
|
||
65 | * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
||
66 | */
|
||
67 | public com.vividsolutions.jts.geom.Geometry getJTS() {
|
||
68 | List<LineString> lineStrings = new ArrayList<LineString>(primitives.size()); |
||
69 | LineString lineString = null;
|
||
70 | for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
||
71 | Primitive primitive = (Primitive) iterator.next(); |
||
72 | lineString = (LineString) ((GeometryJTS)primitive).getJTS(); |
||
73 | } |
||
74 | return JTSUtils.createJTSMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()])); |
||
75 | } |
||
76 | |||
77 | /* (non-Javadoc)
|
||
78 | * @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform)
|
||
79 | */
|
||
80 | public PathIterator getPathIterator(AffineTransform at) { |
||
81 | 42277 | fdiaz | MultiLineIterator pi = new MultiLineIterator(at);
|
82 | return pi;
|
||
83 | 42274 | fdiaz | } |
84 | |||
85 | /* (non-Javadoc)
|
||
86 | * @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double)
|
||
87 | */
|
||
88 | public PathIterator getPathIterator(AffineTransform at, double flatness) { |
||
89 | 42275 | fdiaz | return getPathIterator(at);
|
90 | 42274 | fdiaz | } |
91 | |||
92 | /* (non-Javadoc)
|
||
93 | * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
||
94 | */
|
||
95 | public GeneralPathX getGeneralPath() {
|
||
96 | 42277 | fdiaz | return new DefaultGeneralPathX(getPathIterator(null), false, 0); |
97 | 42274 | fdiaz | } |
98 | |||
99 | 42277 | fdiaz | protected class MultiLineIterator extends GeneralPathXIterator { |
100 | |||
101 | /** Transform applied on the coordinates during iteration */
|
||
102 | private AffineTransform at; |
||
103 | |||
104 | /** True when the point has been read once */
|
||
105 | private boolean done; |
||
106 | private int index = 0; |
||
107 | private List<PathIterator>iterators = new ArrayList<PathIterator>(primitives.size()); |
||
108 | |||
109 | /**
|
||
110 | * Creates a new PointIterator object.
|
||
111 | *
|
||
112 | * @param p
|
||
113 | * The polygon
|
||
114 | * @param at
|
||
115 | * The affine transform applied to coordinates during
|
||
116 | * iteration
|
||
117 | */
|
||
118 | public MultiLineIterator(AffineTransform at) { |
||
119 | super(new GeneralPathX()); |
||
120 | if (at == null) { |
||
121 | at = new AffineTransform(); |
||
122 | } |
||
123 | |||
124 | this.at = at;
|
||
125 | for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
||
126 | Primitive primitive = (Primitive) iterator.next(); |
||
127 | iterators.add(primitive.getPathIterator(at)); |
||
128 | } |
||
129 | done = false;
|
||
130 | } |
||
131 | |||
132 | /**
|
||
133 | * Return the winding rule for determining the interior of the path.
|
||
134 | *
|
||
135 | * @return <code>WIND_EVEN_ODD</code> by default.
|
||
136 | */
|
||
137 | public int getWindingRule() { |
||
138 | return PathIterator.WIND_EVEN_ODD; |
||
139 | } |
||
140 | |||
141 | /**
|
||
142 | * @see java.awt.geom.PathIterator#next()
|
||
143 | */
|
||
144 | public void next() { |
||
145 | PathIterator pathIteratorPrimitive = iterators.get(index);
|
||
146 | pathIteratorPrimitive.next(); |
||
147 | if(pathIteratorPrimitive.isDone()){
|
||
148 | index++; |
||
149 | done = (index==primitives.size()); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | /**
|
||
154 | * @see java.awt.geom.PathIterator#isDone()
|
||
155 | */
|
||
156 | public boolean isDone() { |
||
157 | return done;
|
||
158 | } |
||
159 | |||
160 | /**
|
||
161 | * @see java.awt.geom.PathIterator#currentSegment(double[])
|
||
162 | */
|
||
163 | public int currentSegment(double[] coords) { |
||
164 | return iterators.get(index).currentSegment(coords);
|
||
165 | } |
||
166 | |||
167 | /*
|
||
168 | * (non-Javadoc)
|
||
169 | *
|
||
170 | * @see java.awt.geom.PathIterator#currentSegment(float[])
|
||
171 | */
|
||
172 | public int currentSegment(float[] coords) { |
||
173 | return iterators.get(index).currentSegment(coords);
|
||
174 | } |
||
175 | } |
||
176 | |||
177 | |||
178 | 42278 | fdiaz | /*
|
179 | * (non-Javadoc)
|
||
180 | *
|
||
181 | * @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
||
182 | */
|
||
183 | public Shape getShape(AffineTransform affineTransform) { |
||
184 | return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
||
185 | } |
||
186 | |||
187 | /*
|
||
188 | * (non-Javadoc)
|
||
189 | *
|
||
190 | * @see org.gvsig.fmap.geom.Geometry#getShape()
|
||
191 | */
|
||
192 | public Shape getShape() { |
||
193 | return new DefaultGeneralPathX(getPathIterator(null),false,0); |
||
194 | } |
||
195 | |||
196 | 42281 | fdiaz | /* (non-Javadoc)
|
197 | * @see org.gvsig.fmap.geom.jts.GeometryJTS#flip()
|
||
198 | */
|
||
199 | public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
200 | for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
||
201 | ((GeometryJTS)iterator.next()).flip(); |
||
202 | } |
||
203 | } |
||
204 | 42267 | fdiaz | } |