svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.impl / src / main / java / org / gvsig / fmap / geom / aggregate / impl / MultiPoint2D.java @ 40435
History | View | Annotate | Download (7.63 KB)
1 | 40435 | jjdelcerro | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package org.gvsig.fmap.geom.aggregate.impl; |
||
42 | |||
43 | import java.awt.Rectangle; |
||
44 | import java.awt.geom.AffineTransform; |
||
45 | import java.awt.geom.Rectangle2D; |
||
46 | import java.util.ArrayList; |
||
47 | |||
48 | import org.cresques.cts.IProjection; |
||
49 | import org.gvsig.fmap.geom.Geometry; |
||
50 | import org.gvsig.fmap.geom.aggregate.MultiPoint; |
||
51 | import org.gvsig.fmap.geom.handler.AbstractHandler; |
||
52 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
53 | import org.gvsig.fmap.geom.primitive.FShape; |
||
54 | import org.gvsig.fmap.geom.primitive.Point; |
||
55 | import org.gvsig.fmap.geom.primitive.impl.Envelope2D; |
||
56 | import org.gvsig.fmap.geom.primitive.impl.Point2D; |
||
57 | import org.gvsig.fmap.geom.type.GeometryType; |
||
58 | |||
59 | /**
|
||
60 | * Multipunto 2D.
|
||
61 | *
|
||
62 | * @author Vicente Caballero Navarro
|
||
63 | */
|
||
64 | public class MultiPoint2D extends BaseMultiPrimitive implements MultiPoint { |
||
65 | |||
66 | /**
|
||
67 | * The constructor with the GeometryType like and argument
|
||
68 | * is used by the {@link GeometryType}{@link #create()}
|
||
69 | * to create the geometry
|
||
70 | * @param type
|
||
71 | * The geometry type
|
||
72 | */
|
||
73 | public MultiPoint2D(GeometryType geometryType) {
|
||
74 | super(geometryType);
|
||
75 | } |
||
76 | |||
77 | /**
|
||
78 | *
|
||
79 | * @param geometryType
|
||
80 | * @param id
|
||
81 | * @param projection
|
||
82 | */
|
||
83 | MultiPoint2D(GeometryType geometryType, String id, IProjection projection) {
|
||
84 | super(geometryType, id, projection);
|
||
85 | } |
||
86 | |||
87 | /**
|
||
88 | *
|
||
89 | * @param geometryType
|
||
90 | * @param id
|
||
91 | * @param projection
|
||
92 | * @param points
|
||
93 | */
|
||
94 | public MultiPoint2D(GeometryType geometryType, String id, IProjection projection, Point2D[] points) { |
||
95 | super(geometryType, id, projection, points);
|
||
96 | } |
||
97 | |||
98 | |||
99 | |||
100 | /**
|
||
101 | *
|
||
102 | * @param id
|
||
103 | * @param projection
|
||
104 | * @param x
|
||
105 | * @param y
|
||
106 | */
|
||
107 | MultiPoint2D(GeometryType geometryType, String id, IProjection projection, double[] x, |
||
108 | double[] y) { |
||
109 | super(geometryType, id, projection);
|
||
110 | geometries = new ArrayList(); |
||
111 | for (int i = 0; i < x.length; i++) { |
||
112 | geometries.add(new Point2D(x[i], y[i])); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | /*
|
||
117 | * (non-Javadoc)
|
||
118 | *
|
||
119 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
||
120 | */
|
||
121 | public Geometry cloneGeometry() {
|
||
122 | MultiPoint auxPoint = new MultiPoint2D(geometryType, id, projection);
|
||
123 | for (int i = 0; i < getPrimitivesNumber(); i++) { |
||
124 | auxPoint.addPoint((Point)((Point) geometries.get(i)).cloneGeometry()); |
||
125 | } |
||
126 | return auxPoint;
|
||
127 | } |
||
128 | |||
129 | /*
|
||
130 | * (non-Javadoc)
|
||
131 | *
|
||
132 | * @see com.iver.cit.gvsig.fmap.core.FGeometryCollection#getBounds()
|
||
133 | */
|
||
134 | public Rectangle getBounds() { |
||
135 | Rectangle r = null; |
||
136 | if (getNumgeometries() > 0) { |
||
137 | r = ((Point)geometries.get(0)).getShape().getBounds(); |
||
138 | } |
||
139 | |||
140 | Rectangle2D r2d = new Rectangle2D.Double( |
||
141 | r.x, |
||
142 | r.y, |
||
143 | r.width, |
||
144 | r.height); |
||
145 | |||
146 | for (int i = 1; i < getNumgeometries(); i++) { |
||
147 | java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
||
148 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
149 | r2d.add(p.getX(), p.getY()); |
||
150 | } |
||
151 | |||
152 | Rectangle resp = new Rectangle( |
||
153 | Math.round((float) r2d.getMinX()), |
||
154 | Math.round((float) r2d.getMinY()), |
||
155 | Math.max(1, Math.round((float) r2d.getWidth())), |
||
156 | Math.max(1, Math.round((float) r2d.getHeight()))); |
||
157 | // w,h >= 1
|
||
158 | |||
159 | return resp;
|
||
160 | } |
||
161 | |||
162 | /*
|
||
163 | * (non-Javadoc)
|
||
164 | *
|
||
165 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
||
166 | */
|
||
167 | public Rectangle2D getBounds2D() { |
||
168 | Rectangle2D r = null; |
||
169 | if (getNumgeometries() > 0) { |
||
170 | java.awt.geom.Point2D p = ((Point)geometries.get(0)) |
||
171 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
172 | |||
173 | r = new Rectangle2D.Double(p.getX(), p.getY(), 0.001, 0.001); |
||
174 | } |
||
175 | for (int i = 1; i < getNumgeometries(); i++) { |
||
176 | java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
||
177 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
178 | r.add(p.getX(), p.getY()); |
||
179 | } |
||
180 | return r;
|
||
181 | } |
||
182 | |||
183 | /*
|
||
184 | * (non-Javadoc)
|
||
185 | *
|
||
186 | * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
||
187 | */
|
||
188 | public FShape cloneFShape() {
|
||
189 | Point2D[] aux = new Point2D[getNumgeometries()]; |
||
190 | for (int i = 0; i < getNumgeometries(); i++) { |
||
191 | aux[i] = (Point2D) ((Point)geometries.get(i)).cloneGeometry().getInternalShape(); |
||
192 | } |
||
193 | return (FShape) new MultiPoint2D(getGeometryType(), id, projection, aux); |
||
194 | } |
||
195 | |||
196 | /**
|
||
197 | * @return the numbre of points
|
||
198 | * @deprecated use getPrimitivesNumber
|
||
199 | */
|
||
200 | public int getNumgeometries() { |
||
201 | return getPrimitivesNumber();
|
||
202 | } |
||
203 | |||
204 | /**
|
||
205 | * @return the numbre of points
|
||
206 | * @deprecated use getPrimitivesNumber
|
||
207 | */
|
||
208 | public int getNumPoints() { |
||
209 | return getPrimitivesNumber();
|
||
210 | } |
||
211 | |||
212 | public Point2D getPoint(int i) { |
||
213 | return (Point2D) ((Point)geometries.get(i)).getInternalShape(); |
||
214 | } |
||
215 | |||
216 | /**
|
||
217 | * DOCUMENT ME!
|
||
218 | *
|
||
219 | * @author Vicente Caballero Navarro
|
||
220 | */
|
||
221 | class PointHandler extends AbstractHandler { |
||
222 | /**
|
||
223 | * Crea un nuevo PointHandler.
|
||
224 | *
|
||
225 | * @param x
|
||
226 | * DOCUMENT ME!
|
||
227 | * @param y
|
||
228 | * DOCUMENT ME!
|
||
229 | */
|
||
230 | public PointHandler(int i, Point2D p) { |
||
231 | point = new java.awt.geom.Point2D.Double(p.getX(), p.getY());
|
||
232 | index = i; |
||
233 | } |
||
234 | |||
235 | /**
|
||
236 | * DOCUMENT ME!
|
||
237 | *
|
||
238 | * @param x
|
||
239 | * DOCUMENT ME!
|
||
240 | * @param y
|
||
241 | * DOCUMENT ME!
|
||
242 | *
|
||
243 | * @return DOCUMENT ME!
|
||
244 | */
|
||
245 | public void move(double x, double y) { |
||
246 | java.awt.geom.Point2D p = ((Point)geometries.get(index))
|
||
247 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
248 | |||
249 | point.setLocation(p.getX() + x, p.getY() + y); |
||
250 | } |
||
251 | |||
252 | /**
|
||
253 | * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
||
254 | */
|
||
255 | public void set(double x, double y) { |
||
256 | point.setLocation(x, y); |
||
257 | } |
||
258 | |||
259 | } |
||
260 | |||
261 | public void transform(AffineTransform at) { |
||
262 | for (int i = 0; i < getNumgeometries(); i++) { |
||
263 | ((Point)geometries.get(i)).transform(at);
|
||
264 | } |
||
265 | |||
266 | } |
||
267 | |||
268 | public Envelope getEnvelope() {
|
||
269 | Envelope r = null;
|
||
270 | if (getNumgeometries() > 0) { |
||
271 | java.awt.geom.Point2D p = ((Point)geometries.get(0)) |
||
272 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
273 | |||
274 | r = new Envelope2D(p.getX(), p.getY(), p.getX()+0.001, p.getY()+0.001); |
||
275 | } |
||
276 | for (int i = 1; i < getNumgeometries(); i++) { |
||
277 | java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
||
278 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
279 | r.add(new Envelope2D(p.getX(), p.getY(),p.getX()+0.001, p.getY()+0.001)); |
||
280 | } |
||
281 | return r;
|
||
282 | } |
||
283 | |||
284 | /* (non-Javadoc)
|
||
285 | * @see org.gvsig.fmap.geom.aggregate.MultiPoint#addPoint(org.gvsig.fmap.geom.primitive.Point)
|
||
286 | */
|
||
287 | public void addPoint(Point point) { |
||
288 | addPrimitive(point); |
||
289 | } |
||
290 | |||
291 | /* (non-Javadoc)
|
||
292 | * @see org.gvsig.fmap.geom.aggregate.MultiPoint#setPoints(double[], double[])
|
||
293 | */
|
||
294 | public void setPoints(double[] x, double[] y) { |
||
295 | geometries = new ArrayList(); |
||
296 | for (int i = 0; i < x.length; i++) { |
||
297 | geometries.add(new Point2D(x[i], y[i])); |
||
298 | } |
||
299 | } |
||
300 | |||
301 | /* (non-Javadoc)
|
||
302 | * @see org.gvsig.fmap.geom.aggregate.MultiPoint#getPointAt(int)
|
||
303 | */
|
||
304 | public Point getPointAt(int index) { |
||
305 | return (Point)getPrimitiveAt(index) ; |
||
306 | } |
||
307 | } |