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 / spatialIndex / SpatialIndexJTS.java @ 41246
History | View | Annotate | Download (4.08 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.geom.impl.spatialIndex; |
24 |
|
25 |
import java.util.Iterator; |
26 |
import java.util.List; |
27 |
|
28 |
import org.gvsig.fmap.geom.GeometryManager; |
29 |
import org.gvsig.fmap.geom.SpatialIndex; |
30 |
import org.gvsig.fmap.geom.SpatialIndexFactory; |
31 |
import org.gvsig.fmap.geom.util.Converter; |
32 |
import org.gvsig.tools.dynobject.DynObject; |
33 |
import org.gvsig.tools.visitor.Visitor; |
34 |
|
35 |
public class SpatialIndexJTS extends AbstractSpatialIndex implements SpatialIndex { |
36 |
|
37 |
private com.vividsolutions.jts.index.quadtree.Quadtree index = null; |
38 |
|
39 |
public SpatialIndexJTS(GeometryManager geometryManager, SpatialIndexFactory factory, DynObject parameters) {
|
40 |
super(geometryManager, factory, parameters);
|
41 |
this.index = null; |
42 |
open(); |
43 |
} |
44 |
|
45 |
public void open() { |
46 |
this.index = new com.vividsolutions.jts.index.quadtree.Quadtree(); |
47 |
} |
48 |
|
49 |
public void close() { |
50 |
this.index = null; |
51 |
} |
52 |
|
53 |
private com.vividsolutions.jts.geom.Geometry asJTS(org.gvsig.fmap.geom.Geometry geom) {
|
54 |
return Converter.geometryToJts(geom);
|
55 |
} |
56 |
|
57 |
public long size() { |
58 |
return this.index.size(); |
59 |
} |
60 |
|
61 |
public void query(org.gvsig.fmap.geom.primitive.Envelope envelope, |
62 |
Visitor visitor) { |
63 |
com.vividsolutions.jts.index.ItemVisitor visitor_jts = new JTSVisitorWrapper(visitor);
|
64 |
com.vividsolutions.jts.geom.Envelope env_jts = asJTS(envelope.getGeometry()).getEnvelopeInternal(); |
65 |
this.index.query(env_jts, visitor_jts);
|
66 |
|
67 |
} |
68 |
|
69 |
public Iterator query(org.gvsig.fmap.geom.primitive.Envelope envelope,long limit) { |
70 |
if( limit!=0 ) { |
71 |
throw new UnsupportedOperationException("Not supported yet."); |
72 |
} |
73 |
com.vividsolutions.jts.geom.Envelope env_jts = asJTS(envelope.getGeometry()).getEnvelopeInternal(); |
74 |
List result = this.index.query(env_jts); |
75 |
return result.iterator();
|
76 |
} |
77 |
|
78 |
public Iterator queryNearest(org.gvsig.fmap.geom.primitive.Envelope envelope, long limit) { |
79 |
throw new UnsupportedOperationException("Not supported yet."); |
80 |
} |
81 |
|
82 |
public Iterator queryAll() { |
83 |
List result = this.index.queryAll(); |
84 |
return result.iterator();
|
85 |
} |
86 |
|
87 |
public void insert(org.gvsig.fmap.geom.primitive.Envelope envelope, Object data) { |
88 |
com.vividsolutions.jts.geom.Envelope env_jts = asJTS(envelope.getGeometry()).getEnvelopeInternal(); |
89 |
index.insert(env_jts, data); |
90 |
} |
91 |
|
92 |
public boolean remove(org.gvsig.fmap.geom.primitive.Envelope envelope, Object data) { |
93 |
com.vividsolutions.jts.geom.Envelope env_jts = asJTS(envelope.getGeometry()).getEnvelopeInternal(); |
94 |
return index.remove(env_jts, data);
|
95 |
} |
96 |
|
97 |
public void removeAll() { |
98 |
index = new com.vividsolutions.jts.index.quadtree.Quadtree();
|
99 |
} |
100 |
|
101 |
private class JTSVisitorWrapper implements com.vividsolutions.jts.index.ItemVisitor { |
102 |
|
103 |
private Visitor visitor = null; |
104 |
|
105 |
public JTSVisitorWrapper(Visitor visitor) {
|
106 |
this.visitor = visitor;
|
107 |
} |
108 |
|
109 |
public void visitItem(Object arg0) { |
110 |
try {
|
111 |
this.visitor.visit(arg0);
|
112 |
} catch (Exception e) { |
113 |
throw new RuntimeException(); |
114 |
} |
115 |
} |
116 |
|
117 |
} |
118 |
|
119 |
} |