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 / AbstractMultiPoint.java @ 42267
History | View | Annotate | Download (6.71 KB)
1 |
/* 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 |
import java.awt.Shape; |
26 |
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 org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
34 |
import org.gvsig.fmap.geom.handler.Handler; |
35 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
36 |
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator; |
37 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
38 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
39 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
40 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
41 |
import org.gvsig.fmap.geom.primitive.Point; |
42 |
import org.gvsig.fmap.geom.primitive.Primitive; |
43 |
|
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public abstract class AbstractMultiPoint extends AbstractMultiPrimitive implements MultiPoint { |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = 7056816718895043774L; |
55 |
|
56 |
/**
|
57 |
* @param type
|
58 |
* @param subtype
|
59 |
*/
|
60 |
public AbstractMultiPoint(int subtype) { |
61 |
super(Geometry.TYPES.MULTIPOINT, subtype);
|
62 |
} |
63 |
|
64 |
|
65 |
/* (non-Javadoc)
|
66 |
* @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
|
67 |
*/
|
68 |
public Handler[] getHandlers(int type) { |
69 |
List<Handler> handlers = new ArrayList<Handler>(); |
70 |
for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
71 |
Primitive primitive = (Primitive) iterator.next(); |
72 |
Handler[] primitiveHandlers = primitive.getHandlers(type); |
73 |
for (int i = 0; i < primitiveHandlers.length; i++) { |
74 |
handlers.add(primitiveHandlers[i]); |
75 |
} |
76 |
} |
77 |
return handlers.toArray(new Handler[handlers.size()]); |
78 |
} |
79 |
|
80 |
/* (non-Javadoc)
|
81 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
82 |
*/
|
83 |
public com.vividsolutions.jts.geom.Geometry getJTS() {
|
84 |
ArrayListCoordinateSequence coordinateSequence = new ArrayListCoordinateSequence();
|
85 |
for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
86 |
PointJTS point = (PointJTS) iterator.next(); |
87 |
coordinateSequence.add(point.getJTSCoordinate()); |
88 |
} |
89 |
return JTSUtils.createJTSMultiPoint(coordinateSequence);
|
90 |
} |
91 |
|
92 |
/* (non-Javadoc)
|
93 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#addPoint(org.gvsig.fmap.geom.primitive.Point)
|
94 |
*/
|
95 |
public void addPoint(Point point) { |
96 |
primitives.add(point); |
97 |
} |
98 |
|
99 |
/* (non-Javadoc)
|
100 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#getPointAt(int)
|
101 |
*/
|
102 |
public Point getPointAt(int index) { |
103 |
return (Point)primitives.get(index); |
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
*
|
109 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
110 |
*/
|
111 |
public Shape getShape(AffineTransform affineTransform) { |
112 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
113 |
} |
114 |
|
115 |
/*
|
116 |
* (non-Javadoc)
|
117 |
*
|
118 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
119 |
*/
|
120 |
public Shape getShape() { |
121 |
return new DefaultGeneralPathX(getPathIterator(null),false,0); |
122 |
} |
123 |
|
124 |
/*
|
125 |
* (non-Javadoc)
|
126 |
*
|
127 |
* @see
|
128 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
129 |
* )
|
130 |
*/
|
131 |
public PathIterator getPathIterator(AffineTransform at) { |
132 |
PointIterator pi = new PointIterator(at);
|
133 |
return pi;
|
134 |
} |
135 |
|
136 |
/*
|
137 |
* (non-Javadoc)
|
138 |
*
|
139 |
* @see
|
140 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
141 |
* , double)
|
142 |
*/
|
143 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
144 |
return getPathIterator(at);
|
145 |
} |
146 |
|
147 |
protected class PointIterator extends GeneralPathXIterator { |
148 |
|
149 |
/** Transform applied on the coordinates during iteration */
|
150 |
private AffineTransform at; |
151 |
|
152 |
/** True when the point has been read once */
|
153 |
private boolean done; |
154 |
private int index = 0; |
155 |
|
156 |
/**
|
157 |
* Creates a new PointIterator object.
|
158 |
*
|
159 |
* @param p
|
160 |
* The polygon
|
161 |
* @param at
|
162 |
* The affine transform applied to coordinates during
|
163 |
* iteration
|
164 |
*/
|
165 |
public PointIterator(AffineTransform at) { |
166 |
super(new GeneralPathX()); |
167 |
if (at == null) { |
168 |
at = new AffineTransform(); |
169 |
} |
170 |
|
171 |
this.at = at;
|
172 |
done = false;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* Return the winding rule for determining the interior of the path.
|
177 |
*
|
178 |
* @return <code>WIND_EVEN_ODD</code> by default.
|
179 |
*/
|
180 |
public int getWindingRule() { |
181 |
return PathIterator.WIND_EVEN_ODD; |
182 |
} |
183 |
|
184 |
/**
|
185 |
* @see java.awt.geom.PathIterator#next()
|
186 |
*/
|
187 |
public void next() { |
188 |
done = (primitives.size() == index++); |
189 |
} |
190 |
|
191 |
/**
|
192 |
* @see java.awt.geom.PathIterator#isDone()
|
193 |
*/
|
194 |
public boolean isDone() { |
195 |
return done;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* @see java.awt.geom.PathIterator#currentSegment(double[])
|
200 |
*/
|
201 |
public int currentSegment(double[] coords) { |
202 |
Point point = (Point) primitives.get(index); |
203 |
coords[0] = point.getX();
|
204 |
coords[1] = point.getY();
|
205 |
at.transform(coords, 0, coords, 0, 1); |
206 |
return PathIterator.SEG_MOVETO; |
207 |
} |
208 |
|
209 |
/*
|
210 |
* (non-Javadoc)
|
211 |
*
|
212 |
* @see java.awt.geom.PathIterator#currentSegment(float[])
|
213 |
*/
|
214 |
public int currentSegment(float[] coords) { |
215 |
Point point = (Point) primitives.get(index); |
216 |
coords[0] = (float)point.getX(); |
217 |
coords[1] = (float)point.getY(); |
218 |
at.transform(coords, 0, coords, 0, 1); |
219 |
return PathIterator.SEG_MOVETO; |
220 |
} |
221 |
} |
222 |
|
223 |
} |