Revision 24248 branches/v2_0_0_prep/libraries/libFMap_spatialindex/src/org/gvsig/fmap/data/index/spatial/gt2/QuadtreeGt2.java
QuadtreeGt2.java | ||
---|---|---|
69 | 69 |
import org.geotools.index.quadtree.fs.FileSystemIndexStore; |
70 | 70 |
import org.geotools.index.quadtree.fs.IndexHeader; |
71 | 71 |
import org.gvsig.fmap.data.exceptions.InitializeException; |
72 |
import org.gvsig.fmap.data.feature.FeatureReference; |
|
73 | 72 |
import org.gvsig.fmap.data.feature.FeatureStore; |
74 | 73 |
import org.gvsig.fmap.data.feature.exceptions.FeatureIndexException; |
74 |
import org.gvsig.fmap.data.feature.spi.FeatureReferenceProviderServices; |
|
75 | 75 |
import org.gvsig.fmap.data.feature.spi.index.AbstractFeatureIndexProvider; |
76 | 76 |
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProvider; |
77 | 77 |
import org.gvsig.tools.exception.BaseException; |
... | ... | |
91 | 91 |
* of rectangle, it also returned byte offset of this rectangle in shp file</li> |
92 | 92 |
* <li> Query artifact wasnt run well at all </li> |
93 | 93 |
* </ol> |
94 |
*
|
|
94 |
* |
|
95 | 95 |
* @author azabala |
96 |
*
|
|
96 |
* |
|
97 | 97 |
*/ |
98 | 98 |
public class QuadtreeGt2 extends AbstractFeatureIndexProvider implements FeatureIndexProvider { |
99 |
|
|
99 |
|
|
100 | 100 |
public static final String NAME = "QuadtreeGt2"; |
101 | 101 |
/** |
102 | 102 |
* Geotools quadtree implementation |
... | ... | |
124 | 124 |
//int numRecs = 0; |
125 | 125 |
|
126 | 126 |
boolean inMemory = false; |
127 |
|
|
127 |
|
|
128 | 128 |
public QuadtreeGt2() { |
129 |
|
|
129 |
|
|
130 | 130 |
} |
131 | 131 |
|
132 |
public void initialize() throws InitializeException {
|
|
132 |
public void initialize() throws InitializeException { |
|
133 | 133 |
try { |
134 | 134 |
File file = File.createTempFile(getFeatureStore().getName(), ".qix"); |
135 | 135 |
this.fileName = file.getAbsolutePath(); |
136 |
org.gvsig.fmap.geom.primitive.Envelope env = (org.gvsig.fmap.geom.primitive.Envelope) getFeatureStore().getMetadata().get("extent"); |
|
136 |
org.gvsig.fmap.geom.primitive.Envelope env = getFeatureStore() |
|
137 |
.getEnvelope(); |
|
137 | 138 |
int featureCount = (int) getFeatureStore().getFeatureSet().getSize(); |
138 | 139 |
this.byteOrder = "NM"; |
139 | 140 |
quadtree = new QuadTree(featureCount, toJtsEnvelope(env)); |
140 | 141 |
if (exists()) { |
141 | 142 |
load(); |
142 |
}
|
|
143 |
} |
|
143 | 144 |
} catch (IOException e) { |
144 | 145 |
throw new InitializeException(e); |
145 | 146 |
} catch (BaseException e) { |
146 | 147 |
throw new InitializeException(e); |
147 | 148 |
} |
148 |
}
|
|
149 |
|
|
149 |
} |
|
150 |
|
|
150 | 151 |
/** |
151 | 152 |
* If the spatial index file exists and has content |
152 | 153 |
*/ |
... | ... | |
174 | 175 |
* Inserts an object in the index |
175 | 176 |
*/ |
176 | 177 |
public void insert(org.gvsig.fmap.geom.primitive.Envelope env, int index) { |
177 |
if (env == null) |
|
178 |
if (env == null) {
|
|
178 | 179 |
throw new IllegalArgumentException("Envelope cannot be null"); |
180 |
} |
|
179 | 181 |
Envelope e = toJtsEnvelope(env); |
180 |
if (e == null) |
|
182 |
if (e == null) {
|
|
181 | 183 |
throw new IllegalStateException( |
182 | 184 |
"JTS Envelope conversion returns null"); |
185 |
} |
|
183 | 186 |
System.out.println("recno=" + index); |
184 |
if (quadtree == null) |
|
187 |
if (quadtree == null) {
|
|
185 | 188 |
throw new IllegalStateException("quadtree is null"); |
189 |
} |
|
186 | 190 |
try { |
187 | 191 |
quadtree.insert(index, toJtsEnvelope(env)); |
188 | 192 |
} catch (StoreException se) { |
... | ... | |
192 | 196 |
} |
193 | 197 |
|
194 | 198 |
public void delete(org.gvsig.fmap.geom.primitive.Envelope env, int index) { |
195 |
if (inMemory) |
|
199 |
if (inMemory) {
|
|
196 | 200 |
quadtree.delete(toJtsEnvelope(env), index); |
201 |
} |
|
197 | 202 |
} |
198 | 203 |
|
199 | 204 |
public Envelope toJtsEnvelope(org.gvsig.fmap.geom.primitive.Envelope env) { |
200 |
if (env == null) |
|
205 |
if (env == null) {
|
|
201 | 206 |
return null; |
207 |
} |
|
202 | 208 |
double[] min = env.getLowerCorner(); |
203 | 209 |
double[] max = env.getUpperCorner(); |
204 | 210 |
return new Envelope(min[0], max[0], min[1], max[1]); |
205 | 211 |
} |
206 | 212 |
|
207 | 213 |
/** |
208 |
*
|
|
214 |
* |
|
209 | 215 |
* @throws StoreException |
210 | 216 |
* @deprecated |
211 | 217 |
*/ |
... | ... | |
280 | 286 |
return getFeatureIndexProviderServices().getFeatureStore(); |
281 | 287 |
} |
282 | 288 |
|
283 |
public void delete(Object value, FeatureReference fref) { |
|
284 |
delete((org.gvsig.fmap.geom.primitive.Envelope) value, ((Integer)fref.getId()).intValue()); |
|
289 |
public void delete(Object value, FeatureReferenceProviderServices fref) { |
|
290 |
delete((org.gvsig.fmap.geom.primitive.Envelope) value, ((Integer) fref |
|
291 |
.getOID()).intValue()); |
|
285 | 292 |
} |
286 | 293 |
|
287 |
public void insert(Object value, FeatureReference fref) { |
|
288 |
insert((org.gvsig.fmap.geom.primitive.Envelope) value, ((Integer)fref.getId()).intValue()); |
|
294 |
public void insert(Object value, FeatureReferenceProviderServices fref) { |
|
295 |
insert((org.gvsig.fmap.geom.primitive.Envelope) value, ((Integer) fref |
|
296 |
.getOID()).intValue()); |
|
289 | 297 |
} |
290 | 298 |
|
291 | 299 |
public List match(Object value) throws FeatureIndexException { |
292 |
if (quadtree == null) |
|
300 |
if (quadtree == null) {
|
|
293 | 301 |
throw new IllegalStateException("This quadtree is null."); |
294 |
if (value == null) |
|
302 |
} |
|
303 |
if (value == null) { |
|
295 | 304 |
throw new IllegalArgumentException("Envelope cannot be null."); |
296 |
if (!(value instanceof org.gvsig.fmap.geom.primitive.Envelope)) |
|
305 |
} |
|
306 |
if (!(value instanceof org.gvsig.fmap.geom.primitive.Envelope)) { |
|
297 | 307 |
throw new IllegalArgumentException("Not an envelope."); |
308 |
} |
|
298 | 309 |
return quadtree.query(toJtsEnvelope((org.gvsig.fmap.geom.primitive.Envelope) value)); |
299 | 310 |
} |
300 | 311 |
|
Also available in: Unified diff