Revision 4976 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/ShpStrategy.java
ShpStrategy.java | ||
---|---|---|
185 | 185 |
// Otherwhise, we will not use it. |
186 | 186 |
boolean bUseSpatialIndex = false; |
187 | 187 |
sc = adapter.getShapeCount(); |
188 |
if (lyr.getSpatialIndex() != null) |
|
188 |
// if (lyr.getSpatialIndex() != null) AZABALA |
|
189 |
if(lyr.getISpatialIndex() != null) |
|
189 | 190 |
{ |
190 |
double areaExtent = extent.getWidth() * extent.getHeight(); |
|
191 |
double areaFullExtent = lyr.getFullExtent().getWidth() * |
|
192 |
lyr.getFullExtent().getHeight(); |
|
193 |
if (areaExtent < (areaFullExtent / 4.0)) |
|
194 |
{ |
|
195 |
Coordinate c1 = new Coordinate(extent.getMinX(), extent.getMinY()); |
|
196 |
Coordinate c2 = new Coordinate(extent.getMaxX(), extent.getMaxY()); |
|
197 |
Envelope env = new Envelope(c1, c2); |
|
198 |
lstIndexes = lyr.getSpatialIndex().query(env); |
|
191 |
if(isSpatialIndexNecessary(extent)){ |
|
192 |
lstIndexes = lyr.getISpatialIndex().query(extent); |
|
199 | 193 |
sc = lstIndexes.size(); |
200 | 194 |
bUseSpatialIndex = true; |
201 |
}
|
|
202 |
} |
|
195 |
}//if
|
|
196 |
}//if
|
|
203 | 197 |
int i; |
204 |
|
|
205 | 198 |
for (int aux = 0; aux < sc; aux++) { |
206 | 199 |
// Salimos si alguien cancela |
207 |
if(cancel != null){//azabala (por si acaso, al arreglar bug de process) |
|
200 |
if(cancel != null){ |
|
201 |
//azabala (por si acaso, al arreglar bug de process) |
|
208 | 202 |
if (cancel.isCanceled()) { |
209 | 203 |
break; |
210 | 204 |
} |
... | ... | |
218 | 212 |
{ |
219 | 213 |
i = aux; |
220 | 214 |
} |
221 |
|
|
222 | 215 |
bounds = shapeBounds.getShapeBounds(i); |
223 |
|
|
224 | 216 |
if (ct != null) { |
225 | 217 |
bounds = ct.convert(bounds); |
226 | 218 |
} |
227 |
|
|
228 | 219 |
if (XRectangle2D.intersectInclusive(extent, bounds)) { |
229 | 220 |
FSymbol symbol = l.getSymbol(i); |
230 | 221 |
|
... | ... | |
430 | 421 |
throws DriverException, VisitException { |
431 | 422 |
// Si hay un ?ndice espacial, lo usamos para hacer el query. |
432 | 423 |
FLyrVect lyr = (FLyrVect) capa; |
433 |
if (lyr.getSpatialIndex() == null) |
|
424 |
// if (lyr.getSpatialIndex() == null) AZABALA |
|
425 |
if (lyr.getISpatialIndex() == null) |
|
434 | 426 |
return super.queryByShape(g, relationship); |
435 | 427 |
|
436 | 428 |
long t1 = System.currentTimeMillis(); |
437 | 429 |
ReadableVectorial va = lyr.getSource(); |
438 | 430 |
ICoordTrans ct = lyr.getCoordTrans(); |
439 | 431 |
Rectangle2D bounds = g.getBounds2D(); |
440 |
Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY()); |
|
441 |
Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY()); |
|
442 |
Envelope env = new Envelope(c1, c2); |
|
443 |
|
|
444 |
List lstRecs = lyr.getSpatialIndex().query(env); |
|
432 |
// AZABALA |
|
433 |
// Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY()); |
|
434 |
// Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY()); |
|
435 |
// Envelope env = new Envelope(c1, c2); |
|
436 |
// List lstRecs = lyr.getSpatialIndex().query(env); |
|
437 |
List lstRecs = lyr.getISpatialIndex().query(bounds); |
|
445 | 438 |
Integer idRec; |
446 | 439 |
FBitSet bitset = new FBitSet(); |
447 | 440 |
Geometry jtsShape = g.toJTSGeometry(); |
... | ... | |
541 | 534 |
public FBitSet queryByRect(Rectangle2D rect, CancellableMonitorable cancel) throws DriverException { |
542 | 535 |
// Si hay un ?ndice espacial, lo usamos para hacer el query. |
543 | 536 |
FLyrVect lyr = (FLyrVect) capa; |
544 |
if (lyr.getSpatialIndex() == null) |
|
537 |
// if (lyr.getSpatialIndex() == null) |
|
538 |
if(lyr.getISpatialIndex() == null) |
|
545 | 539 |
return super.queryByRect(rect, cancel); |
546 | 540 |
|
547 | 541 |
ReadableVectorial va = lyr.getSource(); |
548 | 542 |
ICoordTrans ct = lyr.getCoordTrans(); |
549 | 543 |
Rectangle2D bounds = rect; |
550 |
Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY()); |
|
551 |
Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY()); |
|
552 |
Envelope env = new Envelope(c1, c2); |
|
553 |
|
|
554 |
List lstRecs = lyr.getSpatialIndex().query(env); |
|
544 |
// Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY()); |
|
545 |
// Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY()); |
|
546 |
// Envelope env = new Envelope(c1, c2); |
|
547 |
// List lstRecs = lyr.getSpatialIndex().query(env); |
|
548 |
// AZABALA |
|
549 |
List lstRecs = lyr.getISpatialIndex().query(bounds); |
|
555 | 550 |
Integer idRec; |
556 | 551 |
FBitSet bitset = new FBitSet(); |
557 | 552 |
int index; |
... | ... | |
601 | 596 |
process(visitor, rectangle, null); |
602 | 597 |
} |
603 | 598 |
|
599 |
/** |
|
600 |
* Tells when in a spatial query the use of an spatial index is an advanced, |
|
601 |
* or it would be better to use a secuential search. |
|
602 |
* <br> |
|
603 |
* The criteria to decide is the area of the query region. If it is less than |
|
604 |
* 1/4 of full extent layer region, the spatial index will be an improve. |
|
605 |
* Else, a secuential scan would be better |
|
606 |
* @param rectangle |
|
607 |
* @return |
|
608 |
* @throws DriverException |
|
609 |
*/ |
|
610 |
private boolean isSpatialIndexNecessary(Rectangle2D extent) throws DriverException{ |
|
611 |
FLyrVect lyr = (FLyrVect) getCapa(); |
|
612 |
double areaExtent = extent.getWidth() * extent.getHeight(); |
|
613 |
double areaFullExtent = lyr.getFullExtent().getWidth() * |
|
614 |
lyr.getFullExtent().getHeight(); |
|
615 |
return areaExtent < (areaFullExtent / 4.0); |
|
616 |
|
|
617 |
} |
|
604 | 618 |
|
619 |
|
|
605 | 620 |
/** |
606 | 621 |
* Processes (by calling visitor.process() method) only those |
607 | 622 |
* features of the vectorial layer associated which intersects given |
... | ... | |
611 | 626 |
|
612 | 627 |
public void process(FeatureVisitor visitor, Rectangle2D rectangle, CancellableMonitorable cancel) throws DriverException, VisitException { |
613 | 628 |
FLyrVect lyr = (FLyrVect) capa; |
614 |
if (lyr.getSpatialIndex() == null){ |
|
629 |
//if we dont have spatial index or... |
|
630 |
if (lyr.getISpatialIndex() == null){ |
|
615 | 631 |
super.process(visitor, rectangle, cancel); |
616 | 632 |
return; |
617 |
} |
|
633 |
} |
|
634 |
//if spatial index is not worthy |
|
635 |
if(! isSpatialIndexNecessary(rectangle)){ |
|
636 |
super.process(visitor, rectangle, cancel); |
|
637 |
return; |
|
638 |
} |
|
618 | 639 |
|
619 | 640 |
ReadableVectorial va = lyr.getSource(); |
620 | 641 |
ICoordTrans ct = lyr.getCoordTrans(); |
621 | 642 |
Rectangle2D bounds = rectangle; |
622 |
Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY()); |
|
623 |
Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY()); |
|
624 |
Envelope env = new Envelope(c1, c2); |
|
625 |
List lstRecs = lyr.getSpatialIndex().query(env); |
|
643 |
List lstRecs = lyr.getISpatialIndex().query(bounds); |
|
626 | 644 |
Integer idRec; |
627 | 645 |
int index; |
628 | 646 |
try { |
Also available in: Unified diff