svn-gvsig-desktop / tags / v1_1_Build_1008 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / ShpStrategy.java @ 12520
History | View | Annotate | Download (23.2 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.operations.strategies; |
42 |
|
43 |
import java.awt.Graphics2D; |
44 |
import java.awt.geom.Point2D; |
45 |
import java.awt.geom.Rectangle2D; |
46 |
import java.awt.image.BufferedImage; |
47 |
import java.io.IOException; |
48 |
import java.util.BitSet; |
49 |
import java.util.List; |
50 |
|
51 |
import javax.print.attribute.PrintRequestAttributeSet; |
52 |
|
53 |
import org.apache.log4j.Logger; |
54 |
import org.cresques.cts.ICoordTrans; |
55 |
import org.geotools.resources.geometry.XRectangle2D; |
56 |
|
57 |
import com.hardcode.driverManager.DriverLoadException; |
58 |
import com.iver.cit.gvsig.fmap.DriverException; |
59 |
import com.iver.cit.gvsig.fmap.ViewPort; |
60 |
import com.iver.cit.gvsig.fmap.core.FShape; |
61 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
62 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
63 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
64 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
65 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
66 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
67 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
68 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
70 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
71 |
import com.iver.cit.gvsig.fmap.layers.SpatialCache; |
72 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
73 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
74 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
75 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
76 |
import com.iver.utiles.swing.threads.Cancellable; |
77 |
import com.iver.utiles.swing.threads.CancellableMonitorable; |
78 |
import com.vividsolutions.jts.geom.Geometry; |
79 |
import com.vividsolutions.jts.geom.IntersectionMatrix; |
80 |
|
81 |
/**
|
82 |
* Esta clase definir? las operaciones de la interfaz FLyrVect de la manera m?s
|
83 |
* ?ptima para los ficheros shp.
|
84 |
*/
|
85 |
public class ShpStrategy extends DefaultStrategy { |
86 |
private static Logger logger = Logger |
87 |
.getLogger(ShpStrategy.class.getName()); |
88 |
|
89 |
/**
|
90 |
* Crea una ShpStrategy.
|
91 |
*
|
92 |
* @param capa
|
93 |
*/
|
94 |
public ShpStrategy(FLayer capa) {
|
95 |
super(capa);
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
100 |
* java.awt.Graphics2D, ISymbol)
|
101 |
*/
|
102 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
103 |
Cancellable cancel) throws DriverException {
|
104 |
try {
|
105 |
ReadableVectorial adapter = ((SingleLayer) getCapa()).getSource(); |
106 |
if (adapter.getShapeCount() <= 0) { |
107 |
// logger.info("Layer:" + getCapa().getName() + " sin
|
108 |
// registros");
|
109 |
return;
|
110 |
} |
111 |
|
112 |
// Selectable selection = (Selectable) getCapa();
|
113 |
FLyrVect lyr = (FLyrVect) getCapa(); |
114 |
Selectable selectable = lyr.getRecordset(); |
115 |
ICoordTrans ct = getCapa().getCoordTrans(); |
116 |
FBitSet bitSet = selectable.getSelection(); |
117 |
BoundedShapes shapeBounds; |
118 |
if (adapter instanceof BoundedShapes) |
119 |
shapeBounds = (BoundedShapes) adapter; |
120 |
else
|
121 |
shapeBounds = (BoundedShapes) adapter.getDriver(); |
122 |
// VectorialFileDriver driver = (VectorialFileDriver)
|
123 |
// adapter.getDriver();
|
124 |
// logger.debug("adapter.start() -> Layer:" + getCapa().getName());
|
125 |
adapter.start(); |
126 |
IGeometry geom; |
127 |
// if (adapter.getShapeCount() > 0) {
|
128 |
// geom = adapter.getShape(0);
|
129 |
// }
|
130 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) getCapa()) |
131 |
.getLegend(); |
132 |
|
133 |
// if (l instanceof ClassifiedLegendInfo) {
|
134 |
// ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) l;
|
135 |
// ISymbol[] symbs = clsfLegend.getSymbols();
|
136 |
// // double rSym = 0;
|
137 |
// // double maxRSym = -1;
|
138 |
//
|
139 |
// for (int i = 0; i < symbs.length; i++) {
|
140 |
// // TODO: REVISAR LOS SIMBOLOS Y SUS TAMA?OS
|
141 |
//
|
142 |
// /*
|
143 |
// * Style2D pointSymbol = symbs[i].getPointStyle2D(); if
|
144 |
// * (pointSymbol instanceof MarkStyle2D) { MarkStyle2D mrk2D =
|
145 |
// * (MarkStyle2D) pointSymbol; rSym =
|
146 |
// * viewPort.toMapDistance(mrk2D.getSize()); if (maxRSym <
|
147 |
// * rSym) maxRSym = rSym; }
|
148 |
// */
|
149 |
// }
|
150 |
// }
|
151 |
|
152 |
Rectangle2D extent = viewPort.getAdjustedExtent();
|
153 |
// AffineTransform at = viewPort.getAffineTransform();
|
154 |
|
155 |
int sc;
|
156 |
|
157 |
Rectangle2D bounds;
|
158 |
|
159 |
long t1 = System.currentTimeMillis(); |
160 |
// logger.debug("getCapa().getRecordset().start()");
|
161 |
|
162 |
//CHEMA
|
163 |
// En teorioa el al hacer el adapter.start()
|
164 |
// deja abierta las fuentes de datos
|
165 |
// geometrica y alfanumerica (cuando no son la misma
|
166 |
// excepto cuando se ha hecho una operacion de 'join' de la tabla
|
167 |
// (join de las tablas de gvsig(gdbms) no join de sql), entoces
|
168 |
// el origen alfanumerico no es el mismo en el source
|
169 |
// que en la capa.
|
170 |
//
|
171 |
//((FLyrVect) getCapa()).getRecordset().start();
|
172 |
if (lyr.isJoined()){
|
173 |
lyr.getRecordset().start(); |
174 |
} |
175 |
//CHEMA
|
176 |
|
177 |
// TODO: A revisar si es o no conveniente este sistema
|
178 |
// de comunicaci?n con los drivers.
|
179 |
DriverAttributes attr = adapter.getDriverAttributes(); |
180 |
boolean bMustClone = false; |
181 |
if (attr != null) { |
182 |
if (attr.isLoadedInMemory()) {
|
183 |
bMustClone = attr.isLoadedInMemory(); |
184 |
} |
185 |
} |
186 |
|
187 |
List lstIndexes = null; |
188 |
|
189 |
// If area of needed extent is less than fullExtent / 4,
|
190 |
// it will be worthy to use SpatialIndex.
|
191 |
// Otherwhise, we will not use it.
|
192 |
boolean bUseSpatialIndex = false; |
193 |
sc = adapter.getShapeCount(); |
194 |
// if (lyr.getSpatialIndex() != null) AZABALA
|
195 |
// long t11 = System.currentTimeMillis();
|
196 |
if (lyr.getISpatialIndex() != null) { |
197 |
if (isSpatialIndexNecessary(extent)) {
|
198 |
lstIndexes = lyr.getISpatialIndex().query(extent); |
199 |
// If the layer is reprojected, spatial index was created
|
200 |
// in its own projection, so we must to apply an inverse
|
201 |
// transform
|
202 |
if (ct != null) { |
203 |
Rectangle2D newExtent = ct.getInverted()
|
204 |
.convert(extent); |
205 |
// Rectangle2D newExtent = ct.convert(extent);
|
206 |
// lstIndexes = lyr.getISpatialIndex().query(extent);
|
207 |
lstIndexes = lyr.getISpatialIndex().query(newExtent); |
208 |
} else {
|
209 |
lstIndexes = lyr.getISpatialIndex().query(extent); |
210 |
} |
211 |
sc = lstIndexes.size(); |
212 |
bUseSpatialIndex = true;
|
213 |
}// if
|
214 |
}// if
|
215 |
/*
|
216 |
* long t12 = System.currentTimeMillis(); System.out.println("Tiempo
|
217 |
* en mirar el ?ndice espacial y recuperar los ?ndices:" +
|
218 |
* (t12-t11)); System.out.println("Numero de ?ndices:" + sc);
|
219 |
*/
|
220 |
|
221 |
// SpatialCache cache = lyr.createSpatialCache();
|
222 |
lyr.getSpatialCache().clearAll(); |
223 |
SpatialCache cache = lyr.getSpatialCache(); |
224 |
int i;
|
225 |
|
226 |
// En OS X con renderer Quartz (JRE<6), mezclar setRGB con dibujado
|
227 |
// geometrico en mismo BufferedImage
|
228 |
// provoca ralentizaci?n brutal. Lo evitamos separando los setRGB en
|
229 |
// otro BufferedImage y juntandolos luego.
|
230 |
boolean MAC_OS_X = System.getProperty("os.name").toLowerCase() |
231 |
.startsWith("mac os x");
|
232 |
BufferedImage auxBI = null; |
233 |
if (MAC_OS_X) {
|
234 |
auxBI = new BufferedImage(image.getWidth(), image.getHeight(), |
235 |
image.getType()); |
236 |
} |
237 |
for (int aux = 0; aux < sc; aux++) { |
238 |
// Salimos si alguien cancela
|
239 |
|
240 |
if (cancel != null) { |
241 |
// azabala (por si acaso, al arreglar bug de process)
|
242 |
if (cancel.isCanceled()) {
|
243 |
return;
|
244 |
} |
245 |
} |
246 |
if (bUseSpatialIndex) {
|
247 |
Integer idRec = (Integer) lstIndexes.get(aux); |
248 |
i = idRec.intValue(); |
249 |
} else {
|
250 |
i = aux; |
251 |
} |
252 |
if (getCapa().isEditing())
|
253 |
bounds=adapter.getShape(i).getBounds2D(); |
254 |
else
|
255 |
bounds = shapeBounds.getShapeBounds(i); |
256 |
if (ct != null) { |
257 |
bounds = ct.convert(bounds); |
258 |
} |
259 |
if (XRectangle2D.intersectInclusive(extent, bounds)) {
|
260 |
ISymbol symbol = l.getSymbol(i); |
261 |
if (symbol == null) |
262 |
continue;
|
263 |
|
264 |
if (bitSet.get(i)) {
|
265 |
symbol = symbol.getSymbolForSelection(); |
266 |
} |
267 |
|
268 |
|
269 |
|
270 |
boolean bPoint = (shapeBounds.getShapeType(i) == FShape.POINT);
|
271 |
|
272 |
if (bPoint
|
273 |
|| ((bounds.getHeight() > viewPort.getDist1pixel()) || (bounds |
274 |
.getWidth() > viewPort.getDist1pixel()))) { |
275 |
geom = adapter.getShape(i); |
276 |
|
277 |
// PRUEBA DE VELOCIDAD
|
278 |
// geom = ShapeFactory.createPolygon2D(new
|
279 |
// GeneralPathX(bounds));
|
280 |
|
281 |
|
282 |
//JMVIVO: OJO, No colnamos siempre porque
|
283 |
// el FGeometry.drawInt (a diferencia del
|
284 |
// FGeometry.draw) clona siempre la geometria
|
285 |
// antes de pintarla (para transforma a enteros)
|
286 |
if (ct != null) { |
287 |
if (bMustClone)
|
288 |
geom = geom.cloneGeometry(); |
289 |
geom.reProject(ct); |
290 |
} |
291 |
if (lyr.isSpatialCacheEnabled()) {
|
292 |
if (cache.getMaxFeatures() >= cache.size()) {
|
293 |
// Ya reproyectado todo
|
294 |
cache.insert(bounds, geom); |
295 |
} |
296 |
} |
297 |
|
298 |
// FJP: CAMBIO: Sabemos que vamos a dibujar sobre una
|
299 |
// imagen, con coordenadas enteras, as?
|
300 |
// que lo tenemos en cuenta.
|
301 |
// ANTES: geom.draw(g, viewPort, symbol);
|
302 |
// AHORA:
|
303 |
geom.drawInts(g, viewPort, symbol); |
304 |
// geom.draw(g, viewPort, symbol);
|
305 |
/*
|
306 |
* if (lyr.isEditing()) { if (bitSet.get(i)) { Handler[]
|
307 |
* handlers = geom.getHandlers(IGeometry.SELECTHANDLER);
|
308 |
* FGraphicUtilities.DrawHandlers(g,
|
309 |
* viewPort.getAffineTransform(), handlers); } }
|
310 |
*/
|
311 |
|
312 |
} else {
|
313 |
Point2D.Double pOrig = new Point2D.Double(bounds |
314 |
.getMinX(), bounds.getMinY()); |
315 |
Point2D pDest, pDest2;
|
316 |
|
317 |
pDest = viewPort.getAffineTransform().transform(pOrig, |
318 |
null);
|
319 |
pDest2 = g.getTransform().transform(pDest, null);
|
320 |
|
321 |
int pixX = (int) pDest2.getX(); |
322 |
int pixY = (int) pDest2.getY(); |
323 |
if (symbol == null) |
324 |
continue;
|
325 |
if ((pixX > 0) && (pixX < image.getWidth())) { |
326 |
if ((pixY > 0) && (pixY < image.getHeight())) { |
327 |
if (MAC_OS_X) {
|
328 |
auxBI.setRGB(pixX, pixY, symbol |
329 |
.getOnePointRgb()); |
330 |
} else {
|
331 |
image.setRGB(pixX, pixY, symbol |
332 |
.getOnePointRgb()); |
333 |
} |
334 |
} |
335 |
} |
336 |
} |
337 |
} |
338 |
} |
339 |
|
340 |
if (MAC_OS_X) {
|
341 |
g.drawImage(auxBI, 0, 0, null); |
342 |
} |
343 |
|
344 |
// logger.debug("getCapa().getRecordset().stop()");
|
345 |
//CHEMA
|
346 |
// Cerramos la fuente alfanumerica cuando se ha hecho
|
347 |
// una operacion de 'join'
|
348 |
//((FLyrVect) getCapa()).getSource().getRecordset().stop();
|
349 |
if (lyr.isJoined()){
|
350 |
lyr.getRecordset().stop(); |
351 |
} |
352 |
//CHEMA
|
353 |
|
354 |
long t2 = System.currentTimeMillis(); |
355 |
// logger.debug("adapter.stop()");
|
356 |
adapter.stop(); |
357 |
|
358 |
// System.out.println(t2 - t1);
|
359 |
} catch (DriverIOException e) {
|
360 |
throw new DriverException(e); |
361 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
362 |
throw new DriverException(e); |
363 |
} catch (DriverException e) {
|
364 |
throw new DriverException(e); |
365 |
} catch (IOException e) { |
366 |
throw new DriverException(e); |
367 |
} catch (DriverLoadException e) {
|
368 |
// TODO Auto-generated catch block
|
369 |
e.printStackTrace(); |
370 |
} |
371 |
} |
372 |
|
373 |
/**
|
374 |
* M?todo utilizado para dibujar sobre el graphics que se pasa como
|
375 |
* par?metro, pensado para utilizarse para imprimir.
|
376 |
*
|
377 |
* @param g
|
378 |
* Graphics2D
|
379 |
* @param viewPort
|
380 |
* ViewPort.
|
381 |
* @param cancel
|
382 |
*
|
383 |
* @throws DriverException
|
384 |
*/
|
385 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
386 |
PrintRequestAttributeSet printProperties) throws DriverException { |
387 |
// super.draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del
|
388 |
// padre, que es el que va sin acelaraci?n!!
|
389 |
try {
|
390 |
ReadableVectorial adapter = ((SingleLayer) getCapa()).getSource(); |
391 |
if (adapter.getShapeCount() <= 0) { |
392 |
// logger.info("Layer:" + getCapa().getName() + " sin
|
393 |
// registros");
|
394 |
return;
|
395 |
} |
396 |
FLyrVect lyr = (FLyrVect) getCapa(); |
397 |
lyr.beforePrinting(printProperties); |
398 |
|
399 |
Selectable selectable = lyr.getRecordset(); |
400 |
ICoordTrans ct = getCapa().getCoordTrans(); |
401 |
BitSet bitSet = selectable.getSelection();
|
402 |
BoundedShapes shapeBounds = (BoundedShapes) adapter.getDriver(); |
403 |
VectorialDriver driver = (VectorialDriver) adapter |
404 |
.getDriver(); |
405 |
// logger.debug("adapter.start() -> Layer:" + getCapa().getName());
|
406 |
adapter.start(); |
407 |
IGeometry geom; |
408 |
if (adapter.getShapeCount() > 0) { |
409 |
geom = adapter.getShape(0);
|
410 |
} |
411 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) getCapa()) |
412 |
.getLegend(); |
413 |
|
414 |
Rectangle2D extent = viewPort.getAdjustedExtent();
|
415 |
// AffineTransform at = viewPort.getAffineTransform();
|
416 |
|
417 |
int sc;
|
418 |
|
419 |
Rectangle2D bounds;
|
420 |
|
421 |
sc = adapter.getShapeCount(); |
422 |
|
423 |
long t1 = System.currentTimeMillis(); |
424 |
// logger.debug("getCapa().getRecordset().start()");
|
425 |
|
426 |
//CHEMA
|
427 |
// En teorioa el al hacer el adapter.start()
|
428 |
// deja abierta las fuentes de datos
|
429 |
// geometrica y alfanumerica (cuando no son la misma
|
430 |
// excepto cuando se ha hecho una operacion de 'join' de la tabla
|
431 |
// (join de las tablas de gvsig(gdbms) no join de sql), entoces
|
432 |
// el origen alfanumerico no es el mismo en el source
|
433 |
// que en la capa.
|
434 |
//
|
435 |
//((FLyrVect) getCapa()).getRecordset().start();
|
436 |
if (lyr.isJoined()){
|
437 |
lyr.getRecordset().start(); |
438 |
} |
439 |
//CHEMA
|
440 |
|
441 |
|
442 |
// TODO: A revisar si es o no conveniente este sistema
|
443 |
// de comunicaci?n con los drivers.
|
444 |
DriverAttributes attr = adapter.getDriverAttributes(); |
445 |
boolean bMustClone = false; |
446 |
if (attr != null) { |
447 |
if (attr.isLoadedInMemory()) {
|
448 |
bMustClone = attr.isLoadedInMemory(); |
449 |
} |
450 |
} |
451 |
|
452 |
List lstIndexes = null; |
453 |
|
454 |
boolean bUseSpatialIndex = false; |
455 |
if (lyr.getISpatialIndex() != null) { |
456 |
if (isSpatialIndexNecessary(extent)) {
|
457 |
lstIndexes = lyr.getISpatialIndex().query(extent); |
458 |
if (ct != null) { |
459 |
Rectangle2D newExtent = ct.getInverted()
|
460 |
.convert(extent); |
461 |
lstIndexes = lyr.getISpatialIndex().query(newExtent); |
462 |
} else {
|
463 |
lstIndexes = lyr.getISpatialIndex().query(extent); |
464 |
} |
465 |
sc = lstIndexes.size(); |
466 |
bUseSpatialIndex = true;
|
467 |
}// if
|
468 |
}// if
|
469 |
|
470 |
int i;
|
471 |
for (int aux = 0; aux < sc; aux++) { |
472 |
if (bUseSpatialIndex) {
|
473 |
Integer idRec = (Integer) lstIndexes.get(aux); |
474 |
i = idRec.intValue(); |
475 |
} else {
|
476 |
i = aux; |
477 |
} |
478 |
|
479 |
bounds = shapeBounds.getShapeBounds(i); |
480 |
|
481 |
if (ct != null) { |
482 |
bounds = ct.convert(bounds); |
483 |
} |
484 |
|
485 |
if (XRectangle2D.intersectInclusive(extent, bounds)) {
|
486 |
ISymbol symbol = l.getSymbol(i); |
487 |
if (symbol == null) |
488 |
continue;
|
489 |
if (bitSet.get(i)) {
|
490 |
symbol = symbol.getSymbolForSelection(); |
491 |
} |
492 |
|
493 |
//boolean bPoint = (shapeBounds.getShapeType(i) == FShape.POINT);
|
494 |
|
495 |
geom = driver.getShape(i); |
496 |
|
497 |
// PRUEBA DE VELOCIDAD
|
498 |
// geom = ShapeFactory.createPolygon2D(new
|
499 |
// GeneralPathX(bounds));
|
500 |
|
501 |
// JMVIVO: Clonamos siempre que sea necesario y no
|
502 |
// solo si hay que reproyectar. Porque el FGeometry.draw
|
503 |
// va a aplicar la transformacion sobre la geometria original
|
504 |
if (bMustClone)
|
505 |
geom = geom.cloneGeometry(); |
506 |
|
507 |
if (ct != null) { |
508 |
geom.reProject(ct); |
509 |
} |
510 |
|
511 |
geom.draw(g, viewPort, symbol); |
512 |
|
513 |
} |
514 |
} |
515 |
|
516 |
// logger.debug("getCapa().getRecordset().stop()");
|
517 |
//CHEMA
|
518 |
// Cerramos la fuente alfanumerica cuando se ha hecho
|
519 |
// una operacion de 'join'
|
520 |
//((FLyrVect) getCapa()).getSource().getRecordset().stop();
|
521 |
if (lyr.isJoined()){
|
522 |
lyr.getRecordset().stop(); |
523 |
} |
524 |
//CHEMA
|
525 |
|
526 |
long t2 = System.currentTimeMillis(); |
527 |
// logger.debug("adapter.stop()");
|
528 |
adapter.stop(); |
529 |
lyr.afterPrinting(); |
530 |
// System.out.println(t2 - t1);
|
531 |
} catch (DriverIOException e) {
|
532 |
throw new DriverException(e); |
533 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
534 |
throw new DriverException(e); |
535 |
} catch (DriverException e) {
|
536 |
throw new DriverException(e); |
537 |
} catch (IOException e) { |
538 |
throw new DriverException(e); |
539 |
} |
540 |
|
541 |
} |
542 |
|
543 |
public FBitSet queryByShape(IGeometry g, int relationship) |
544 |
throws DriverException, VisitException {
|
545 |
return queryByShape(g, relationship, null); |
546 |
} |
547 |
|
548 |
/*
|
549 |
* (non-Javadoc)
|
550 |
*
|
551 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.core.IGeometry,
|
552 |
* int)
|
553 |
*/
|
554 |
public FBitSet queryByShape(IGeometry g, int relationship, |
555 |
CancellableMonitorable cancel) throws DriverException,
|
556 |
VisitException { |
557 |
// Si hay un ?ndice espacial, lo usamos para hacer el query.
|
558 |
FLyrVect lyr = (FLyrVect) capa; |
559 |
// if (lyr.getSpatialIndex() == null) AZABALA
|
560 |
if (lyr.getISpatialIndex() == null) |
561 |
return super.queryByShape(g, relationship, null); |
562 |
|
563 |
long t1 = System.currentTimeMillis(); |
564 |
ReadableVectorial va = lyr.getSource(); |
565 |
ICoordTrans ct = lyr.getCoordTrans(); |
566 |
Rectangle2D bounds = g.getBounds2D();
|
567 |
List lstRecs = lyr.getISpatialIndex().query(bounds);
|
568 |
Integer idRec;
|
569 |
FBitSet bitset = new FBitSet();
|
570 |
Geometry jtsShape = g.toJTSGeometry(); |
571 |
IntersectionMatrix m; |
572 |
int index;
|
573 |
try {
|
574 |
va.start(); |
575 |
|
576 |
for (int i = 0; i < lstRecs.size(); i++) { |
577 |
if (cancel != null) { |
578 |
cancel.reportStep(); |
579 |
if (cancel.isCanceled()) {
|
580 |
break;
|
581 |
} |
582 |
} |
583 |
idRec = (Integer) lstRecs.get(i);
|
584 |
index = idRec.intValue(); |
585 |
IGeometry geom = va.getShape(index); |
586 |
if (geom == null) |
587 |
continue;
|
588 |
if (ct != null) { |
589 |
geom.reProject(ct); |
590 |
} |
591 |
Geometry jtsGeom = geom.toJTSGeometry(); |
592 |
switch (relationship) {
|
593 |
case CONTAINS:
|
594 |
m = jtsShape.relate(jtsGeom); |
595 |
if (m.isContains()) {
|
596 |
bitset.set(index, true);
|
597 |
} |
598 |
break;
|
599 |
|
600 |
case CROSSES:
|
601 |
m = jtsShape.relate(jtsGeom); |
602 |
if (m.isCrosses(jtsGeom.getDimension(), jtsShape
|
603 |
.getDimension())) { |
604 |
bitset.set(index, true);
|
605 |
} |
606 |
break;
|
607 |
|
608 |
case DISJOINT:
|
609 |
// TODO: CREO QUE EL DISJOINT NO SE PUEDE METER AQUI
|
610 |
m = jtsShape.relate(jtsGeom); |
611 |
if (m.isDisjoint()) {
|
612 |
bitset.set(index, true);
|
613 |
} |
614 |
break;
|
615 |
|
616 |
case EQUALS:
|
617 |
m = jtsShape.relate(jtsGeom); |
618 |
if (m.isEquals(jtsGeom.getDimension(), jtsShape
|
619 |
.getDimension())) { |
620 |
bitset.set(index, true);
|
621 |
} |
622 |
break;
|
623 |
|
624 |
case INTERSECTS:
|
625 |
m = jtsShape.relate(jtsGeom); |
626 |
if (m.isIntersects()) {
|
627 |
bitset.set(index, true);
|
628 |
} |
629 |
break;
|
630 |
|
631 |
case OVERLAPS:
|
632 |
m = jtsShape.relate(jtsGeom); |
633 |
if (m.isOverlaps(jtsGeom.getDimension(), jtsShape
|
634 |
.getDimension())) { |
635 |
bitset.set(index, true);
|
636 |
} |
637 |
|
638 |
break;
|
639 |
|
640 |
case TOUCHES:
|
641 |
m = jtsShape.relate(jtsGeom); |
642 |
if (m.isTouches(jtsGeom.getDimension(), jtsShape
|
643 |
.getDimension())) { |
644 |
bitset.set(index, true);
|
645 |
} |
646 |
|
647 |
break;
|
648 |
|
649 |
case WITHIN:
|
650 |
m = jtsShape.relate(jtsGeom); |
651 |
if (m.isWithin()) {
|
652 |
bitset.set(index, true);
|
653 |
} |
654 |
|
655 |
break;
|
656 |
} |
657 |
} |
658 |
va.stop(); |
659 |
} catch (DriverIOException e) {
|
660 |
// TODO Auto-generated catch block
|
661 |
e.printStackTrace(); |
662 |
} |
663 |
long t2 = System.currentTimeMillis(); |
664 |
// logger.info("queryByShape optimizado sobre la capa " + lyr.getName()
|
665 |
// + ". " + (t2 - t1) + " mseg.");
|
666 |
return bitset;
|
667 |
} |
668 |
|
669 |
public FBitSet queryByRect(Rectangle2D rect, CancellableMonitorable cancel) |
670 |
throws DriverException {
|
671 |
// Si hay un ?ndice espacial, lo usamos para hacer el query.
|
672 |
FLyrVect lyr = (FLyrVect) capa; |
673 |
if (lyr.getISpatialIndex() == null) |
674 |
return super.queryByRect(rect, cancel); |
675 |
|
676 |
ReadableVectorial va = lyr.getSource(); |
677 |
ICoordTrans ct = lyr.getCoordTrans(); |
678 |
Rectangle2D bounds = rect;
|
679 |
List lstRecs = lyr.getISpatialIndex().query(bounds);
|
680 |
Integer idRec;
|
681 |
FBitSet bitset = new FBitSet();
|
682 |
int index;
|
683 |
try {
|
684 |
va.start(); |
685 |
DriverAttributes attr = va.getDriverAttributes(); |
686 |
boolean bMustClone = false; |
687 |
if (attr != null) { |
688 |
if (attr.isLoadedInMemory()) {
|
689 |
bMustClone = attr.isLoadedInMemory(); |
690 |
} |
691 |
} |
692 |
|
693 |
for (int i = 0; i < lstRecs.size(); i++) { |
694 |
if (cancel != null) { |
695 |
cancel.reportStep(); |
696 |
if (cancel.isCanceled()) {
|
697 |
va.stop(); |
698 |
return bitset;
|
699 |
} |
700 |
} |
701 |
idRec = (Integer) lstRecs.get(i);
|
702 |
index = idRec.intValue(); |
703 |
IGeometry geom = va.getShape(index); |
704 |
if (geom == null)// azabala |
705 |
continue;
|
706 |
if (ct != null) { |
707 |
if (bMustClone)
|
708 |
geom = geom.cloneGeometry(); |
709 |
geom.reProject(ct); |
710 |
} |
711 |
if (geom.intersects(rect))
|
712 |
bitset.set(index, true);
|
713 |
} |
714 |
va.stop(); |
715 |
} catch (DriverIOException e) {
|
716 |
// TODO Auto-generated catch block
|
717 |
e.printStackTrace(); |
718 |
} |
719 |
return bitset;
|
720 |
|
721 |
} |
722 |
|
723 |
public void process(FeatureVisitor visitor, Rectangle2D rectangle) |
724 |
throws DriverException, VisitException {
|
725 |
process(visitor, rectangle, null);
|
726 |
} |
727 |
|
728 |
/**
|
729 |
* Processes (by calling visitor.process() method) only those features of
|
730 |
* the vectorial layer associated which intersects given rectangle2d.
|
731 |
*
|
732 |
*/
|
733 |
|
734 |
public void process(FeatureVisitor visitor, Rectangle2D rectangle, |
735 |
CancellableMonitorable cancel) throws DriverException,
|
736 |
VisitException { |
737 |
if (visitor.start(capa)) {
|
738 |
FLyrVect lyr = (FLyrVect) capa; |
739 |
// if we dont have spatial index or...
|
740 |
if (lyr.getISpatialIndex() == null) { |
741 |
super.process(visitor, rectangle, cancel);
|
742 |
return;
|
743 |
} |
744 |
// if spatial index is not worthy
|
745 |
if (!isSpatialIndexNecessary(rectangle)) {
|
746 |
super.process(visitor, rectangle, cancel);
|
747 |
return;
|
748 |
} |
749 |
|
750 |
ReadableVectorial va = lyr.getSource(); |
751 |
ICoordTrans ct = lyr.getCoordTrans(); |
752 |
Rectangle2D bounds = rectangle;
|
753 |
List lstRecs = lyr.getISpatialIndex().query(bounds);
|
754 |
Integer idRec;
|
755 |
int index;
|
756 |
try {
|
757 |
va.start(); |
758 |
DriverAttributes attr = va.getDriverAttributes(); |
759 |
boolean bMustClone = false; |
760 |
if (attr != null) { |
761 |
if (attr.isLoadedInMemory()) {
|
762 |
bMustClone = attr.isLoadedInMemory(); |
763 |
} |
764 |
} |
765 |
|
766 |
for (int i = 0; i < lstRecs.size(); i++) { |
767 |
if (cancel != null) { |
768 |
cancel.reportStep(); |
769 |
} |
770 |
if (verifyCancelation(cancel, va, visitor))
|
771 |
return;
|
772 |
idRec = (Integer) lstRecs.get(i);
|
773 |
index = idRec.intValue(); |
774 |
IGeometry geom = va.getShape(index); |
775 |
if (geom == null)// azabala |
776 |
continue;
|
777 |
if (ct != null) { |
778 |
if (bMustClone)
|
779 |
geom = geom.cloneGeometry(); |
780 |
geom.reProject(ct); |
781 |
} |
782 |
if (geom.intersects(rectangle))
|
783 |
visitor.visit(geom, index); |
784 |
}// for
|
785 |
va.stop(); |
786 |
} catch (DriverIOException e) {
|
787 |
// TODO Auto-generated catch block
|
788 |
e.printStackTrace(); |
789 |
} |
790 |
}// if visitor.start
|
791 |
} |
792 |
|
793 |
/*
|
794 |
* (non-Javadoc)
|
795 |
*
|
796 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(java.awt.geom.Point2D,
|
797 |
* double)
|
798 |
*/
|
799 |
public FBitSet queryByPoint(Point2D p, double tolerance, |
800 |
CancellableMonitorable cancel) throws DriverException {
|
801 |
// TODO: OJO!!!!. Est? implementado como un rectangulo.
|
802 |
// Lo correcto deber?a ser calculando las distancias reales
|
803 |
// es decir, con un c?rculo.
|
804 |
Rectangle2D recPoint = new Rectangle2D.Double(p.getX() |
805 |
- (tolerance / 2), p.getY() - (tolerance / 2), tolerance, |
806 |
tolerance); |
807 |
return queryByRect(recPoint, cancel);
|
808 |
} |
809 |
} |