root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometryCollection.java @ 3885
History | View | Annotate | Download (8 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 java.awt.Graphics2D; |
44 |
import java.awt.geom.Point2D; |
45 |
import java.awt.geom.Rectangle2D; |
46 |
import java.io.IOException; |
47 |
import java.util.ArrayList; |
48 |
|
49 |
import org.cresques.cts.ICoordTrans; |
50 |
import org.geotools.data.postgis.attributeio.WKBEncoder; |
51 |
|
52 |
import com.iver.cit.gvsig.fmap.ViewPort; |
53 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
54 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
55 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
56 |
import com.vividsolutions.jts.geom.Geometry; |
57 |
import com.vividsolutions.jts.geom.GeometryCollection; |
58 |
import com.vividsolutions.jts.geom.GeometryFactory; |
59 |
|
60 |
|
61 |
/**
|
62 |
* Colecci?n de Geometr?as.
|
63 |
*
|
64 |
* @author Vicente Caballero Navarro
|
65 |
*/
|
66 |
public class FGeometryCollection implements IGeometry { |
67 |
private ArrayList geometries = new ArrayList(); |
68 |
|
69 |
/**
|
70 |
* Crea un nuevo FGeometryCollection.
|
71 |
*
|
72 |
* @param geoms vector de geometr?as.
|
73 |
*/
|
74 |
public FGeometryCollection(IGeometry[] geoms) { |
75 |
for (int i = 0; i < geoms.length; i++) { |
76 |
geometries.add(geoms[i]); |
77 |
} |
78 |
} |
79 |
|
80 |
public void addGeometry(IGeometry g){ |
81 |
geometries.add(g); |
82 |
} |
83 |
|
84 |
/**
|
85 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D,
|
86 |
* com.iver.cit.gvsig.fmap.ViewPort, FStyle2D)
|
87 |
*/
|
88 |
public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) { |
89 |
for (int i = 0; i < geometries.size(); i++) |
90 |
((IGeometry)geometries.get(i)).draw(g, vp, symbol); |
91 |
} |
92 |
|
93 |
/**
|
94 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
|
95 |
*/
|
96 |
public FLabel[] createLabels(int position, boolean duplicates) { |
97 |
return null; |
98 |
} |
99 |
|
100 |
/**
|
101 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
|
102 |
*/
|
103 |
/* public boolean intersects(Rectangle2D r, double flatness) {
|
104 |
boolean resul = false;
|
105 |
for (int i = 0; i < geometries.size(); i++)
|
106 |
{
|
107 |
resul = ((IGeometry)geometries.get(i)).intersects(r, flatness);
|
108 |
if (resul) break;
|
109 |
}
|
110 |
|
111 |
return resul;
|
112 |
}
|
113 |
*/
|
114 |
/**
|
115 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
|
116 |
*/
|
117 |
public boolean intersects(Rectangle2D r) { |
118 |
boolean resul = false; |
119 |
for (int i = 0; i < geometries.size(); i++) |
120 |
{ |
121 |
resul = ((IGeometry)geometries.get(i)).intersects(r); |
122 |
if (resul) break; |
123 |
} |
124 |
|
125 |
return resul;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
130 |
*/
|
131 |
public Rectangle2D getBounds2D() { |
132 |
Rectangle2D rAux = null; |
133 |
|
134 |
for (int i = 0; i < geometries.size(); i++) |
135 |
if (rAux==null){ |
136 |
rAux=((IGeometry)geometries.get(i)).getBounds2D(); |
137 |
}else{
|
138 |
rAux.add(((IGeometry)geometries.get(i)).getBounds2D()); |
139 |
} |
140 |
return rAux;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
|
145 |
*/
|
146 |
public int getGeometryType() { |
147 |
/*int ret = 0;
|
148 |
|
149 |
for (int i = 0; i < geometries.length; i++) {
|
150 |
ret = ret | geometries[i].getGeometryType();
|
151 |
}
|
152 |
|
153 |
return ret;
|
154 |
*/
|
155 |
return FShape.LINE;
|
156 |
} |
157 |
|
158 |
/* (non-Javadoc)
|
159 |
* @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)
|
160 |
*/
|
161 |
public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) { |
162 |
for (int i = 0; i < geometries.size(); i++) |
163 |
((IGeometry)geometries.get(i)).draw(g, vp, symbol); |
164 |
} |
165 |
|
166 |
/* (non-Javadoc)
|
167 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
168 |
*/
|
169 |
public IGeometry cloneGeometry() {
|
170 |
IGeometry[] newGeometries = new IGeometry[geometries.size()]; |
171 |
|
172 |
for (int i = 0; i < geometries.size(); i++) |
173 |
newGeometries[i] = ((IGeometry)geometries.get(i)).cloneGeometry(); |
174 |
|
175 |
return new FGeometryCollection(newGeometries); |
176 |
} |
177 |
|
178 |
/* (non-Javadoc)
|
179 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
|
180 |
*/
|
181 |
public Geometry toJTSGeometry() {
|
182 |
Geometry[] theGeoms = new Geometry[geometries.size()]; |
183 |
for (int i = 0; i < geometries.size(); i++) |
184 |
{ |
185 |
theGeoms[i] = ((IGeometry)geometries.get(i)).toJTSGeometry(); |
186 |
} |
187 |
GeometryCollection geomCol = new GeometryFactory().createGeometryCollection(theGeoms);
|
188 |
return geomCol;
|
189 |
} |
190 |
|
191 |
/* (non-Javadoc)
|
192 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
|
193 |
*/
|
194 |
public void reProject(ICoordTrans ct) { |
195 |
for (int i = 0; i < geometries.size(); i++) |
196 |
((IGeometry)geometries.get(i)).reProject(ct); |
197 |
} |
198 |
|
199 |
/**
|
200 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
|
201 |
*/
|
202 |
public GeneralPathXIterator getGeneralPathXIterator() {
|
203 |
//TODO no esta implementado.
|
204 |
return null; |
205 |
} |
206 |
|
207 |
/* (non-Javadoc)
|
208 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
|
209 |
*/
|
210 |
public boolean fastIntersects(double x, double y, double w, double h) { |
211 |
boolean resul = false; |
212 |
for (int i = 0; i < geometries.size(); i++) |
213 |
{ |
214 |
resul = ((IGeometry)geometries.get(i)).fastIntersects(x,y,w,h); |
215 |
if (resul) break; |
216 |
} |
217 |
return resul;
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#toWKB()
|
222 |
*/
|
223 |
public byte[] toWKB() throws IOException { |
224 |
return WKBEncoder.encodeGeometry(toJTSGeometry());
|
225 |
} |
226 |
|
227 |
/* (non-Javadoc)
|
228 |
* @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)
|
229 |
*/
|
230 |
public void drawInts(Graphics2D g, ViewPort vp, FSymbol symbol) { |
231 |
for (int i = 0; i < geometries.size(); i++) |
232 |
((IGeometry)geometries.get(i)).drawInts(g, vp, symbol); |
233 |
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getShapes()
|
238 |
*/
|
239 |
/*public FShape[] getShapes() {
|
240 |
ArrayList shapes=new ArrayList();
|
241 |
for (int i= 0;i<geometries.size();i++){
|
242 |
FShape[] s=((IGeometry)geometries.get(i)).getShapes();
|
243 |
for (int j=0;j<s.length;j++){
|
244 |
shapes.add(s[j]);
|
245 |
}
|
246 |
}
|
247 |
return (FShape[])shapes.toArray(new FShape[0]);
|
248 |
}*/
|
249 |
public IGeometry[] getGeometries(){ |
250 |
return (IGeometry[])geometries.toArray(new IGeometry[0]).clone(); |
251 |
} |
252 |
|
253 |
/* (non-Javadoc)
|
254 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers(int)
|
255 |
*/
|
256 |
public Handler[] getHandlers(int type) { |
257 |
ArrayList handlers=new ArrayList(); |
258 |
for (int i = 0; i < geometries.size(); i++){ |
259 |
Handler[] handAux=((IGeometry)geometries.get(i)).getHandlers(type); |
260 |
for (int j=0;j<handAux.length;j++){ |
261 |
handlers.add(handAux[j]); |
262 |
} |
263 |
} |
264 |
return (Handler[])handlers.toArray(new Handler[0]); |
265 |
} |
266 |
|
267 |
public void move(double x, double y) { |
268 |
for (int i = 0; i < geometries.size(); i++){ |
269 |
((IGeometry)geometries.get(i)).move(x,y); |
270 |
} |
271 |
} |
272 |
/**
|
273 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#rotate(double, double, double)
|
274 |
*/
|
275 |
public void rotate(double r, double x, double y) { |
276 |
for (int i = 0; i < geometries.size(); i++){ |
277 |
((IGeometry)geometries.get(i)).rotate(r,x,y); |
278 |
} |
279 |
} |
280 |
/**
|
281 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#scale(java.awt.geom.Point2D, double, double)
|
282 |
*/
|
283 |
public void scale(Point2D point, double x, double y) { |
284 |
for (int i = 0; i < geometries.size(); i++){ |
285 |
((IGeometry)geometries.get(i)).scale(point,x,y); |
286 |
} |
287 |
} |
288 |
|
289 |
} |