svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.impl / src / main / java / org / gvsig / fmap / geom / impl / SpatialIndexJTS.java @ 40435
History | View | Annotate | Download (3.93 KB)
1 |
package org.gvsig.fmap.geom.impl; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Collection; |
5 |
import java.util.Iterator; |
6 |
import java.util.List; |
7 |
|
8 |
import org.gvsig.fmap.geom.Geometry; |
9 |
import org.gvsig.fmap.geom.SpatialIndex; |
10 |
import org.gvsig.fmap.geom.primitive.Envelope; |
11 |
import org.gvsig.fmap.geom.util.Converter; |
12 |
import org.gvsig.tools.visitor.Visitor; |
13 |
|
14 |
public class SpatialIndexJTS implements SpatialIndex { |
15 |
|
16 |
private class JTSVisitorWrapper implements com.vividsolutions.jts.index.ItemVisitor { |
17 |
|
18 |
private Visitor visitor = null; |
19 |
public JTSVisitorWrapper(Visitor visitor) {
|
20 |
this.visitor = visitor;
|
21 |
} |
22 |
public void visitItem(Object arg0) { |
23 |
try {
|
24 |
this.visitor.visit(arg0);
|
25 |
} catch (Exception e) { |
26 |
throw new RuntimeException(); |
27 |
} |
28 |
} |
29 |
|
30 |
} |
31 |
private com.vividsolutions.jts.index.quadtree.Quadtree index = null; |
32 |
|
33 |
public SpatialIndexJTS() {
|
34 |
index = new com.vividsolutions.jts.index.quadtree.Quadtree();
|
35 |
} |
36 |
|
37 |
private com.vividsolutions.jts.geom.Geometry getJTS(org.gvsig.fmap.geom.Geometry geom) {
|
38 |
return Converter.geometryToJts(geom);
|
39 |
} |
40 |
|
41 |
public long size() { |
42 |
return this.index.size(); |
43 |
} |
44 |
|
45 |
public void query(org.gvsig.fmap.geom.primitive.Envelope envelope, |
46 |
Visitor visitor) { |
47 |
com.vividsolutions.jts.index.ItemVisitor visitor_jts = new JTSVisitorWrapper(visitor);
|
48 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(envelope.getGeometry()).getEnvelopeInternal(); |
49 |
this.index.query(env_jts, visitor_jts);
|
50 |
|
51 |
} |
52 |
|
53 |
public void query(org.gvsig.fmap.geom.Geometry geom, Visitor visitor) { |
54 |
com.vividsolutions.jts.index.ItemVisitor visitor_jts = new JTSVisitorWrapper(visitor);
|
55 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(geom).getEnvelopeInternal(); |
56 |
this.index.query(env_jts, visitor_jts);
|
57 |
} |
58 |
|
59 |
public Iterator query(org.gvsig.fmap.geom.primitive.Envelope envelope) { |
60 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(envelope.getGeometry()).getEnvelopeInternal(); |
61 |
List result = this.index.query(env_jts); |
62 |
return result.iterator();
|
63 |
} |
64 |
public Iterator queryAll() { |
65 |
List result = this.index.queryAll(); |
66 |
return result.iterator();
|
67 |
} |
68 |
|
69 |
public Iterator query(org.gvsig.fmap.geom.Geometry geom) { |
70 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(geom).getEnvelopeInternal(); |
71 |
List result = this.index.query(env_jts); |
72 |
return result.iterator();
|
73 |
} |
74 |
|
75 |
public void insert(org.gvsig.fmap.geom.Geometry geom, Object data) { |
76 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(geom).getEnvelopeInternal(); |
77 |
index.insert(env_jts, data); |
78 |
} |
79 |
|
80 |
public void insert(org.gvsig.fmap.geom.Geometry geom) { |
81 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(geom).getEnvelopeInternal(); |
82 |
index.insert(env_jts, geom); |
83 |
} |
84 |
|
85 |
public void insert(org.gvsig.fmap.geom.primitive.Envelope envelope, Object data) { |
86 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(envelope.getGeometry()).getEnvelopeInternal(); |
87 |
index.insert(env_jts, data); |
88 |
} |
89 |
|
90 |
public boolean remove(org.gvsig.fmap.geom.Geometry geom) { |
91 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(geom).getEnvelopeInternal(); |
92 |
return index.remove (env_jts, geom);
|
93 |
} |
94 |
|
95 |
public boolean remove(org.gvsig.fmap.geom.Geometry geom, Object data) { |
96 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(geom).getEnvelopeInternal(); |
97 |
return index.remove (env_jts, data);
|
98 |
} |
99 |
|
100 |
public boolean remove(org.gvsig.fmap.geom.primitive.Envelope envelope, Object data) { |
101 |
com.vividsolutions.jts.geom.Envelope env_jts = getJTS(envelope.getGeometry()).getEnvelopeInternal(); |
102 |
return index.remove (env_jts, data);
|
103 |
} |
104 |
|
105 |
public void removeAll() { |
106 |
index = new com.vividsolutions.jts.index.quadtree.Quadtree();
|
107 |
} |
108 |
|
109 |
public List queryAsList(Envelope envelope) { |
110 |
return IteratorToList( query(envelope) );
|
111 |
} |
112 |
|
113 |
public List queryAsList(Geometry geom) { |
114 |
return IteratorToList( query(geom) );
|
115 |
} |
116 |
|
117 |
public List queryAllAsList() { |
118 |
return IteratorToList( queryAll() );
|
119 |
} |
120 |
|
121 |
private List IteratorToList(Iterator it) { |
122 |
List l = new ArrayList(); |
123 |
while( it.hasNext() ) {
|
124 |
l.add(it.next()); |
125 |
} |
126 |
return l;
|
127 |
} |
128 |
} |