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 @ 40559
History | View | Annotate | Download (7.38 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.geom.aggregate.impl; |
25 |
|
26 |
import java.awt.Rectangle; |
27 |
import java.awt.geom.AffineTransform; |
28 |
import java.awt.geom.Rectangle2D; |
29 |
import java.util.ArrayList; |
30 |
|
31 |
import org.cresques.cts.IProjection; |
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
34 |
import org.gvsig.fmap.geom.handler.AbstractHandler; |
35 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 |
import org.gvsig.fmap.geom.primitive.FShape; |
37 |
import org.gvsig.fmap.geom.primitive.Point; |
38 |
import org.gvsig.fmap.geom.primitive.impl.Envelope2D; |
39 |
import org.gvsig.fmap.geom.primitive.impl.Point2D; |
40 |
import org.gvsig.fmap.geom.type.GeometryType; |
41 |
|
42 |
/**
|
43 |
* Multipunto 2D.
|
44 |
*
|
45 |
* @author Vicente Caballero Navarro
|
46 |
*/
|
47 |
public class MultiPoint2D extends BaseMultiPrimitive implements MultiPoint { |
48 |
|
49 |
/**
|
50 |
* The constructor with the GeometryType like and argument
|
51 |
* is used by the {@link GeometryType}{@link #create()}
|
52 |
* to create the geometry
|
53 |
* @param type
|
54 |
* The geometry type
|
55 |
*/
|
56 |
public MultiPoint2D(GeometryType geometryType) {
|
57 |
super(geometryType);
|
58 |
} |
59 |
|
60 |
/**
|
61 |
*
|
62 |
* @param geometryType
|
63 |
* @param id
|
64 |
* @param projection
|
65 |
*/
|
66 |
MultiPoint2D(GeometryType geometryType, String id, IProjection projection) {
|
67 |
super(geometryType, id, projection);
|
68 |
} |
69 |
|
70 |
/**
|
71 |
*
|
72 |
* @param geometryType
|
73 |
* @param id
|
74 |
* @param projection
|
75 |
* @param points
|
76 |
*/
|
77 |
public MultiPoint2D(GeometryType geometryType, String id, IProjection projection, Point2D[] points) { |
78 |
super(geometryType, id, projection, points);
|
79 |
} |
80 |
|
81 |
|
82 |
|
83 |
/**
|
84 |
*
|
85 |
* @param id
|
86 |
* @param projection
|
87 |
* @param x
|
88 |
* @param y
|
89 |
*/
|
90 |
MultiPoint2D(GeometryType geometryType, String id, IProjection projection, double[] x, |
91 |
double[] y) { |
92 |
super(geometryType, id, projection);
|
93 |
geometries = new ArrayList(); |
94 |
for (int i = 0; i < x.length; i++) { |
95 |
geometries.add(new Point2D(x[i], y[i])); |
96 |
} |
97 |
} |
98 |
|
99 |
/*
|
100 |
* (non-Javadoc)
|
101 |
*
|
102 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
103 |
*/
|
104 |
public Geometry cloneGeometry() {
|
105 |
MultiPoint auxPoint = new MultiPoint2D(geometryType, id, projection);
|
106 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
107 |
auxPoint.addPoint((Point)((Point) geometries.get(i)).cloneGeometry()); |
108 |
} |
109 |
return auxPoint;
|
110 |
} |
111 |
|
112 |
/*
|
113 |
* (non-Javadoc)
|
114 |
*
|
115 |
* @see com.iver.cit.gvsig.fmap.core.FGeometryCollection#getBounds()
|
116 |
*/
|
117 |
public Rectangle getBounds() { |
118 |
Rectangle r = null; |
119 |
if (getNumgeometries() > 0) { |
120 |
r = ((Point)geometries.get(0)).getShape().getBounds(); |
121 |
} |
122 |
|
123 |
Rectangle2D r2d = new Rectangle2D.Double( |
124 |
r.x, |
125 |
r.y, |
126 |
r.width, |
127 |
r.height); |
128 |
|
129 |
for (int i = 1; i < getNumgeometries(); i++) { |
130 |
java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
131 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
132 |
r2d.add(p.getX(), p.getY()); |
133 |
} |
134 |
|
135 |
Rectangle resp = new Rectangle( |
136 |
Math.round((float) r2d.getMinX()), |
137 |
Math.round((float) r2d.getMinY()), |
138 |
Math.max(1, Math.round((float) r2d.getWidth())), |
139 |
Math.max(1, Math.round((float) r2d.getHeight()))); |
140 |
// w,h >= 1
|
141 |
|
142 |
return resp;
|
143 |
} |
144 |
|
145 |
/*
|
146 |
* (non-Javadoc)
|
147 |
*
|
148 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
149 |
*/
|
150 |
public Rectangle2D getBounds2D() { |
151 |
Rectangle2D r = null; |
152 |
if (getNumgeometries() > 0) { |
153 |
java.awt.geom.Point2D p = ((Point)geometries.get(0)) |
154 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
155 |
|
156 |
r = new Rectangle2D.Double(p.getX(), p.getY(), 0.001, 0.001); |
157 |
} |
158 |
for (int i = 1; i < getNumgeometries(); i++) { |
159 |
java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
160 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
161 |
r.add(p.getX(), p.getY()); |
162 |
} |
163 |
return r;
|
164 |
} |
165 |
|
166 |
/*
|
167 |
* (non-Javadoc)
|
168 |
*
|
169 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
170 |
*/
|
171 |
public FShape cloneFShape() {
|
172 |
Point2D[] aux = new Point2D[getNumgeometries()]; |
173 |
for (int i = 0; i < getNumgeometries(); i++) { |
174 |
aux[i] = (Point2D) ((Point)geometries.get(i)).cloneGeometry().getInternalShape(); |
175 |
} |
176 |
return (FShape) new MultiPoint2D(getGeometryType(), id, projection, aux); |
177 |
} |
178 |
|
179 |
/**
|
180 |
* @return the numbre of points
|
181 |
* @deprecated use getPrimitivesNumber
|
182 |
*/
|
183 |
public int getNumgeometries() { |
184 |
return getPrimitivesNumber();
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* @return the numbre of points
|
189 |
* @deprecated use getPrimitivesNumber
|
190 |
*/
|
191 |
public int getNumPoints() { |
192 |
return getPrimitivesNumber();
|
193 |
} |
194 |
|
195 |
public Point2D getPoint(int i) { |
196 |
return (Point2D) ((Point)geometries.get(i)).getInternalShape(); |
197 |
} |
198 |
|
199 |
/**
|
200 |
* DOCUMENT ME!
|
201 |
*
|
202 |
* @author Vicente Caballero Navarro
|
203 |
*/
|
204 |
class PointHandler extends AbstractHandler { |
205 |
/**
|
206 |
* Crea un nuevo PointHandler.
|
207 |
*
|
208 |
* @param x
|
209 |
* DOCUMENT ME!
|
210 |
* @param y
|
211 |
* DOCUMENT ME!
|
212 |
*/
|
213 |
public PointHandler(int i, Point2D p) { |
214 |
point = new java.awt.geom.Point2D.Double(p.getX(), p.getY());
|
215 |
index = i; |
216 |
} |
217 |
|
218 |
/**
|
219 |
* DOCUMENT ME!
|
220 |
*
|
221 |
* @param x
|
222 |
* DOCUMENT ME!
|
223 |
* @param y
|
224 |
* DOCUMENT ME!
|
225 |
*
|
226 |
* @return DOCUMENT ME!
|
227 |
*/
|
228 |
public void move(double x, double y) { |
229 |
java.awt.geom.Point2D p = ((Point)geometries.get(index))
|
230 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
231 |
|
232 |
point.setLocation(p.getX() + x, p.getY() + y); |
233 |
} |
234 |
|
235 |
/**
|
236 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
237 |
*/
|
238 |
public void set(double x, double y) { |
239 |
point.setLocation(x, y); |
240 |
} |
241 |
|
242 |
} |
243 |
|
244 |
public void transform(AffineTransform at) { |
245 |
for (int i = 0; i < getNumgeometries(); i++) { |
246 |
((Point)geometries.get(i)).transform(at);
|
247 |
} |
248 |
|
249 |
} |
250 |
|
251 |
public Envelope getEnvelope() {
|
252 |
Envelope r = null;
|
253 |
if (getNumgeometries() > 0) { |
254 |
java.awt.geom.Point2D p = ((Point)geometries.get(0)) |
255 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
256 |
|
257 |
r = new Envelope2D(p.getX(), p.getY(), p.getX()+0.001, p.getY()+0.001); |
258 |
} |
259 |
for (int i = 1; i < getNumgeometries(); i++) { |
260 |
java.awt.geom.Point2D p = ((Point)geometries.get(i))
|
261 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
262 |
r.add(new Envelope2D(p.getX(), p.getY(),p.getX()+0.001, p.getY()+0.001)); |
263 |
} |
264 |
return r;
|
265 |
} |
266 |
|
267 |
/* (non-Javadoc)
|
268 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#addPoint(org.gvsig.fmap.geom.primitive.Point)
|
269 |
*/
|
270 |
public void addPoint(Point point) { |
271 |
addPrimitive(point); |
272 |
} |
273 |
|
274 |
/* (non-Javadoc)
|
275 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#setPoints(double[], double[])
|
276 |
*/
|
277 |
public void setPoints(double[] x, double[] y) { |
278 |
geometries = new ArrayList(); |
279 |
for (int i = 0; i < x.length; i++) { |
280 |
geometries.add(new Point2D(x[i], y[i])); |
281 |
} |
282 |
} |
283 |
|
284 |
/* (non-Javadoc)
|
285 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#getPointAt(int)
|
286 |
*/
|
287 |
public Point getPointAt(int index) { |
288 |
return (Point)getPrimitiveAt(index) ; |
289 |
} |
290 |
} |