svn-gvsig-desktop / tags / v1_1_Build_1015 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / SpatialCache.java @ 13679
History | View | Annotate | Download (1.39 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
|
5 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
6 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
7 |
import com.vividsolutions.jts.geom.Envelope; |
8 |
import com.vividsolutions.jts.index.ItemVisitor; |
9 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
10 |
|
11 |
public class SpatialCache { |
12 |
int maxFeatures = 1000; // Por defecto, pero se puede cambiar |
13 |
int fastNumTotalRegs=0; |
14 |
Quadtree quadTree = new Quadtree();
|
15 |
|
16 |
public int getMaxFeatures() { |
17 |
return maxFeatures;
|
18 |
} |
19 |
|
20 |
public void setMaxFeatures(int maxFeatures) { |
21 |
this.maxFeatures = maxFeatures;
|
22 |
} |
23 |
|
24 |
/**
|
25 |
* M?todo de conveniencia
|
26 |
*
|
27 |
* @param r
|
28 |
* @param igeometry
|
29 |
*/
|
30 |
public synchronized void insert(Rectangle2D bounds, IGeometry geom) { |
31 |
Envelope env = FConverter.convertRectangle2DtoEnvelope(bounds); |
32 |
this.insert(env, geom);
|
33 |
fastNumTotalRegs++; |
34 |
} |
35 |
|
36 |
public synchronized void query(Envelope searchEnv, ItemVisitor visitor) |
37 |
{ |
38 |
quadTree.query(searchEnv, visitor); |
39 |
} |
40 |
|
41 |
public void insert(Envelope itemEnv, Object item) { |
42 |
quadTree.insert(itemEnv, item); |
43 |
fastNumTotalRegs++; |
44 |
} |
45 |
|
46 |
public boolean remove(Envelope itemEnv, Object item) { |
47 |
boolean resul = quadTree.remove(itemEnv, item);
|
48 |
if (resul)
|
49 |
fastNumTotalRegs--; |
50 |
return resul;
|
51 |
} |
52 |
|
53 |
public int size() { |
54 |
return fastNumTotalRegs;
|
55 |
} |
56 |
|
57 |
public void clearAll() { |
58 |
quadTree = new Quadtree();
|
59 |
fastNumTotalRegs = 0;
|
60 |
} |
61 |
|
62 |
|
63 |
} |