root / tags / v1_0_2_Build_903+3D / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FMultiPoint2D.java @ 10722
History | View | Annotate | Download (10.6 KB)
1 | 1100 | fjp | /* 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 | 262 | fjp | package com.iver.cit.gvsig.fmap.core; |
42 | |||
43 | 3885 | caballero | import java.awt.Color; |
44 | import java.awt.Graphics2D; |
||
45 | 4879 | fjp | import java.awt.Rectangle; |
46 | 5008 | fjp | import java.awt.Shape; |
47 | 3904 | fjp | import java.awt.geom.AffineTransform; |
48 | 4799 | fjp | import java.awt.geom.PathIterator; |
49 | 3885 | caballero | import java.awt.geom.Point2D; |
50 | import java.awt.geom.Rectangle2D; |
||
51 | import java.io.IOException; |
||
52 | |||
53 | import org.cresques.cts.ICoordTrans; |
||
54 | 4879 | fjp | import org.geotools.data.postgis.attributeio.WKBEncoder; |
55 | 3885 | caballero | |
56 | 262 | fjp | import com.iver.cit.gvsig.fmap.ViewPort; |
57 | 757 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
58 | 324 | fernando | import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
59 | 4879 | fjp | import com.vividsolutions.jts.geom.Coordinate; |
60 | 703 | fjp | import com.vividsolutions.jts.geom.Geometry; |
61 | 4879 | fjp | import com.vividsolutions.jts.geom.GeometryFactory; |
62 | import com.vividsolutions.jts.geom.MultiPoint; |
||
63 | 262 | fjp | |
64 | |||
65 | /**
|
||
66 | * Multipunto 2D.
|
||
67 | *
|
||
68 | * @author Vicente Caballero Navarro
|
||
69 | */
|
||
70 | 305 | fjp | public class FMultiPoint2D implements IGeometry { |
71 | 8779 | caballero | FGeometry[] points = null; |
72 | 262 | fjp | |
73 | 1005 | vcaballero | /**
|
74 | * Crea un nuevo MultiPoint2D.
|
||
75 | *
|
||
76 | * @param x DOCUMENT ME!
|
||
77 | * @param y DOCUMENT ME!
|
||
78 | */
|
||
79 | public FMultiPoint2D(double[] x, double[] y) { |
||
80 | 8779 | caballero | points = new FGeometry[x.length];
|
81 | 3904 | fjp | for (int i=0;i<x.length;i++){ |
82 | 8779 | caballero | points[i] = new FGeometry(new FPoint2D(x[i], y[i])); |
83 | 3904 | fjp | } |
84 | |||
85 | 1005 | vcaballero | } |
86 | 1132 | vcaballero | public FMultiPoint2D(FPoint2D[] points) { |
87 | 8779 | caballero | this.points=new FGeometry[points.length]; |
88 | for (int i=0;i<points.length;i++){ |
||
89 | this.points[i] = new FGeometry(points[i]); |
||
90 | } |
||
91 | } |
||
92 | 1005 | vcaballero | /**
|
93 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D,
|
||
94 | * ViewPort, FStyle2D)
|
||
95 | */
|
||
96 | public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) { |
||
97 | int size = 2; |
||
98 | int hw = 4; |
||
99 | 262 | fjp | |
100 | 3904 | fjp | for (int i = 0; i < points.length; i++) { |
101 | 8779 | caballero | Point2D p=points[i].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
102 | //Point2D.Double p = new Point2D.Double(p.getX(), p.getY());
|
||
103 | 1005 | vcaballero | vp.getAffineTransform().transform(p, p); |
104 | g.setColor(Color.red);
|
||
105 | 8779 | caballero | g.fillOval((int) p.getX() - size, (int) p.getY() - size, hw, hw); |
106 | 1005 | vcaballero | g.setColor(Color.black);
|
107 | 8779 | caballero | g.drawOval((int) p.getX() - size, (int) p.getY() - size, hw, hw); |
108 | 1005 | vcaballero | } |
109 | } |
||
110 | 262 | fjp | |
111 | 1005 | vcaballero | /**
|
112 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
|
||
113 | */
|
||
114 | public Geometry toJTSGeometry() {
|
||
115 | 4879 | fjp | Coordinate[] theGeoms = new Coordinate[points.length]; |
116 | for (int i = 0; i < theGeoms.length; i++) |
||
117 | { |
||
118 | 8779 | caballero | Point2D p=points[i].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
119 | |||
120 | Coordinate c = new Coordinate(p.getX(), p.getY());
|
||
121 | 4879 | fjp | theGeoms[i] = c; |
122 | } |
||
123 | MultiPoint geomCol = new GeometryFactory().createMultiPoint(theGeoms);
|
||
124 | 6024 | caballero | |
125 | |||
126 | 4879 | fjp | return geomCol;
|
127 | 1005 | vcaballero | } |
128 | 267 | fjp | |
129 | 1005 | vcaballero | /**
|
130 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
|
||
131 | */
|
||
132 | public FLabel[] createLabels(int position, boolean duplicates) { |
||
133 | 3453 | fjp | FLabel[] aux = new FLabel[getNumPoints()]; |
134 | for (int i=0; i < getNumPoints(); i++) |
||
135 | { |
||
136 | 8779 | caballero | Shape p=points[i].getInternalShape();
|
137 | |||
138 | aux[i] = FLabel.createFLabel((FShape)p); |
||
139 | 3453 | fjp | } |
140 | 3833 | caballero | |
141 | 3453 | fjp | return aux;
|
142 | 1005 | vcaballero | } |
143 | |||
144 | 267 | fjp | /* (non-Javadoc)
|
145 | 305 | fjp | * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
|
146 | 267 | fjp | */
|
147 | public boolean intersects(Rectangle2D r) { |
||
148 | 2193 | vcaballero | for (int i=0;i<getNumPoints();i++){ |
149 | 8779 | caballero | Point2D p=points[i].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
150 | if (r.contains(p.getX(),p.getY()))
|
||
151 | 6024 | caballero | return true; |
152 | 2193 | vcaballero | } |
153 | 267 | fjp | return false; |
154 | } |
||
155 | |||
156 | /* (non-Javadoc)
|
||
157 | 305 | fjp | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
158 | 267 | fjp | */
|
159 | public Rectangle2D getBounds2D() { |
||
160 | 2193 | vcaballero | Rectangle2D r=null; |
161 | if (getNumPoints()>0){ |
||
162 | 8779 | caballero | Point2D p=points[0].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
163 | |||
164 | r=new Rectangle2D.Double(p.getX(),p.getY(),0.001,0.001); |
||
165 | 2193 | vcaballero | } |
166 | for (int i=1;i<getNumPoints();i++){ |
||
167 | 8779 | caballero | Point2D p=points[i].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
168 | r.add(p.getX(),p.getY()); |
||
169 | 2193 | vcaballero | } |
170 | return r;
|
||
171 | 267 | fjp | } |
172 | 324 | fernando | |
173 | /**
|
||
174 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
|
||
175 | */
|
||
176 | public int getGeometryType() { |
||
177 | 5880 | fjp | return FShape.MULTIPOINT;
|
178 | 324 | fernando | } |
179 | 458 | fjp | |
180 | /* (non-Javadoc)
|
||
181 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
|
||
182 | */
|
||
183 | 8765 | jjdelcerro | public void draw(Graphics2D g, ViewPort vp, ISymbol symbol) { |
184 | 3885 | caballero | //int size = 2;
|
185 | //int hw = 4;
|
||
186 | 1005 | vcaballero | |
187 | 3904 | fjp | for (int i = 0; i < getNumPoints(); i++) { |
188 | 8779 | caballero | Point2D p=points[i].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
189 | |||
190 | 1005 | vcaballero | vp.getAffineTransform().transform(p, p); |
191 | 8765 | jjdelcerro | symbol.draw(g, vp.getAffineTransform(), new FPoint2D(p.getX(),p.getY()));
|
192 | // FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), new FPoint2D(p.getX(),p.getY()), symbol);
|
||
193 | 3833 | caballero | |
194 | 2193 | vcaballero | /* java.awt.geom.Point2D.Double p = new java.awt.geom.Point2D.Double(x[i],
|
195 | y[i]);
|
||
196 | vp.getAffineTransform().transform(p, p);
|
||
197 | 1005 | vcaballero | g.setColor(Color.red);
|
198 | g.fillOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
|
||
199 | g.setColor(Color.black);
|
||
200 | g.drawOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
|
||
201 | 2193 | vcaballero | */
|
202 | 1005 | vcaballero | } |
203 | 458 | fjp | } |
204 | 703 | fjp | |
205 | /* (non-Javadoc)
|
||
206 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
||
207 | */
|
||
208 | public IGeometry cloneGeometry() {
|
||
209 | 3904 | fjp | FPoint2D[] aux = new FPoint2D[getNumPoints()]; |
210 | for (int i=0; i < getNumPoints(); i++) |
||
211 | { |
||
212 | 8779 | caballero | aux[i] = (FPoint2D) points[i].cloneGeometry().getInternalShape(); |
213 | 3904 | fjp | } |
214 | 5880 | fjp | return new FMultiPoint2D(aux); |
215 | 703 | fjp | } |
216 | 885 | fjp | |
217 | /* (non-Javadoc)
|
||
218 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
|
||
219 | */
|
||
220 | public void reProject(ICoordTrans ct) { |
||
221 | 3904 | fjp | for (int i=0; i < getNumPoints(); i++) |
222 | { |
||
223 | points[i].reProject(ct); |
||
224 | } |
||
225 | 885 | fjp | } |
226 | 1132 | vcaballero | public int getNumPoints(){ |
227 | 3904 | fjp | return points.length;
|
228 | 1132 | vcaballero | } |
229 | public FPoint2D getPoint(int i){ |
||
230 | 8779 | caballero | return (FPoint2D)points[i].getInternalShape();
|
231 | 1132 | vcaballero | } |
232 | /**
|
||
233 | 4879 | fjp | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(AffineTransform)
|
234 | 1132 | vcaballero | */
|
235 | 4879 | fjp | public PathIterator getPathIterator(AffineTransform at) { |
236 | 2193 | vcaballero | GeneralPathX gpx=new GeneralPathX();
|
237 | if (getNumPoints()>0){ |
||
238 | 8779 | caballero | Point2D p=points[0].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
239 | gpx.moveTo(p.getX(), p.getY()); |
||
240 | 2193 | vcaballero | } |
241 | for (int i=1;i<getNumPoints();i++){ |
||
242 | 8779 | caballero | Point2D p=points[i].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
243 | gpx.lineTo(p.getX(), p.getY()); |
||
244 | 2193 | vcaballero | } |
245 | return (GeneralPathXIterator)gpx.getPathIterator(null); |
||
246 | 1132 | vcaballero | } |
247 | 1298 | fjp | /* (non-Javadoc)
|
248 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
|
||
249 | */
|
||
250 | public boolean fastIntersects(double x, double y, double w, double h) { |
||
251 | 3904 | fjp | for (int i=0; i < getNumPoints(); i++) |
252 | { |
||
253 | if (points[i].intersects(x,y,w,h))
|
||
254 | return true; |
||
255 | } |
||
256 | 1298 | fjp | return false; |
257 | } |
||
258 | 2859 | fjp | /* (non-Javadoc)
|
259 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#drawInts(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
|
||
260 | */
|
||
261 | 8765 | jjdelcerro | public void drawInts(Graphics2D g, ViewPort vp, ISymbol symbol) { |
262 | 2859 | fjp | draw(g,vp, symbol); |
263 | 3833 | caballero | |
264 | 2859 | fjp | } |
265 | 3833 | caballero | /* (non-Javadoc)
|
266 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers(int)
|
||
267 | */
|
||
268 | public Handler[] getHandlers(int type) { |
||
269 | 8779 | caballero | int numPoints=getNumPoints();
|
270 | Handler[] handlers=new Handler[numPoints]; |
||
271 | for (int i = 0; i < numPoints; i++){ |
||
272 | handlers[i]=points[i].getHandlers(type)[0];
|
||
273 | 3833 | caballero | } |
274 | 8779 | caballero | return handlers;
|
275 | 3833 | caballero | } |
276 | /**
|
||
277 | * DOCUMENT ME!
|
||
278 | *
|
||
279 | * @author Vicente Caballero Navarro
|
||
280 | */
|
||
281 | class PointHandler extends AbstractHandler { |
||
282 | /**
|
||
283 | * Crea un nuevo PointHandler.
|
||
284 | *
|
||
285 | * @param x DOCUMENT ME!
|
||
286 | * @param y DOCUMENT ME!
|
||
287 | */
|
||
288 | 3904 | fjp | public PointHandler(int i,FPoint2D p) { |
289 | point = new Point2D.Double(p.getX(), p.getY()); |
||
290 | 3833 | caballero | index=i; |
291 | } |
||
292 | |||
293 | /**
|
||
294 | * DOCUMENT ME!
|
||
295 | *
|
||
296 | * @param x DOCUMENT ME!
|
||
297 | * @param y DOCUMENT ME!
|
||
298 | *
|
||
299 | * @return DOCUMENT ME!
|
||
300 | */
|
||
301 | public void move(double x, double y) { |
||
302 | 8779 | caballero | Point2D p=points[index].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
303 | |||
304 | point.setLocation(p.getX()+x, |
||
305 | p.getY()+y); |
||
306 | 3833 | caballero | } |
307 | |||
308 | /**
|
||
309 | * @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
||
310 | */
|
||
311 | public void set(double x, double y) { |
||
312 | 3904 | fjp | point.setLocation(x, y); |
313 | 3833 | caballero | } |
314 | |||
315 | } |
||
316 | 3904 | fjp | public void transform(AffineTransform at) { |
317 | for (int i=0; i < getNumPoints(); i++) |
||
318 | { |
||
319 | points[i].transform(at); |
||
320 | } |
||
321 | 4711 | caballero | |
322 | 3904 | fjp | } |
323 | public byte[] toWKB() throws IOException { |
||
324 | 4879 | fjp | return WKBEncoder.encodeGeometry(toJTSGeometry());
|
325 | 3885 | caballero | } |
326 | 4879 | fjp | public PathIterator getPathIterator(AffineTransform at, double flatness) { |
327 | 4799 | fjp | GeneralPathX gpx=new GeneralPathX();
|
328 | if (getNumPoints()>0){ |
||
329 | 8779 | caballero | Point2D p=points[0].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
330 | |||
331 | gpx.moveTo(p.getX(), p.getY()); |
||
332 | 4799 | fjp | } |
333 | for (int i=1;i<getNumPoints();i++){ |
||
334 | 8779 | caballero | Point2D p=points[i].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
335 | |||
336 | gpx.lineTo(p.getX(), p.getY()); |
||
337 | 4799 | fjp | } |
338 | 6024 | caballero | return gpx.getPathIterator(at, flatness);
|
339 | 4799 | fjp | |
340 | } |
||
341 | 4879 | fjp | public boolean contains(double x, double y) { |
342 | boolean bResul;
|
||
343 | for (int i=0; i < getNumPoints(); i++) |
||
344 | { |
||
345 | bResul = points[i].contains(x,y); |
||
346 | if (bResul) return true; |
||
347 | } |
||
348 | return false; |
||
349 | } |
||
350 | public boolean contains(double x, double y, double w, double h) { |
||
351 | return false; |
||
352 | } |
||
353 | public boolean intersects(double x, double y, double w, double h) { |
||
354 | boolean bResul;
|
||
355 | for (int i=0; i < getNumPoints(); i++) |
||
356 | { |
||
357 | bResul = points[i].contains(x,y,w,h); |
||
358 | if (bResul) return true; |
||
359 | } |
||
360 | return false; |
||
361 | } |
||
362 | public Rectangle getBounds() { |
||
363 | Rectangle r=null; |
||
364 | if (getNumPoints()>0){ |
||
365 | r= points[0].getBounds();
|
||
366 | } |
||
367 | for (int i=1;i<getNumPoints();i++){ |
||
368 | 8779 | caballero | Point2D p=points[i].getHandlers(IGeometry.SELECTHANDLER)[0].getPoint(); |
369 | r.add(p.getX(),p.getY()); |
||
370 | 4879 | fjp | } |
371 | return r;
|
||
372 | } |
||
373 | public boolean contains(Point2D p) { |
||
374 | boolean bResul;
|
||
375 | for (int i=0; i < getNumPoints(); i++) |
||
376 | { |
||
377 | bResul = points[i].contains(p); |
||
378 | if (bResul) return true; |
||
379 | } |
||
380 | return false; |
||
381 | |||
382 | } |
||
383 | public boolean contains(Rectangle2D r) { |
||
384 | boolean bResul;
|
||
385 | for (int i=0; i < getNumPoints(); i++) |
||
386 | { |
||
387 | bResul = points[i].contains(r); |
||
388 | if (bResul) return true; |
||
389 | } |
||
390 | return false; |
||
391 | |||
392 | } |
||
393 | 5008 | fjp | public Shape getInternalShape() { |
394 | return this; |
||
395 | } |
||
396 | 262 | fjp | } |