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