svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / aggregate / impl / MultiPoint2D.java @ 29097
History | View | Annotate | Download (7.29 KB)
1 |
/* 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)).getBounds(); |
138 |
} |
139 |
for (int i = 1; i < getNumgeometries(); i++) { |
140 |
java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
141 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
142 |
r.add(p.getX(), p.getY()); |
143 |
} |
144 |
return r;
|
145 |
} |
146 |
|
147 |
/*
|
148 |
* (non-Javadoc)
|
149 |
*
|
150 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
151 |
*/
|
152 |
public Rectangle2D getBounds2D() { |
153 |
Rectangle2D r = null; |
154 |
if (getNumgeometries() > 0) { |
155 |
java.awt.geom.Point2D p = ((Point)geometries.get(0)) |
156 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
157 |
|
158 |
r = new Rectangle2D.Double(p.getX(), p.getY(), 0.001, 0.001); |
159 |
} |
160 |
for (int i = 1; i < getNumgeometries(); i++) { |
161 |
java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
162 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
163 |
r.add(p.getX(), p.getY()); |
164 |
} |
165 |
return r;
|
166 |
} |
167 |
|
168 |
/*
|
169 |
* (non-Javadoc)
|
170 |
*
|
171 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
172 |
*/
|
173 |
public FShape cloneFShape() {
|
174 |
Point2D[] aux = new Point2D[getNumgeometries()]; |
175 |
for (int i = 0; i < getNumgeometries(); i++) { |
176 |
aux[i] = (Point2D) ((Point)geometries.get(i)).cloneGeometry().getInternalShape(); |
177 |
} |
178 |
return (FShape) new MultiPoint2D(getGeometryType(), id, projection, aux); |
179 |
} |
180 |
|
181 |
/**
|
182 |
* @return the numbre of points
|
183 |
* @deprecated use getPrimitivesNumber
|
184 |
*/
|
185 |
public int getNumgeometries() { |
186 |
return getPrimitivesNumber();
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* @return the numbre of points
|
191 |
* @deprecated use getPrimitivesNumber
|
192 |
*/
|
193 |
public int getNumPoints() { |
194 |
return getPrimitivesNumber();
|
195 |
} |
196 |
|
197 |
public Point2D getPoint(int i) { |
198 |
return (Point2D) ((Point)geometries.get(i)).getInternalShape(); |
199 |
} |
200 |
|
201 |
/**
|
202 |
* DOCUMENT ME!
|
203 |
*
|
204 |
* @author Vicente Caballero Navarro
|
205 |
*/
|
206 |
class PointHandler extends AbstractHandler { |
207 |
/**
|
208 |
* Crea un nuevo PointHandler.
|
209 |
*
|
210 |
* @param x
|
211 |
* DOCUMENT ME!
|
212 |
* @param y
|
213 |
* DOCUMENT ME!
|
214 |
*/
|
215 |
public PointHandler(int i, Point2D p) { |
216 |
point = new java.awt.geom.Point2D.Double(p.getX(), p.getY());
|
217 |
index = i; |
218 |
} |
219 |
|
220 |
/**
|
221 |
* DOCUMENT ME!
|
222 |
*
|
223 |
* @param x
|
224 |
* DOCUMENT ME!
|
225 |
* @param y
|
226 |
* DOCUMENT ME!
|
227 |
*
|
228 |
* @return DOCUMENT ME!
|
229 |
*/
|
230 |
public void move(double x, double y) { |
231 |
java.awt.geom.Point2D p = ((Point)geometries.get(index))
|
232 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
233 |
|
234 |
point.setLocation(p.getX() + x, p.getY() + y); |
235 |
} |
236 |
|
237 |
/**
|
238 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
239 |
*/
|
240 |
public void set(double x, double y) { |
241 |
point.setLocation(x, y); |
242 |
} |
243 |
|
244 |
} |
245 |
|
246 |
public void transform(AffineTransform at) { |
247 |
for (int i = 0; i < getNumgeometries(); i++) { |
248 |
((Point)geometries.get(i)).transform(at);
|
249 |
} |
250 |
|
251 |
} |
252 |
|
253 |
public Envelope getEnvelope() {
|
254 |
Envelope r = null;
|
255 |
if (getNumgeometries() > 0) { |
256 |
java.awt.geom.Point2D p = ((Point)geometries.get(0)) |
257 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
258 |
|
259 |
r = new Envelope2D(p.getX(), p.getY(), p.getX()+0.001, p.getY()+0.001); |
260 |
} |
261 |
for (int i = 1; i < getNumgeometries(); i++) { |
262 |
java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
263 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
264 |
r.add(new Envelope2D(p.getX(), p.getY(),p.getX()+0.001, p.getY()+0.001)); |
265 |
} |
266 |
return r;
|
267 |
} |
268 |
|
269 |
/* (non-Javadoc)
|
270 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#addPoint(org.gvsig.fmap.geom.primitive.Point)
|
271 |
*/
|
272 |
public void addPoint(Point point) { |
273 |
addPrimitive(point); |
274 |
} |
275 |
|
276 |
/* (non-Javadoc)
|
277 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#setPoints(double[], double[])
|
278 |
*/
|
279 |
public void setPoints(double[] x, double[] y) { |
280 |
geometries = new ArrayList(); |
281 |
for (int i = 0; i < x.length; i++) { |
282 |
geometries.add(new Point2D(x[i], y[i])); |
283 |
} |
284 |
} |
285 |
|
286 |
/* (non-Javadoc)
|
287 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#getPointAt(int)
|
288 |
*/
|
289 |
public Point getPointAt(int index) { |
290 |
return (Point)getPrimitiveAt(index) ; |
291 |
} |
292 |
} |