Revision 24033 branches/v2_0_0_prep/libraries/libFMap_spatialindex/src/org/gvsig/fmap/data/index/spatial/jsi/RTreeJsi.java
RTreeJsi.java | ||
---|---|---|
69 | 69 |
import java.util.List; |
70 | 70 |
import java.util.Properties; |
71 | 71 |
|
72 |
import org.geotools.index.quadtree.QuadTree; |
|
73 |
import org.gvsig.fmap.data.ReadException; |
|
74 |
import org.gvsig.fmap.data.feature.Feature; |
|
75 |
import org.gvsig.fmap.data.index.IndexException; |
|
76 |
import org.gvsig.fmap.data.index.IndexParameters; |
|
77 |
import org.gvsig.fmap.data.index.spatial.AbstractIntBasedSpatialIndex; |
|
78 |
import org.gvsig.fmap.data.index.spatial.NearestNeighbourFinder; |
|
79 |
import org.gvsig.fmap.data.index.spatial.SpatialIndex; |
|
80 |
import org.gvsig.fmap.geom.Geometry; |
|
72 |
import org.gvsig.fmap.data.exceptions.InitializeException; |
|
73 |
import org.gvsig.fmap.data.feature.FeatureReference; |
|
74 |
import org.gvsig.fmap.data.feature.spi.index.AbstractFeatureIndexProvider; |
|
75 |
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProvider; |
|
81 | 76 |
import org.gvsig.fmap.geom.primitive.Envelope; |
77 |
import org.gvsig.fmap.geom.primitive.Point; |
|
82 | 78 |
import org.gvsig.fmap.geom.primitive.Point2D; |
83 |
import org.gvsig.tools.exception.BaseException; |
|
84 | 79 |
|
85 | 80 |
import com.infomatiq.jsi.IntProcedure; |
86 | 81 |
import com.infomatiq.jsi.Rectangle; |
... | ... | |
103 | 98 |
* It isnt persistent, and We've found some problems |
104 | 99 |
* with delete operations. |
105 | 100 |
* |
101 |
* |
|
106 | 102 |
* |
107 | 103 |
* |
108 |
* |
|
109 | 104 |
* @author azabala |
105 |
* @author jyarza |
|
110 | 106 |
* |
111 | 107 |
*/ |
112 |
public class RTreeJsi extends AbstractIntBasedSpatialIndex implements SpatialIndex, NearestNeighbourFinder {
|
|
108 |
public class RTreeJsi extends AbstractFeatureIndexProvider implements FeatureIndexProvider {
|
|
113 | 109 |
private RTree rtree; |
114 | 110 |
|
115 |
public RTreeJsi(IndexParameters params) throws IndexException { |
|
116 |
super(params); |
|
111 |
public RTreeJsi() { |
|
117 | 112 |
rtree = new RTree(); |
118 | 113 |
} |
119 | 114 |
|
120 |
public void create(){ |
|
115 |
|
|
116 |
public void initialize() throws InitializeException { |
|
121 | 117 |
Properties props = new Properties(); |
122 | 118 |
// props.setProperty("MaxNodeEntries", "500"); |
123 | 119 |
// props.setProperty("MinNodeEntries", "200"); |
... | ... | |
143 | 139 |
return (List) rtree.nearest(jsiPoint, numberOfNearest); |
144 | 140 |
} |
145 | 141 |
|
146 |
//FIXME Add this method to spatial index interface |
|
147 | 142 |
public Iterator iterator(){ |
148 | 143 |
return rtree.iterator(); |
149 | 144 |
} |
... | ... | |
152 | 147 |
return rtree.size(); |
153 | 148 |
} |
154 | 149 |
|
155 |
public void delete(Envelope env, int index) { |
|
156 |
rtree.delete(toJsiRect(env), index); |
|
157 |
} |
|
158 |
|
|
159 |
public void insert(Envelope env, int index) { |
|
160 |
rtree.add(toJsiRect(env), index); |
|
161 |
} |
|
162 |
|
|
163 |
public List query(Envelope env) throws IndexException { |
|
164 |
ListIntProcedure solution = new ListIntProcedure(); |
|
165 |
rtree.intersects(toJsiRect(env), solution); |
|
166 |
return solution.getSolution(); |
|
167 |
} |
|
168 |
|
|
169 |
public List findNNearest(int numberOfNearest, Envelope env){ |
|
170 |
return (List) rtree.nearest(toJsiRect(env), numberOfNearest); |
|
171 |
} |
|
172 |
|
|
173 | 150 |
protected Rectangle toJsiRect(Envelope env){ |
174 | 151 |
double[] min = env.getLowerCorner(); |
175 | 152 |
double[] max = env.getUpperCorner(); |
... | ... | |
181 | 158 |
return jsiRect; |
182 | 159 |
} |
183 | 160 |
|
161 |
public void insert(Object value, FeatureReference fref) { |
|
162 |
if (value == null) throw new IllegalArgumentException("value is null"); |
|
163 |
if (!(value instanceof Envelope)) { |
|
164 |
throw new IllegalArgumentException("Received " + value.getClass().getName() + " but expected org.gvsig.fmap.geom.primitive.Envelope."); |
|
165 |
} |
|
166 |
if (!(fref.getId() instanceof Integer)) throw new IllegalArgumentException("Reference Id is of type " + fref.getId().getClass().getName() + " but expected an Integer."); |
|
167 |
rtree.add(toJsiRect((Envelope) value), ((Integer) fref.getId()).intValue()); |
|
168 |
} |
|
169 |
|
|
170 |
public void delete(Object value, FeatureReference fref) { |
|
171 |
if (value == null) throw new IllegalArgumentException("value is null"); |
|
172 |
if (!(value instanceof Envelope)) { |
|
173 |
throw new IllegalArgumentException("Received " + value.getClass().getName() + " but expected org.gvsig.fmap.geom.primitive.Envelope."); |
|
174 |
} |
|
175 |
rtree.delete(toJsiRect((Envelope) value), ((Integer) fref.getId()).intValue()); |
|
176 |
} |
|
177 |
|
|
178 |
public List match(Object value) { |
|
179 |
if (value == null) throw new IllegalArgumentException("value is null"); |
|
180 |
if (!(value instanceof Envelope)) { |
|
181 |
throw new IllegalArgumentException("Received " + value.getClass().getName() + " but expected org.gvsig.fmap.geom.primitive.Envelope."); |
|
182 |
} |
|
183 |
ListIntProcedure solution = new ListIntProcedure(); |
|
184 |
rtree.intersects(toJsiRect((Envelope) value), solution); |
|
185 |
return solution.getSolution(); |
|
186 |
} |
|
187 |
|
|
188 |
public List match(Object min, Object max) { |
|
189 |
throw new UnsupportedOperationException(); |
|
190 |
} |
|
191 |
|
|
192 |
public List nearest(int n, Object value) { |
|
193 |
if (value == null) throw new IllegalArgumentException("value is null"); |
|
194 |
if (value instanceof Envelope) { |
|
195 |
return (List) rtree.nearest(toJsiRect((Envelope) value), n); |
|
196 |
|
|
197 |
} else if (value instanceof Point) { |
|
198 |
Point p = (Point) value; |
|
199 |
com.infomatiq.jsi.Point jsiPoint = |
|
200 |
new com.infomatiq.jsi.Point((float) p.getDirectPosition().getOrdinate(0), (float) p.getDirectPosition().getOrdinate(1)); |
|
201 |
return (List) rtree.nearest(jsiPoint, n); |
|
202 |
} |
|
203 |
throw new IllegalArgumentException("Received " + value.getClass().getName() + " but expected org.gvsig.fmap.geom.primitive.Envelope."); |
|
204 |
} |
|
205 |
|
|
184 | 206 |
} |
185 | 207 |
|
Also available in: Unified diff