svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / aggregate / MultiPoint2D.java @ 21425
History | View | Annotate | Download (6.73 KB)
1 | 21308 | jiyarza | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 20761 | jmvivo | *
|
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 | 21308 | jiyarza | * Av. Blasco Ib??ez, 50
|
24 | 20761 | jmvivo | * 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 | |||
47 | import org.cresques.cts.IProjection; |
||
48 | import org.gvsig.fmap.geom.Geometry; |
||
49 | 20964 | jiyarza | import org.gvsig.fmap.geom.GeometryManager; |
50 | 20761 | jmvivo | import org.gvsig.fmap.geom.handler.AbstractHandler; |
51 | 21425 | vcaballero | import org.gvsig.fmap.geom.primitive.DefaultEnvelope; |
52 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
53 | 20761 | jmvivo | import org.gvsig.fmap.geom.primitive.FShape; |
54 | import org.gvsig.fmap.geom.primitive.Point2D; |
||
55 | 20964 | jiyarza | import org.gvsig.fmap.geom.type.GeometryType; |
56 | 20761 | jmvivo | |
57 | /**
|
||
58 | * Multipunto 2D.
|
||
59 | 21425 | vcaballero | *
|
60 | 20761 | jmvivo | * @author Vicente Caballero Navarro
|
61 | */
|
||
62 | 20765 | jmvivo | public class MultiPoint2D extends BaseMultiPrimitive implements MultiPoint { |
63 | 20761 | jmvivo | |
64 | private static final long serialVersionUID = 1L; |
||
65 | 21425 | vcaballero | |
66 | 20964 | jiyarza | private static GeometryType geomType = GeometryManager.getInstance() |
67 | 21425 | vcaballero | .registerGeometryType(MultiPoint2D.class); |
68 | 21081 | jiyarza | public static int CODE = geomType.getType(); |
69 | 20761 | jmvivo | |
70 | public MultiPoint2D(IProjection projection, Point2D[] points) { |
||
71 | this(null, projection, points); |
||
72 | } |
||
73 | |||
74 | public MultiPoint2D(Point2D[] points) { |
||
75 | this(null, null, points); |
||
76 | } |
||
77 | |||
78 | public MultiPoint2D(IProjection projection) {
|
||
79 | this(null, projection, null); |
||
80 | } |
||
81 | |||
82 | public MultiPoint2D(String id, IProjection projection, Point2D[] points) { |
||
83 | super(id, projection, points);
|
||
84 | } |
||
85 | |||
86 | public MultiPoint2D(String id, IProjection projection) { |
||
87 | this(id, projection, null); |
||
88 | } |
||
89 | |||
90 | public MultiPoint2D(double[] x, double[] y) { |
||
91 | this(null, null, x, y); |
||
92 | } |
||
93 | |||
94 | /**
|
||
95 | * Crea un nuevo MultiPoint2D.
|
||
96 | 21425 | vcaballero | *
|
97 | 20761 | jmvivo | * @param x
|
98 | * DOCUMENT ME!
|
||
99 | * @param y
|
||
100 | * DOCUMENT ME!
|
||
101 | */
|
||
102 | public MultiPoint2D(String id, IProjection projection, double[] x, |
||
103 | double[] y) { |
||
104 | super(id, projection);
|
||
105 | geometries = new Point2D[x.length]; |
||
106 | for (int i = 0; i < x.length; i++) { |
||
107 | geometries[i] = new Point2D(id, projection, x[i], y[i]); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | /*
|
||
112 | * (non-Javadoc)
|
||
113 | 21425 | vcaballero | *
|
114 | 20761 | jmvivo | * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
115 | */
|
||
116 | public Geometry cloneGeometry() {
|
||
117 | Point2D[] aux = new Point2D[getNumgeometries()]; |
||
118 | for (int i = 0; i < getNumgeometries(); i++) { |
||
119 | aux[i] = (Point2D) geometries[i].cloneGeometry().getInternalShape();
|
||
120 | } |
||
121 | return new MultiPoint2D(id, projection, aux); |
||
122 | } |
||
123 | |||
124 | /*
|
||
125 | * (non-Javadoc)
|
||
126 | 21425 | vcaballero | *
|
127 | 20761 | jmvivo | * @see com.iver.cit.gvsig.fmap.core.FGeometryCollection#getBounds()
|
128 | */
|
||
129 | public Rectangle getBounds() { |
||
130 | Rectangle r = null; |
||
131 | if (getNumgeometries() > 0) { |
||
132 | r = geometries[0].getBounds();
|
||
133 | } |
||
134 | for (int i = 1; i < getNumgeometries(); i++) { |
||
135 | java.awt.geom.Point2D p = geometries[i] |
||
136 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
137 | r.add(p.getX(), p.getY()); |
||
138 | } |
||
139 | return r;
|
||
140 | } |
||
141 | |||
142 | /*
|
||
143 | * (non-Javadoc)
|
||
144 | 21425 | vcaballero | *
|
145 | 20761 | jmvivo | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
146 | */
|
||
147 | public Rectangle2D getBounds2D() { |
||
148 | Rectangle2D r = null; |
||
149 | if (getNumgeometries() > 0) { |
||
150 | java.awt.geom.Point2D p = geometries[0]
|
||
151 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
152 | |||
153 | r = new Rectangle2D.Double(p.getX(), p.getY(), 0.001, 0.001); |
||
154 | } |
||
155 | for (int i = 1; i < getNumgeometries(); i++) { |
||
156 | java.awt.geom.Point2D p = geometries[i] |
||
157 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
158 | r.add(p.getX(), p.getY()); |
||
159 | } |
||
160 | return r;
|
||
161 | } |
||
162 | |||
163 | /*
|
||
164 | * (non-Javadoc)
|
||
165 | 21425 | vcaballero | *
|
166 | 20761 | jmvivo | * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
167 | */
|
||
168 | public int getShapeType() { |
||
169 | return FShape.MULTIPOINT;
|
||
170 | } |
||
171 | |||
172 | /*
|
||
173 | * (non-Javadoc)
|
||
174 | 21425 | vcaballero | *
|
175 | 20761 | jmvivo | * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
176 | */
|
||
177 | public FShape cloneFShape() {
|
||
178 | Point2D[] aux = new Point2D[getNumgeometries()]; |
||
179 | for (int i = 0; i < getNumgeometries(); i++) { |
||
180 | aux[i] = (Point2D) geometries[i].cloneGeometry().getInternalShape();
|
||
181 | } |
||
182 | return (FShape) new MultiPoint2D(id, projection, aux); |
||
183 | } |
||
184 | |||
185 | /**
|
||
186 | * @return the numbre of points
|
||
187 | * @deprecated use getPrimitivesNumber
|
||
188 | */
|
||
189 | public int getNumgeometries() { |
||
190 | return getPrimitivesNumber();
|
||
191 | } |
||
192 | |||
193 | /**
|
||
194 | * @return the numbre of points
|
||
195 | * @deprecated use getPrimitivesNumber
|
||
196 | */
|
||
197 | public int getNumPoints() { |
||
198 | return getPrimitivesNumber();
|
||
199 | } |
||
200 | |||
201 | public Point2D getPoint(int i) { |
||
202 | return (Point2D) geometries[i].getInternalShape(); |
||
203 | } |
||
204 | |||
205 | /**
|
||
206 | * DOCUMENT ME!
|
||
207 | 21425 | vcaballero | *
|
208 | 20761 | jmvivo | * @author Vicente Caballero Navarro
|
209 | */
|
||
210 | class PointHandler extends AbstractHandler { |
||
211 | /**
|
||
212 | * Crea un nuevo PointHandler.
|
||
213 | 21425 | vcaballero | *
|
214 | 20761 | jmvivo | * @param x
|
215 | * DOCUMENT ME!
|
||
216 | * @param y
|
||
217 | * DOCUMENT ME!
|
||
218 | */
|
||
219 | public PointHandler(int i, Point2D p) { |
||
220 | point = new java.awt.geom.Point2D.Double(p.getX(), p.getY());
|
||
221 | index = i; |
||
222 | } |
||
223 | |||
224 | /**
|
||
225 | * DOCUMENT ME!
|
||
226 | 21425 | vcaballero | *
|
227 | 20761 | jmvivo | * @param x
|
228 | * DOCUMENT ME!
|
||
229 | * @param y
|
||
230 | * DOCUMENT ME!
|
||
231 | 21425 | vcaballero | *
|
232 | 20761 | jmvivo | * @return DOCUMENT ME!
|
233 | */
|
||
234 | public void move(double x, double y) { |
||
235 | java.awt.geom.Point2D p = geometries[index] |
||
236 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
237 | |||
238 | point.setLocation(p.getX() + x, p.getY() + y); |
||
239 | } |
||
240 | |||
241 | /**
|
||
242 | * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
||
243 | */
|
||
244 | public void set(double x, double y) { |
||
245 | point.setLocation(x, y); |
||
246 | } |
||
247 | |||
248 | } |
||
249 | |||
250 | public void transform(AffineTransform at) { |
||
251 | for (int i = 0; i < getNumgeometries(); i++) { |
||
252 | geometries[i].transform(at); |
||
253 | } |
||
254 | |||
255 | } |
||
256 | |||
257 | 21425 | vcaballero | public Envelope getEnvelope() {
|
258 | Envelope r = null;
|
||
259 | if (getNumgeometries() > 0) { |
||
260 | java.awt.geom.Point2D p = geometries[0]
|
||
261 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
262 | |||
263 | r = new DefaultEnvelope(2,new double[]{p.getX(), p.getY()},new double[]{ p.getX()+0.001, p.getY()+0.001}); |
||
264 | } |
||
265 | for (int i = 1; i < getNumgeometries(); i++) { |
||
266 | java.awt.geom.Point2D p = geometries[i] |
||
267 | .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
||
268 | r.add(new DefaultEnvelope(2,new double[]{p.getX(), p.getY()},new double[]{ p.getX()+0.001, p.getY()+0.001})); |
||
269 | } |
||
270 | return r;
|
||
271 | } |
||
272 | |||
273 | 20761 | jmvivo | } |