Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / SpatialCache.java @ 38605

History | View | Annotate | Download (1.99 KB)

1 21200 vcaballero
package org.gvsig.fmap.mapcontext.layers;
2
3 28313 vcaballero
import java.util.List;
4 21200 vcaballero
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 30011 cordinyana
17
        private boolean enabled = false;
18 21200 vcaballero
19
        public int getMaxFeatures() {
20
                return maxFeatures;
21
        }
22
23
        public void setMaxFeatures(int maxFeatures) {
24
                this.maxFeatures = maxFeatures;
25
        }
26
27
        /**
28
         * M?todo de conveniencia
29
         *
30
         * @param r
31
         * @param igeometry
32
         */
33 22288 vcaballero
        public synchronized void insert(org.gvsig.fmap.geom.primitive.Envelope bounds, Geometry geom) {
34 30011 cordinyana
                if (isEnabled() && getMaxFeatures() >= size()) {
35
                        Envelope env = Converter.convertEnvelopeToJTS(bounds);
36
                        this.insert(env, geom);
37
                        //fastNumTotalRegs++;
38
                }
39 21200 vcaballero
        }
40
41
        public synchronized void query(Envelope searchEnv, ItemVisitor visitor)
42
        {
43
                quadTree.query(searchEnv, visitor);
44
        }
45 28313 vcaballero
        public synchronized List query(Envelope searchEnv)
46
        {
47
                return quadTree.query(searchEnv);
48
        }
49 21200 vcaballero
50
        public void insert(Envelope itemEnv, Object item) {
51 30011 cordinyana
                if (isEnabled() && getMaxFeatures() >= size()) {
52
                        quadTree.insert(itemEnv, item);
53
                        fastNumTotalRegs++;
54
                }
55 21200 vcaballero
        }
56
57
        public boolean remove(Envelope itemEnv, Object item) {
58
                boolean resul = quadTree.remove(itemEnv, item);
59
                if (resul)
60
                        fastNumTotalRegs--;
61
                return resul;
62
        }
63
64
        public int size() {
65
                return fastNumTotalRegs;
66
        }
67
68
        public void clearAll() {
69
                quadTree = new Quadtree();
70
                fastNumTotalRegs = 0;
71
        }
72
73 22288 vcaballero
        public void remove(org.gvsig.fmap.geom.primitive.Envelope bounds, Geometry geom) {
74
                Envelope env = Converter.convertEnvelopeToJTS(bounds);
75 21200 vcaballero
                this.remove(env,geom);
76
        }
77
78 30011 cordinyana
        public boolean isEnabled() {
79
                return enabled;
80
        }
81 21200 vcaballero
82 30011 cordinyana
        public void setEnabled(boolean enabled) {
83
                this.enabled = enabled;
84
        }
85
86
87 21200 vcaballero
}