svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / MemorySpatialIndexProvider.java @ 40435
History | View | Annotate | Download (2.76 KB)
1 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.feature.impl; |
---|---|---|---|
2 | |||
3 | import java.util.List; |
||
4 | |||
5 | import org.gvsig.fmap.dal.exception.DataException; |
||
6 | import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
||
7 | import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
||
8 | import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider; |
||
9 | import org.gvsig.fmap.geom.Geometry; |
||
10 | import org.gvsig.fmap.geom.GeometryLocator; |
||
11 | import org.gvsig.fmap.geom.SpatialIndex; |
||
12 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
13 | import org.gvsig.fmap.geom.primitive.NullGeometry; |
||
14 | |||
15 | public class MemorySpatialIndexProvider extends AbstractFeatureIndexProvider { |
||
16 | |||
17 | public static final String NAME = "MemorySpatialIndexProvider"; |
||
18 | |||
19 | private SpatialIndex index = null; |
||
20 | |||
21 | public MemorySpatialIndexProvider() {
|
||
22 | |||
23 | } |
||
24 | |||
25 | public void initialize() { |
||
26 | try {
|
||
27 | this.index = GeometryLocator.getGeometryManager().createDefaultMemorySpatialIndex();
|
||
28 | } catch (Exception e) { |
||
29 | throw new RuntimeException(); |
||
30 | } |
||
31 | } |
||
32 | |||
33 | public void delete(Object o, FeatureReferenceProviderServices fref) { |
||
34 | Geometry geom = (Geometry) o; |
||
35 | this.index.remove(geom, fref.getOID());
|
||
36 | } |
||
37 | |||
38 | public void insert(Object o, FeatureReferenceProviderServices fref) { |
||
39 | if (o == null || o instanceof NullGeometry) { |
||
40 | return;
|
||
41 | } |
||
42 | Geometry geom = (Geometry) o; |
||
43 | this.index.insert(geom, fref.getOID());
|
||
44 | |||
45 | } |
||
46 | |||
47 | public List match(Object value) throws FeatureIndexException { |
||
48 | Envelope env = null;
|
||
49 | if (value instanceof Envelope) { |
||
50 | env = (Envelope) value; |
||
51 | } else {
|
||
52 | if (value instanceof Geometry) { |
||
53 | env = ((Geometry) value).getEnvelope(); |
||
54 | } |
||
55 | } |
||
56 | return new LongList(this.index.queryAsList(env)); |
||
57 | |||
58 | } |
||
59 | |||
60 | public List match(Object min, Object max) { |
||
61 | throw new UnsupportedOperationException( |
||
62 | "Can't perform this kind of search.");
|
||
63 | } |
||
64 | |||
65 | public List nearest(int count, Object value) throws FeatureIndexException { |
||
66 | throw new UnsupportedOperationException( |
||
67 | "Can't perform this kind of search.");
|
||
68 | } |
||
69 | |||
70 | public boolean isMatchSupported() { |
||
71 | return true; |
||
72 | } |
||
73 | |||
74 | public boolean isNearestSupported() { |
||
75 | return false; |
||
76 | } |
||
77 | |||
78 | public boolean isNearestToleranceSupported() { |
||
79 | return false; |
||
80 | } |
||
81 | |||
82 | public boolean isRangeSupported() { |
||
83 | return false; |
||
84 | } |
||
85 | |||
86 | public List nearest(int count, Object value, Object tolerance) |
||
87 | throws FeatureIndexException {
|
||
88 | throw new UnsupportedOperationException(); |
||
89 | } |
||
90 | |||
91 | public List range(Object value1, Object value2) |
||
92 | throws FeatureIndexException {
|
||
93 | throw new UnsupportedOperationException(); |
||
94 | } |
||
95 | |||
96 | public void clear() throws DataException { |
||
97 | this.index.removeAll();
|
||
98 | } |
||
99 | } |