Revision 41590 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/BaseMultiPrimitive.java
BaseMultiPrimitive.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 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.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 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.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 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. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.fmap.geom.aggregate.impl; |
25 | 24 |
|
... | ... | |
42 | 41 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
43 | 42 |
import org.gvsig.fmap.geom.handler.Handler; |
44 | 43 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
44 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
45 | 45 |
import org.gvsig.fmap.geom.primitive.Envelope; |
46 | 46 |
import org.gvsig.fmap.geom.primitive.FShape; |
47 | 47 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
... | ... | |
53 | 53 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es) |
54 | 54 |
*/ |
55 | 55 |
public abstract class BaseMultiPrimitive extends AbstractPrimitive implements |
56 |
MultiPrimitive { |
|
57 |
private static final long serialVersionUID = 8023609161647736932L; |
|
58 |
|
|
59 |
private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class); |
|
56 |
MultiPrimitive { |
|
60 | 57 |
|
61 |
protected ArrayList geometries = null; |
|
62 |
|
|
63 |
/** |
|
64 |
* The constructor with the GeometryType like and argument |
|
65 |
* is used by the {@link GeometryType}{@link #create()} |
|
66 |
* to create the geometry |
|
67 |
* @param type |
|
68 |
* The geometry type |
|
69 |
*/ |
|
70 |
public BaseMultiPrimitive(GeometryType geometryType) { |
|
71 |
super(geometryType); |
|
72 |
geometries = new ArrayList(); |
|
73 |
} |
|
58 |
private static final long serialVersionUID = 8023609161647736932L; |
|
74 | 59 |
|
75 |
BaseMultiPrimitive(GeometryType geometryType, String id, IProjection projection, |
|
76 |
Geometry[] geometries) { |
|
77 |
super(geometryType, id, projection); |
|
78 |
this.geometries = new ArrayList(); |
|
79 |
for (int i=0 ; i<geometries.length ; i++){ |
|
80 |
this.geometries.add(geometries[i]); |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
BaseMultiPrimitive(GeometryType geometryType, String id, IProjection projection) { |
|
85 |
super(geometryType, id, projection); |
|
86 |
this.geometries = new ArrayList(); |
|
87 |
} |
|
60 |
private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class); |
|
88 | 61 |
|
89 |
/* |
|
90 |
* (non-Javadoc) |
|
91 |
* |
|
92 |
* @see java.awt.Shape#contains(double, double) |
|
93 |
*/ |
|
94 |
public boolean contains(double x, double y) { |
|
95 |
|
|
96 |
boolean bResul; |
|
97 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
62 |
protected List geometries = null; |
|
98 | 63 |
|
99 |
try { |
|
100 |
bResul = containsPoint( |
|
101 |
(Geometry)geometries.get(i), x, y); |
|
102 |
} catch (GeometryOperationException e) { |
|
103 |
logger.error("While doing contains: " + e.getMessage(), e); |
|
104 |
bResul = true; |
|
105 |
} |
|
64 |
/** |
|
65 |
* The constructor with the GeometryType like and argument is used by the |
|
66 |
* {@link GeometryType}{@link #create()} to create the geometry |
|
67 |
* |
|
68 |
* @param type The geometry type |
|
69 |
*/ |
|
70 |
public BaseMultiPrimitive(GeometryType geometryType) { |
|
71 |
super(geometryType); |
|
72 |
geometries = new ArrayList(); |
|
73 |
} |
|
106 | 74 |
|
107 |
if (bResul) |
|
108 |
return true; |
|
109 |
} |
|
110 |
return false; |
|
111 |
} |
|
75 |
BaseMultiPrimitive(GeometryType geometryType, String id, IProjection projection, |
|
76 |
Geometry[] geometries) { |
|
77 |
super(geometryType, id, projection); |
|
78 |
this.geometries = new ArrayList(); |
|
79 |
for (int i = 0; i < geometries.length; i++) { |
|
80 |
this.geometries.add(geometries[i]); |
|
81 |
} |
|
82 |
} |
|
112 | 83 |
|
113 |
/* |
|
114 |
* (non-Javadoc) |
|
115 |
* |
|
116 |
* @see java.awt.Shape#contains(double, double, double, double) |
|
117 |
*/ |
|
118 |
public boolean contains(double x, double y, double w, double h) { |
|
119 |
return false; |
|
120 |
} |
|
84 |
BaseMultiPrimitive(GeometryType geometryType, String id, IProjection projection) { |
|
85 |
super(geometryType, id, projection); |
|
86 |
this.geometries = new ArrayList(); |
|
87 |
} |
|
121 | 88 |
|
122 |
/* |
|
123 |
* (non-Javadoc) |
|
124 |
* |
|
125 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D) |
|
126 |
*/ |
|
127 |
public boolean contains(Point2D p) { |
|
128 |
boolean bResul; |
|
129 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
130 |
try { |
|
131 |
bResul = containsPoint( |
|
132 |
(Geometry)geometries.get(i), |
|
133 |
p.getX(), p.getY()); |
|
134 |
} catch (GeometryOperationException e) { |
|
135 |
logger.error("While doing contains: " + e.getMessage(), e); |
|
136 |
bResul = true; |
|
137 |
} |
|
138 |
if (bResul) |
|
139 |
return true; |
|
140 |
} |
|
141 |
return false; |
|
142 |
} |
|
89 |
/* |
|
90 |
* (non-Javadoc) |
|
91 |
* |
|
92 |
* @see java.awt.Shape#contains(double, double) |
|
93 |
*/ |
|
94 |
public boolean contains(double x, double y) { |
|
143 | 95 |
|
144 |
/* |
|
145 |
* (non-Javadoc) |
|
146 |
* |
|
147 |
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D) |
|
148 |
*/ |
|
149 |
public boolean contains(Rectangle2D r) { |
|
150 |
boolean bResul; |
|
151 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
152 |
|
|
153 |
try { |
|
154 |
bResul = containsRectangle( |
|
155 |
(Geometry)geometries.get(i), |
|
156 |
r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight()); |
|
157 |
} catch (GeometryOperationException e) { |
|
158 |
logger.error("While doing contains: " + e.getMessage(), e); |
|
159 |
bResul = true; |
|
160 |
} |
|
161 |
|
|
162 |
|
|
163 |
if (bResul) |
|
164 |
return true; |
|
165 |
} |
|
166 |
return false; |
|
167 |
} |
|
96 |
boolean bResul; |
|
97 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
168 | 98 |
|
169 |
/* |
|
170 |
* (non-Javadoc) |
|
171 |
* |
|
172 |
* @see org.gvsig.geometries.iso.GM_Object#coordinateDimension() |
|
173 |
*/ |
|
174 |
public int getDimension() { |
|
175 |
return 2; |
|
176 |
} |
|
99 |
try { |
|
100 |
bResul = containsPoint( |
|
101 |
(Geometry) geometries.get(i), x, y); |
|
102 |
} catch (GeometryOperationException e) { |
|
103 |
logger.error("While doing contains: " + e.getMessage(), e); |
|
104 |
bResul = true; |
|
105 |
} |
|
177 | 106 |
|
178 |
/* |
|
179 |
* (non-Javadoc) |
|
180 |
* |
|
181 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, |
|
182 |
* double, double, double) |
|
183 |
*/ |
|
184 |
public boolean fastIntersects(double x, double y, double w, double h) { |
|
185 |
|
|
186 |
boolean resp = false; |
|
187 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
188 |
|
|
189 |
Geometry geom = (Geometry) geometries.get(i); |
|
190 |
|
|
191 |
try { |
|
192 |
resp = intersectsRectangle(geom, x, y, w, h); |
|
193 |
} catch (GeometryOperationException e) { |
|
194 |
logger.error("While doing fast intersects: " + e.getMessage(), e); |
|
195 |
resp = true; |
|
196 |
} |
|
197 |
|
|
198 |
if (resp) { |
|
199 |
return true; |
|
200 |
} |
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
} |
|
205 |
return false; |
|
206 |
} |
|
107 |
if (bResul) { |
|
108 |
return true; |
|
109 |
} |
|
110 |
} |
|
111 |
return false; |
|
112 |
} |
|
207 | 113 |
|
114 |
/* |
|
115 |
* (non-Javadoc) |
|
116 |
* |
|
117 |
* @see java.awt.Shape#contains(double, double, double, double) |
|
118 |
*/ |
|
119 |
public boolean contains(double x, double y, double w, double h) { |
|
120 |
return false; |
|
121 |
} |
|
208 | 122 |
|
209 |
/* |
|
210 |
* (non-Javadoc) |
|
211 |
* |
|
212 |
* @see java.awt.Shape#getBounds() |
|
213 |
*/ |
|
214 |
public Rectangle getBounds() { |
|
215 |
Rectangle r = null; |
|
216 |
if (getPrimitivesNumber() > 0) { |
|
217 |
r = ((Geometry)geometries.get(0)).getShape().getBounds(); |
|
218 |
} |
|
219 |
for (int i = 1; i < getPrimitivesNumber(); i++) { |
|
220 |
Rectangle r2 = ((Geometry)geometries.get(i)).getShape().getBounds(); |
|
221 |
r.add(r2); |
|
222 |
} |
|
223 |
return r; |
|
224 |
} |
|
123 |
/* |
|
124 |
* (non-Javadoc) |
|
125 |
* |
|
126 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D) |
|
127 |
*/ |
|
128 |
public boolean contains(Point2D p) { |
|
129 |
boolean bResul; |
|
130 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
131 |
try { |
|
132 |
bResul = containsPoint( |
|
133 |
(Geometry) geometries.get(i), |
|
134 |
p.getX(), p.getY()); |
|
135 |
} catch (GeometryOperationException e) { |
|
136 |
logger.error("While doing contains: " + e.getMessage(), e); |
|
137 |
bResul = true; |
|
138 |
} |
|
139 |
if (bResul) { |
|
140 |
return true; |
|
141 |
} |
|
142 |
} |
|
143 |
return false; |
|
144 |
} |
|
225 | 145 |
|
226 |
/*
|
|
227 |
* (non-Javadoc)
|
|
228 |
*
|
|
229 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
|
230 |
*/
|
|
231 |
public Rectangle2D getBounds2D() {
|
|
232 |
return null;
|
|
233 |
}
|
|
146 |
/*
|
|
147 |
* (non-Javadoc)
|
|
148 |
*
|
|
149 |
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
|
|
150 |
*/
|
|
151 |
public boolean contains(Rectangle2D r) {
|
|
152 |
boolean bResul;
|
|
153 |
for (int i = 0; i < getPrimitivesNumber(); i++) {
|
|
234 | 154 |
|
235 |
public Handler[] getHandlers(int type) { |
|
236 |
int numPrimitives = getPrimitivesNumber(); |
|
237 |
List handlers = new ArrayList(); |
|
238 |
for (int i = 0; i < numPrimitives; i++) { |
|
239 |
Handler[] currentHandlers = getPrimitiveAt(i).getHandlers(type); |
|
240 |
for (int j=0 ; j<currentHandlers.length ; j++){ |
|
241 |
handlers.add(currentHandlers[j]); |
|
242 |
} |
|
243 |
} |
|
244 |
return (Handler[])handlers.toArray(new Handler[handlers.size()]); |
|
245 |
} |
|
155 |
try { |
|
156 |
bResul = containsRectangle( |
|
157 |
(Geometry) geometries.get(i), |
|
158 |
r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight()); |
|
159 |
} catch (GeometryOperationException e) { |
|
160 |
logger.error("While doing contains: " + e.getMessage(), e); |
|
161 |
bResul = true; |
|
162 |
} |
|
246 | 163 |
|
247 |
/* |
|
248 |
* (non-Javadoc) |
|
249 |
* |
|
250 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getInternalShape() |
|
251 |
*/ |
|
252 |
public Shape getInternalShape() { |
|
253 |
return this; |
|
254 |
} |
|
164 |
if (bResul) { |
|
165 |
return true; |
|
166 |
} |
|
167 |
} |
|
168 |
return false; |
|
169 |
} |
|
255 | 170 |
|
256 |
/* |
|
257 |
* (non-Javadoc) |
|
258 |
* |
|
259 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(java.awt.geom.AffineTransform) |
|
260 |
*/ |
|
261 |
public PathIterator getPathIterator(AffineTransform at) { |
|
262 |
GeneralPathX gpx = new GeneralPathX(); |
|
263 |
int primiNum = getPrimitivesNumber(); |
|
264 |
if (primiNum > 0) { |
|
265 |
Point2D p = ((Geometry)geometries.get(0)).getHandlers(Geometry.SELECTHANDLER)[0] |
|
266 |
.getPoint(); |
|
267 |
gpx.moveTo(p.getX(), p.getY()); |
|
171 |
/* |
|
172 |
* (non-Javadoc) |
|
173 |
* |
|
174 |
* @see org.gvsig.geometries.iso.GM_Object#coordinateDimension() |
|
175 |
*/ |
|
176 |
public int getDimension() { |
|
177 |
return 2; |
|
178 |
} |
|
268 | 179 |
|
269 |
for (int i = 1; i < primiNum; i++) { |
|
270 |
p = ((Geometry)geometries.get(i)).getHandlers(Geometry.SELECTHANDLER)[0] |
|
271 |
.getPoint(); |
|
272 |
gpx.lineTo(p.getX(), p.getY()); |
|
273 |
} |
|
274 |
Point2D p2 = ((Geometry)geometries.get(primiNum-1)).getHandlers(Geometry.SELECTHANDLER)[((Geometry)geometries.get(primiNum-1)).getHandlers(Geometry.SELECTHANDLER).length-1] |
|
275 |
.getPoint(); |
|
276 |
gpx.lineTo(p2.getX(), p2.getY()); |
|
277 |
} |
|
278 |
return gpx.getPathIterator(at); |
|
279 |
} |
|
180 |
/* |
|
181 |
* (non-Javadoc) |
|
182 |
* |
|
183 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, |
|
184 |
* double, double, double) |
|
185 |
*/ |
|
186 |
public boolean fastIntersects(double x, double y, double w, double h) { |
|
280 | 187 |
|
281 |
/* |
|
282 |
* (non-Javadoc) |
|
283 |
* |
|
284 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(java.awt.geom.AffineTransform, |
|
285 |
* double) |
|
286 |
*/ |
|
287 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
|
288 |
GeneralPathX gpx = new GeneralPathX(); |
|
289 |
int primiNum = getPrimitivesNumber(); |
|
290 |
if (primiNum > 0) { |
|
188 |
boolean resp = false; |
|
189 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
291 | 190 |
|
292 |
Geometry prim = null; |
|
293 |
for (int i = 0; i < primiNum; i++) { |
|
294 |
prim = (Geometry) geometries.get(i); |
|
295 |
gpx.append( |
|
296 |
prim.getPathIterator(at, flatness), |
|
297 |
/* |
|
298 |
* This is a relevant change. |
|
299 |
* After BN 2056 this class will not return |
|
300 |
* connected path iterator. There will be MOVE_TO |
|
301 |
* between iterator of each primitive |
|
302 |
*/ |
|
303 |
false); |
|
304 |
} |
|
305 |
} |
|
306 |
/* |
|
307 |
* affine transform and flatness already applied in loop |
|
308 |
*/ |
|
309 |
return gpx.getPathIterator(null); |
|
310 |
} |
|
191 |
Geometry geom = (Geometry) geometries.get(i); |
|
311 | 192 |
|
312 |
/* |
|
313 |
* (non-Javadoc) |
|
314 |
* |
|
315 |
* @see org.gvsig.geometries.iso.aggregate.GM_Aggregate#getPrimitiveAt(int) |
|
316 |
*/ |
|
317 |
public Primitive getPrimitiveAt(int i) { |
|
318 |
if (i < getPrimitivesNumber()) { |
|
319 |
return (Primitive) ((Geometry)geometries.get(i)); |
|
320 |
} |
|
321 |
return null; |
|
322 |
} |
|
193 |
try { |
|
194 |
resp = intersectsRectangle(geom, x, y, w, h); |
|
195 |
} catch (GeometryOperationException e) { |
|
196 |
logger.error("While doing fast intersects: " + e.getMessage(), e); |
|
197 |
resp = true; |
|
198 |
} |
|
323 | 199 |
|
324 |
/* |
|
325 |
* (non-Javadoc) |
|
326 |
* |
|
327 |
* @see org.gvsig.geometries.iso.aggregate.GM_Aggregate#getPrimitivesNumber() |
|
328 |
*/ |
|
329 |
public int getPrimitivesNumber() { |
|
330 |
if (geometries == null) { |
|
331 |
return 0; |
|
332 |
} |
|
333 |
return geometries.size(); |
|
334 |
} |
|
200 |
if (resp) { |
|
201 |
return true; |
|
202 |
} |
|
335 | 203 |
|
336 |
/* |
|
337 |
* (non-Javadoc) |
|
338 |
* |
|
339 |
* @see java.awt.Shape#intersects(double, double, double, double) |
|
340 |
*/ |
|
341 |
public boolean intersects(double x, double y, double w, double h) { |
|
342 |
boolean bResul; |
|
343 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
204 |
} |
|
205 |
return false; |
|
206 |
} |
|
344 | 207 |
|
345 |
try { |
|
346 |
bResul = containsRectangle((Geometry)geometries.get(i), x, y, w, h); |
|
347 |
} catch (GeometryOperationException e) { |
|
348 |
logger.error("While doing contains: " + e.getMessage(), e); |
|
349 |
bResul = true; |
|
350 |
} |
|
351 |
if (bResul) |
|
352 |
return true; |
|
353 |
} |
|
354 |
return false; |
|
355 |
} |
|
356 | 208 |
|
209 |
/* |
|
210 |
* (non-Javadoc) |
|
211 |
* |
|
212 |
* @see java.awt.Shape#getBounds() |
|
213 |
*/ |
|
214 |
public Rectangle getBounds() { |
|
215 |
Rectangle r = null; |
|
216 |
if (getPrimitivesNumber() > 0) { |
|
217 |
r = ((Geometry) geometries.get(0)).getShape().getBounds(); |
|
218 |
} |
|
219 |
for (int i = 1; i < getPrimitivesNumber(); i++) { |
|
220 |
Rectangle r2 = ((Geometry) geometries.get(i)).getShape().getBounds(); |
|
221 |
r.add(r2); |
|
222 |
} |
|
223 |
return r; |
|
224 |
} |
|
357 | 225 |
|
358 |
/* |
|
359 |
* (non-Javadoc) |
|
360 |
* |
|
361 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D) |
|
362 |
*/ |
|
363 |
public boolean intersects(Rectangle2D r) { |
|
364 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
365 |
|
|
366 |
Geometry prim = this.getPrimitiveAt(i); |
|
367 |
if (prim.intersects(r)) { |
|
368 |
return true; |
|
369 |
} |
|
370 |
} |
|
371 |
return false; |
|
372 |
} |
|
226 |
/* |
|
227 |
* (non-Javadoc) |
|
228 |
* |
|
229 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D() |
|
230 |
*/ |
|
231 |
public Rectangle2D getBounds2D() { |
|
232 |
return null; |
|
233 |
} |
|
373 | 234 |
|
374 |
/* |
|
375 |
* (non-Javadoc) |
|
376 |
* |
|
377 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#isSimple() |
|
378 |
*/ |
|
379 |
public boolean isSimple() { |
|
380 |
return false; |
|
381 |
} |
|
235 |
public Handler[] getHandlers(int type) { |
|
236 |
int numPrimitives = getPrimitivesNumber(); |
|
237 |
List handlers = new ArrayList(); |
|
238 |
for (int i = 0; i < numPrimitives; i++) { |
|
239 |
Handler[] currentHandlers = getPrimitiveAt(i).getHandlers(type); |
|
240 |
for (int j = 0; j < currentHandlers.length; j++) { |
|
241 |
handlers.add(currentHandlers[j]); |
|
242 |
} |
|
243 |
} |
|
244 |
return (Handler[]) handlers.toArray(new Handler[handlers.size()]); |
|
245 |
} |
|
382 | 246 |
|
383 |
/* |
|
384 |
* (non-Javadoc) |
|
385 |
* |
|
386 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans) |
|
387 |
*/ |
|
388 |
public void reProject(ICoordTrans ct) { |
|
389 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
390 |
((Geometry)geometries.get(i)).reProject(ct); |
|
391 |
} |
|
392 |
} |
|
247 |
/* |
|
248 |
* (non-Javadoc) |
|
249 |
* |
|
250 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getInternalShape() |
|
251 |
*/ |
|
252 |
public Shape getInternalShape() { |
|
253 |
return this; |
|
254 |
} |
|
393 | 255 |
|
394 |
/* |
|
395 |
* (non-Javadoc) |
|
396 |
* |
|
397 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#transform(java.awt.geom.AffineTransform) |
|
398 |
*/ |
|
399 |
public void transform(AffineTransform at) { |
|
400 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
401 |
((Geometry)geometries.get(i)).transform(at); |
|
402 |
} |
|
403 |
} |
|
256 |
/* |
|
257 |
* (non-Javadoc) |
|
258 |
* |
|
259 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(java.awt.geom.AffineTransform) |
|
260 |
*/ |
|
261 |
public PathIterator getPathIterator(AffineTransform at) { |
|
262 |
GeneralPathX gpx = new GeneralPathX(); |
|
263 |
int primiNum = getPrimitivesNumber(); |
|
264 |
if (primiNum > 0) { |
|
265 |
Point2D p = ((Geometry) geometries.get(0)).getHandlers(Geometry.SELECTHANDLER)[0] |
|
266 |
.getPoint(); |
|
267 |
gpx.moveTo(p.getX(), p.getY()); |
|
404 | 268 |
|
405 |
/* |
|
406 |
* (non-Javadoc) |
|
407 |
* |
|
408 |
* @see org.gvsig.geometries.iso.GM_Object#getBoundary() |
|
409 |
*/ |
|
410 |
public Envelope getEnvelope() { |
|
411 |
Envelope r = null; |
|
412 |
if (getPrimitivesNumber() > 0) { |
|
413 |
r = ((Geometry)geometries.get(0)).getEnvelope(); |
|
414 |
} |
|
415 |
for (int i = 1; i < getPrimitivesNumber(); i++) { |
|
416 |
Envelope r2 = ((Geometry)geometries.get(i)).getEnvelope(); |
|
417 |
r.add(r2); |
|
418 |
} |
|
419 |
return r; |
|
420 |
} |
|
269 |
for (int i = 1; i < primiNum; i++) { |
|
270 |
p = ((Geometry) geometries.get(i)).getHandlers(Geometry.SELECTHANDLER)[0] |
|
271 |
.getPoint(); |
|
272 |
gpx.lineTo(p.getX(), p.getY()); |
|
273 |
} |
|
274 |
Point2D p2 = ((Geometry) geometries.get(primiNum - 1)).getHandlers(Geometry.SELECTHANDLER)[((Geometry) geometries.get(primiNum - 1)).getHandlers(Geometry.SELECTHANDLER).length - 1] |
|
275 |
.getPoint(); |
|
276 |
gpx.lineTo(p2.getX(), p2.getY()); |
|
277 |
} |
|
278 |
return gpx.getPathIterator(at); |
|
279 |
} |
|
421 | 280 |
|
422 |
/** |
|
423 |
* @return the geometries |
|
424 |
* @deprecated |
|
425 |
*/ |
|
426 |
public Geometry[] getGeometries() { |
|
427 |
Geometry[] _geometries = new Geometry[geometries.size()]; |
|
428 |
for (int i=0 ; i<geometries.size() ; i++){ |
|
429 |
_geometries[i] = ((Geometry)geometries.get(i)); |
|
430 |
} |
|
431 |
return _geometries; |
|
432 |
} |
|
281 |
/* |
|
282 |
* (non-Javadoc) |
|
283 |
* |
|
284 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(java.awt.geom.AffineTransform, |
|
285 |
* double) |
|
286 |
*/ |
|
287 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
|
288 |
GeneralPathX gpx = new GeneralPathX(); |
|
289 |
int primiNum = getPrimitivesNumber(); |
|
290 |
if (primiNum > 0) { |
|
433 | 291 |
|
434 |
public FShape cloneFShape() { |
|
435 |
// TODO Auto-generated method stub |
|
436 |
return null; |
|
437 |
} |
|
292 |
Geometry prim = null; |
|
293 |
for (int i = 0; i < primiNum; i++) { |
|
294 |
prim = (Geometry) geometries.get(i); |
|
295 |
gpx.append( |
|
296 |
prim.getPathIterator(at, flatness), |
|
297 |
/* |
|
298 |
* This is a relevant change. |
|
299 |
* After BN 2056 this class will not return |
|
300 |
* connected path iterator. There will be MOVE_TO |
|
301 |
* between iterator of each primitive |
|
302 |
*/ |
|
303 |
false); |
|
304 |
} |
|
305 |
} |
|
306 |
/* |
|
307 |
* affine transform and flatness already applied in loop |
|
308 |
*/ |
|
309 |
return gpx.getPathIterator(null); |
|
310 |
} |
|
438 | 311 |
|
439 |
public Handler[] getSelectHandlers() { |
|
440 |
// TODO Auto-generated method stub |
|
441 |
return null; |
|
442 |
} |
|
312 |
/* |
|
313 |
* (non-Javadoc) |
|
314 |
* |
|
315 |
* @see org.gvsig.geometries.iso.aggregate.GM_Aggregate#getPrimitiveAt(int) |
|
316 |
*/ |
|
317 |
public Primitive getPrimitiveAt(int i) { |
|
318 |
if (i < getPrimitivesNumber()) { |
|
319 |
return (Primitive) ((Geometry) geometries.get(i)); |
|
320 |
} |
|
321 |
return null; |
|
322 |
} |
|
443 | 323 |
|
444 |
public Handler[] getStretchingHandlers() { |
|
445 |
// TODO Auto-generated method stub |
|
446 |
return null; |
|
447 |
} |
|
324 |
/* |
|
325 |
* (non-Javadoc) |
|
326 |
* |
|
327 |
* @see org.gvsig.geometries.iso.aggregate.GM_Aggregate#getPrimitivesNumber() |
|
328 |
*/ |
|
329 |
public int getPrimitivesNumber() { |
|
330 |
if (geometries == null) { |
|
331 |
return 0; |
|
332 |
} |
|
333 |
return geometries.size(); |
|
334 |
} |
|
448 | 335 |
|
449 |
public GeneralPathX getGeneralPath() { |
|
450 |
// TODO Auto-generated method stub |
|
451 |
return null; |
|
452 |
} |
|
336 |
/* |
|
337 |
* (non-Javadoc) |
|
338 |
* |
|
339 |
* @see java.awt.Shape#intersects(double, double, double, double) |
|
340 |
*/ |
|
341 |
public boolean intersects(double x, double y, double w, double h) { |
|
342 |
boolean bResul; |
|
343 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
453 | 344 |
|
345 |
try { |
|
346 |
bResul = containsRectangle((Geometry) geometries.get(i), x, y, w, h); |
|
347 |
} catch (GeometryOperationException e) { |
|
348 |
logger.error("While doing contains: " + e.getMessage(), e); |
|
349 |
bResul = true; |
|
350 |
} |
|
351 |
if (bResul) { |
|
352 |
return true; |
|
353 |
} |
|
354 |
} |
|
355 |
return false; |
|
356 |
} |
|
454 | 357 |
|
455 |
/* (non-Javadoc) |
|
456 |
* @see org.gvsig.fmap.geom.aggregate.MultiPrimitive#addPrimitive(org.gvsig.fmap.geom.primitive.Primitive) |
|
457 |
*/ |
|
458 |
public void addPrimitive(Primitive primitive) { |
|
459 |
geometries.add(primitive); |
|
460 |
} |
|
461 |
|
|
462 | 358 |
|
359 |
/* |
|
360 |
* (non-Javadoc) |
|
361 |
* |
|
362 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D) |
|
363 |
*/ |
|
364 |
public boolean intersects(Rectangle2D r) { |
|
365 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
463 | 366 |
|
367 |
Geometry prim = this.getPrimitiveAt(i); |
|
368 |
if (prim.intersects(r)) { |
|
369 |
return true; |
|
370 |
} |
|
371 |
} |
|
372 |
return false; |
|
373 |
} |
|
464 | 374 |
|
375 |
/* |
|
376 |
* (non-Javadoc) |
|
377 |
* |
|
378 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#isSimple() |
|
379 |
*/ |
|
380 |
public boolean isSimple() { |
|
381 |
return false; |
|
382 |
} |
|
465 | 383 |
|
384 |
/* |
|
385 |
* (non-Javadoc) |
|
386 |
* |
|
387 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans) |
|
388 |
*/ |
|
389 |
public void reProject(ICoordTrans ct) { |
|
390 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
391 |
((Geometry) geometries.get(i)).reProject(ct); |
|
392 |
} |
|
393 |
} |
|
394 |
|
|
395 |
/* |
|
396 |
* (non-Javadoc) |
|
397 |
* |
|
398 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#transform(java.awt.geom.AffineTransform) |
|
399 |
*/ |
|
400 |
public void transform(AffineTransform at) { |
|
401 |
for (int i = 0; i < getPrimitivesNumber(); i++) { |
|
402 |
((Geometry) geometries.get(i)).transform(at); |
|
403 |
} |
|
404 |
} |
|
405 |
|
|
406 |
/* |
|
407 |
* (non-Javadoc) |
|
408 |
* |
|
409 |
* @see org.gvsig.geometries.iso.GM_Object#getBoundary() |
|
410 |
*/ |
|
411 |
public Envelope getEnvelope() { |
|
412 |
Envelope r = null; |
|
413 |
if (getPrimitivesNumber() > 0) { |
|
414 |
r = ((Geometry) geometries.get(0)).getEnvelope(); |
|
415 |
} |
|
416 |
for (int i = 1; i < getPrimitivesNumber(); i++) { |
|
417 |
Envelope r2 = ((Geometry) geometries.get(i)).getEnvelope(); |
|
418 |
r.add(r2); |
|
419 |
} |
|
420 |
return r; |
|
421 |
} |
|
422 |
|
|
423 |
/** |
|
424 |
* @return the geometries |
|
425 |
* @deprecated |
|
426 |
*/ |
|
427 |
public Geometry[] getGeometries() { |
|
428 |
Geometry[] _geometries = new Geometry[geometries.size()]; |
|
429 |
for (int i = 0; i < geometries.size(); i++) { |
|
430 |
_geometries[i] = ((Geometry) geometries.get(i)); |
|
431 |
} |
|
432 |
return _geometries; |
|
433 |
} |
|
434 |
|
|
435 |
public FShape cloneFShape() { |
|
436 |
// TODO Auto-generated method stub |
|
437 |
return null; |
|
438 |
} |
|
439 |
|
|
440 |
public Handler[] getSelectHandlers() { |
|
441 |
// TODO Auto-generated method stub |
|
442 |
return null; |
|
443 |
} |
|
444 |
|
|
445 |
public Handler[] getStretchingHandlers() { |
|
446 |
// TODO Auto-generated method stub |
|
447 |
return null; |
|
448 |
} |
|
449 |
|
|
450 |
public GeneralPathX getGeneralPath() { |
|
451 |
// TODO Auto-generated method stub |
|
452 |
return null; |
|
453 |
} |
|
454 |
|
|
455 |
|
|
456 |
public void addPrimitive(Primitive primitive) { |
|
457 |
geometries.add(primitive); |
|
458 |
} |
|
459 |
|
|
460 |
public Geometry union() |
|
461 |
throws GeometryOperationException, GeometryOperationNotSupportedException { |
|
462 |
Geometry result = null; |
|
463 |
if (getPrimitivesNumber() > 0) { |
|
464 |
result = this.getPrimitiveAt(0); |
|
465 |
} |
|
466 |
for (int i = 1; i < getPrimitivesNumber(); i++) { |
|
467 |
Primitive geom = this.getPrimitiveAt(i); |
|
468 |
result = result.union(geom); |
|
469 |
} |
|
470 |
return result; |
|
471 |
} |
|
472 |
|
|
473 |
public Geometry intersection() |
|
474 |
throws GeometryOperationException, GeometryOperationNotSupportedException { |
|
475 |
Geometry result = null; |
|
476 |
if (getPrimitivesNumber() > 0) { |
|
477 |
result = this.getPrimitiveAt(0); |
|
478 |
} |
|
479 |
for (int i = 1; i < getPrimitivesNumber(); i++) { |
|
480 |
Primitive geom = this.getPrimitiveAt(i); |
|
481 |
result = result.intersection(geom); |
|
482 |
} |
|
483 |
return result; |
|
484 |
} |
|
485 |
|
|
486 |
public void ensureCapacity(int capacity) { |
|
487 |
// TODO |
|
488 |
} |
|
489 |
|
|
466 | 490 |
} |
Also available in: Unified diff