svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / aggregate / MultiPoint2D.java @ 26866
History | View | Annotate | Download (7.93 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; |
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.GeometryLocator; |
51 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
52 |
import org.gvsig.fmap.geom.handler.AbstractHandler; |
53 |
import org.gvsig.fmap.geom.primitive.DefaultEnvelope; |
54 |
import org.gvsig.fmap.geom.primitive.Envelope; |
55 |
import org.gvsig.fmap.geom.primitive.FShape; |
56 |
import org.gvsig.fmap.geom.primitive.Point; |
57 |
import org.gvsig.fmap.geom.primitive.Point2D; |
58 |
import org.gvsig.fmap.geom.type.GeometryType; |
59 |
|
60 |
/**
|
61 |
* Multipunto 2D.
|
62 |
*
|
63 |
* @author Vicente Caballero Navarro
|
64 |
*/
|
65 |
public class MultiPoint2D extends BaseMultiPrimitive implements MultiPoint { |
66 |
|
67 |
private static final long serialVersionUID = 1L; |
68 |
|
69 |
private static GeometryType geomType = GeometryLocator.getGeometryManager() |
70 |
.registerGeometryType(MultiPoint2D.class, null, TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
|
71 |
public static int CODE = geomType.getId(); |
72 |
|
73 |
/**
|
74 |
* Constructor without arguments. It is necessary to create
|
75 |
* geometries using the {@link GeometryType}{@link #create()}
|
76 |
* method
|
77 |
*/
|
78 |
public MultiPoint2D() {
|
79 |
super();
|
80 |
} |
81 |
|
82 |
public MultiPoint2D(IProjection projection, Point2D[] points) { |
83 |
this(null, projection, points); |
84 |
} |
85 |
|
86 |
public MultiPoint2D(Point2D[] points) { |
87 |
this(null, null, points); |
88 |
} |
89 |
|
90 |
public MultiPoint2D(IProjection projection) {
|
91 |
this(null, projection, null); |
92 |
} |
93 |
|
94 |
public MultiPoint2D(String id, IProjection projection, Point2D[] points) { |
95 |
super(id, projection, points);
|
96 |
} |
97 |
|
98 |
public MultiPoint2D(String id, IProjection projection) { |
99 |
this(id, projection, null); |
100 |
} |
101 |
|
102 |
public MultiPoint2D(double[] x, double[] y) { |
103 |
this(null, null, x, y); |
104 |
} |
105 |
|
106 |
/**
|
107 |
* Crea un nuevo MultiPoint2D.
|
108 |
*
|
109 |
* @param x
|
110 |
* DOCUMENT ME!
|
111 |
* @param y
|
112 |
* DOCUMENT ME!
|
113 |
*/
|
114 |
public MultiPoint2D(String id, IProjection projection, double[] x, |
115 |
double[] y) { |
116 |
super(id, projection);
|
117 |
geometries = new ArrayList(); |
118 |
for (int i = 0; i < x.length; i++) { |
119 |
geometries.add(new Point2D(id, projection, x[i], y[i])); |
120 |
} |
121 |
} |
122 |
|
123 |
/*
|
124 |
* (non-Javadoc)
|
125 |
*
|
126 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
127 |
*/
|
128 |
public Geometry cloneGeometry() {
|
129 |
MultiPoint auxPoint = new MultiPoint2D(id, projection);
|
130 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
131 |
auxPoint.addPoint((Point)((Point) geometries.get(i)).cloneGeometry()); |
132 |
} |
133 |
return auxPoint;
|
134 |
} |
135 |
|
136 |
/*
|
137 |
* (non-Javadoc)
|
138 |
*
|
139 |
* @see com.iver.cit.gvsig.fmap.core.FGeometryCollection#getBounds()
|
140 |
*/
|
141 |
public Rectangle getBounds() { |
142 |
Rectangle r = null; |
143 |
if (getNumgeometries() > 0) { |
144 |
r = ((Point)geometries.get(0)).getBounds(); |
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 |
r.add(p.getX(), p.getY()); |
150 |
} |
151 |
return r;
|
152 |
} |
153 |
|
154 |
/*
|
155 |
* (non-Javadoc)
|
156 |
*
|
157 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
158 |
*/
|
159 |
public Rectangle2D getBounds2D() { |
160 |
Rectangle2D r = null; |
161 |
if (getNumgeometries() > 0) { |
162 |
java.awt.geom.Point2D p = ((Point)geometries.get(0)) |
163 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
164 |
|
165 |
r = new Rectangle2D.Double(p.getX(), p.getY(), 0.001, 0.001); |
166 |
} |
167 |
for (int i = 1; i < getNumgeometries(); i++) { |
168 |
java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
169 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
170 |
r.add(p.getX(), p.getY()); |
171 |
} |
172 |
return r;
|
173 |
} |
174 |
|
175 |
/*
|
176 |
* (non-Javadoc)
|
177 |
*
|
178 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
179 |
*/
|
180 |
public int getShapeType() { |
181 |
return FShape.MULTIPOINT;
|
182 |
} |
183 |
|
184 |
/*
|
185 |
* (non-Javadoc)
|
186 |
*
|
187 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
188 |
*/
|
189 |
public FShape cloneFShape() {
|
190 |
Point2D[] aux = new Point2D[getNumgeometries()]; |
191 |
for (int i = 0; i < getNumgeometries(); i++) { |
192 |
aux[i] = (Point2D) ((Point)geometries.get(i)).cloneGeometry().getInternalShape(); |
193 |
} |
194 |
return (FShape) new MultiPoint2D(id, projection, aux); |
195 |
} |
196 |
|
197 |
/**
|
198 |
* @return the numbre of points
|
199 |
* @deprecated use getPrimitivesNumber
|
200 |
*/
|
201 |
public int getNumgeometries() { |
202 |
return getPrimitivesNumber();
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* @return the numbre of points
|
207 |
* @deprecated use getPrimitivesNumber
|
208 |
*/
|
209 |
public int getNumPoints() { |
210 |
return getPrimitivesNumber();
|
211 |
} |
212 |
|
213 |
public Point2D getPoint(int i) { |
214 |
return (Point2D) ((Point)geometries.get(i)).getInternalShape(); |
215 |
} |
216 |
|
217 |
/**
|
218 |
* DOCUMENT ME!
|
219 |
*
|
220 |
* @author Vicente Caballero Navarro
|
221 |
*/
|
222 |
class PointHandler extends AbstractHandler { |
223 |
/**
|
224 |
* Crea un nuevo PointHandler.
|
225 |
*
|
226 |
* @param x
|
227 |
* DOCUMENT ME!
|
228 |
* @param y
|
229 |
* DOCUMENT ME!
|
230 |
*/
|
231 |
public PointHandler(int i, Point2D p) { |
232 |
point = new java.awt.geom.Point2D.Double(p.getX(), p.getY());
|
233 |
index = i; |
234 |
} |
235 |
|
236 |
/**
|
237 |
* DOCUMENT ME!
|
238 |
*
|
239 |
* @param x
|
240 |
* DOCUMENT ME!
|
241 |
* @param y
|
242 |
* DOCUMENT ME!
|
243 |
*
|
244 |
* @return DOCUMENT ME!
|
245 |
*/
|
246 |
public void move(double x, double y) { |
247 |
java.awt.geom.Point2D p = ((Point)geometries.get(index))
|
248 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
249 |
|
250 |
point.setLocation(p.getX() + x, p.getY() + y); |
251 |
} |
252 |
|
253 |
/**
|
254 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
255 |
*/
|
256 |
public void set(double x, double y) { |
257 |
point.setLocation(x, y); |
258 |
} |
259 |
|
260 |
} |
261 |
|
262 |
public void transform(AffineTransform at) { |
263 |
for (int i = 0; i < getNumgeometries(); i++) { |
264 |
((Point)geometries.get(i)).transform(at);
|
265 |
} |
266 |
|
267 |
} |
268 |
|
269 |
public Envelope getEnvelope() {
|
270 |
Envelope r = null;
|
271 |
if (getNumgeometries() > 0) { |
272 |
java.awt.geom.Point2D p = ((Point)geometries.get(0)) |
273 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
274 |
|
275 |
r = new DefaultEnvelope(2,new double[]{p.getX(), p.getY()},new double[]{ p.getX()+0.001, p.getY()+0.001}); |
276 |
} |
277 |
for (int i = 1; i < getNumgeometries(); i++) { |
278 |
java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
279 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
280 |
r.add(new DefaultEnvelope(2,new double[]{p.getX(), p.getY()},new double[]{ p.getX()+0.001, p.getY()+0.001})); |
281 |
} |
282 |
return r;
|
283 |
} |
284 |
|
285 |
/* (non-Javadoc)
|
286 |
* @see org.gvsig.fmap.geom.primitive.AbstractPrimitive#getGeometryType()
|
287 |
*/
|
288 |
public GeometryType getGeometryType() {
|
289 |
return geomType;
|
290 |
} |
291 |
|
292 |
/* (non-Javadoc)
|
293 |
* @see org.gvsig.fmap.geom.Geometry#getType()
|
294 |
*/
|
295 |
public int getType() { |
296 |
return geomType.getType();
|
297 |
} |
298 |
|
299 |
/* (non-Javadoc)
|
300 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#addPoint(org.gvsig.fmap.geom.primitive.Point)
|
301 |
*/
|
302 |
public void addPoint(Point point) { |
303 |
addPrimitive(point); |
304 |
} |
305 |
|
306 |
/* (non-Javadoc)
|
307 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#setPoints(double[], double[])
|
308 |
*/
|
309 |
public void setPoints(double[] x, double[] y) { |
310 |
geometries = new ArrayList(); |
311 |
for (int i = 0; i < x.length; i++) { |
312 |
geometries.add(new Point2D(id, projection, x[i], y[i])); |
313 |
} |
314 |
} |
315 |
} |