root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FMultiPoint2D.java @ 2859
History | View | Annotate | Download (6.23 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 com.iver.cit.gvsig.fmap.core; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.ViewPort; |
44 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
45 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
46 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
47 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
48 |
|
49 |
import com.vividsolutions.jts.geom.Geometry; |
50 |
|
51 |
import org.cresques.cts.ICoordTrans; |
52 |
|
53 |
import java.awt.Color; |
54 |
import java.awt.Graphics2D; |
55 |
import java.awt.geom.Rectangle2D; |
56 |
import java.io.IOException; |
57 |
|
58 |
|
59 |
/**
|
60 |
* Multipunto 2D.
|
61 |
*
|
62 |
* @author Vicente Caballero Navarro
|
63 |
*/
|
64 |
public class FMultiPoint2D implements IGeometry { |
65 |
double[] x = null; |
66 |
double[] y = null; |
67 |
|
68 |
/**
|
69 |
* Crea un nuevo MultiPoint2D.
|
70 |
*
|
71 |
* @param x DOCUMENT ME!
|
72 |
* @param y DOCUMENT ME!
|
73 |
*/
|
74 |
public FMultiPoint2D(double[] x, double[] y) { |
75 |
this.x = x;
|
76 |
this.y = y;
|
77 |
} |
78 |
public FMultiPoint2D(FPoint2D[] points) { |
79 |
double[] auxX=new double[points.length]; |
80 |
double[] auxY=new double[points.length]; |
81 |
for (int i=0;i<points.length;i++){ |
82 |
auxX[i]=points[i].getX(); |
83 |
auxY[i]=points[i].getY(); |
84 |
} |
85 |
} |
86 |
/**
|
87 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D,
|
88 |
* ViewPort, FStyle2D)
|
89 |
*/
|
90 |
public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) { |
91 |
int size = 2; |
92 |
int hw = 4; |
93 |
|
94 |
for (int i = 0; i < x.length; i++) { |
95 |
java.awt.geom.Point2D.Double p = new java.awt.geom.Point2D.Double(x[i],
|
96 |
y[i]); |
97 |
vp.getAffineTransform().transform(p, p); |
98 |
g.setColor(Color.red);
|
99 |
g.fillOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw); |
100 |
g.setColor(Color.black);
|
101 |
g.drawOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw); |
102 |
} |
103 |
} |
104 |
|
105 |
/**
|
106 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
|
107 |
*/
|
108 |
public Geometry toJTSGeometry() {
|
109 |
return null; |
110 |
} |
111 |
|
112 |
/**
|
113 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
|
114 |
*/
|
115 |
public FLabel[] createLabels(int position, boolean duplicates) { |
116 |
return null; |
117 |
} |
118 |
|
119 |
/* (non-Javadoc)
|
120 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
|
121 |
*/
|
122 |
public boolean intersects(Rectangle2D r) { |
123 |
for (int i=0;i<getNumPoints();i++){ |
124 |
if (r.contains(x[i],y[i]))return true; |
125 |
} |
126 |
return false; |
127 |
} |
128 |
|
129 |
/* (non-Javadoc)
|
130 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
131 |
*/
|
132 |
public Rectangle2D getBounds2D() { |
133 |
Rectangle2D r=null; |
134 |
if (getNumPoints()>0){ |
135 |
r=new Rectangle2D.Double(x[0],y[0],0.001,0.001); |
136 |
} |
137 |
for (int i=1;i<getNumPoints();i++){ |
138 |
r.add(x[i],y[i]); |
139 |
} |
140 |
return r;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
|
145 |
*/
|
146 |
public int getGeometryType() { |
147 |
return FShape.MULTIPOINT;
|
148 |
} |
149 |
|
150 |
/* (non-Javadoc)
|
151 |
* @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)
|
152 |
*/
|
153 |
public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) { |
154 |
int size = 2; |
155 |
int hw = 4; |
156 |
|
157 |
for (int i = 0; i < x.length; i++) { |
158 |
java.awt.geom.Point2D.Double p = new java.awt.geom.Point2D.Double(x[i],
|
159 |
y[i]); |
160 |
vp.getAffineTransform().transform(p, p); |
161 |
FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), new FPoint2D(p.getX(),p.getY()), symbol);
|
162 |
|
163 |
/* java.awt.geom.Point2D.Double p = new java.awt.geom.Point2D.Double(x[i],
|
164 |
y[i]);
|
165 |
vp.getAffineTransform().transform(p, p);
|
166 |
g.setColor(Color.red);
|
167 |
g.fillOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
|
168 |
g.setColor(Color.black);
|
169 |
g.drawOval((int) p.x - size, (int) p.y - size, (int) hw, (int) hw);
|
170 |
*/
|
171 |
} |
172 |
} |
173 |
|
174 |
/* (non-Javadoc)
|
175 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
176 |
*/
|
177 |
public IGeometry cloneGeometry() {
|
178 |
return new FMultiPoint2D((double[])x.clone(),(double[])y.clone()); |
179 |
} |
180 |
|
181 |
/* (non-Javadoc)
|
182 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
|
183 |
*/
|
184 |
public void reProject(ICoordTrans ct) { |
185 |
// TODO Auto-generated method stub
|
186 |
} |
187 |
public int getNumPoints(){ |
188 |
return x.length;
|
189 |
} |
190 |
public FPoint2D getPoint(int i){ |
191 |
return new FPoint2D(x[i],y[i]); |
192 |
} |
193 |
/**
|
194 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
|
195 |
*/
|
196 |
public GeneralPathXIterator getGeneralPathXIterator() {
|
197 |
GeneralPathX gpx=new GeneralPathX();
|
198 |
if (getNumPoints()>0){ |
199 |
gpx.moveTo(x[0],y[0]); |
200 |
} |
201 |
for (int i=1;i<getNumPoints();i++){ |
202 |
gpx.lineTo(x[i],y[i]); |
203 |
} |
204 |
return (GeneralPathXIterator)gpx.getPathIterator(null); |
205 |
} |
206 |
/* (non-Javadoc)
|
207 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
|
208 |
*/
|
209 |
public boolean fastIntersects(double x, double y, double w, double h) { |
210 |
// TODO Auto-generated method stub
|
211 |
return false; |
212 |
} |
213 |
/**
|
214 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#toWKB()
|
215 |
*/
|
216 |
public byte[] toWKB() throws IOException { |
217 |
// TODO Auto-generated method stub
|
218 |
return null; |
219 |
} |
220 |
/* (non-Javadoc)
|
221 |
* @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)
|
222 |
*/
|
223 |
public void drawInts(Graphics2D g, ViewPort vp, FSymbol symbol) { |
224 |
draw(g,vp, symbol); |
225 |
|
226 |
} |
227 |
} |