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