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