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 @ 40559
History | View | Annotate | Download (3.69 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
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.feature.impl; |
25 |
|
26 |
import java.util.List; |
27 |
|
28 |
import org.gvsig.fmap.dal.exception.DataException; |
29 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
30 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
31 |
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider; |
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.GeometryLocator; |
34 |
import org.gvsig.fmap.geom.SpatialIndex; |
35 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 |
import org.gvsig.fmap.geom.primitive.NullGeometry; |
37 |
|
38 |
public class MemorySpatialIndexProvider extends AbstractFeatureIndexProvider { |
39 |
|
40 |
public static final String NAME = "MemorySpatialIndexProvider"; |
41 |
|
42 |
private SpatialIndex index = null; |
43 |
|
44 |
public MemorySpatialIndexProvider() {
|
45 |
|
46 |
} |
47 |
|
48 |
public void initialize() { |
49 |
try {
|
50 |
this.index = GeometryLocator.getGeometryManager().createDefaultMemorySpatialIndex();
|
51 |
} catch (Exception e) { |
52 |
throw new RuntimeException(); |
53 |
} |
54 |
} |
55 |
|
56 |
public void delete(Object o, FeatureReferenceProviderServices fref) { |
57 |
Geometry geom = (Geometry) o; |
58 |
this.index.remove(geom, fref.getOID());
|
59 |
} |
60 |
|
61 |
public void insert(Object o, FeatureReferenceProviderServices fref) { |
62 |
if (o == null || o instanceof NullGeometry) { |
63 |
return;
|
64 |
} |
65 |
Geometry geom = (Geometry) o; |
66 |
this.index.insert(geom, fref.getOID());
|
67 |
|
68 |
} |
69 |
|
70 |
public List match(Object value) throws FeatureIndexException { |
71 |
Envelope env = null;
|
72 |
if (value instanceof Envelope) { |
73 |
env = (Envelope) value; |
74 |
} else {
|
75 |
if (value instanceof Geometry) { |
76 |
env = ((Geometry) value).getEnvelope(); |
77 |
} |
78 |
} |
79 |
return new LongList(this.index.queryAsList(env)); |
80 |
|
81 |
} |
82 |
|
83 |
public List match(Object min, Object max) { |
84 |
throw new UnsupportedOperationException( |
85 |
"Can't perform this kind of search.");
|
86 |
} |
87 |
|
88 |
public List nearest(int count, Object value) throws FeatureIndexException { |
89 |
throw new UnsupportedOperationException( |
90 |
"Can't perform this kind of search.");
|
91 |
} |
92 |
|
93 |
public boolean isMatchSupported() { |
94 |
return true; |
95 |
} |
96 |
|
97 |
public boolean isNearestSupported() { |
98 |
return false; |
99 |
} |
100 |
|
101 |
public boolean isNearestToleranceSupported() { |
102 |
return false; |
103 |
} |
104 |
|
105 |
public boolean isRangeSupported() { |
106 |
return false; |
107 |
} |
108 |
|
109 |
public List nearest(int count, Object value, Object tolerance) |
110 |
throws FeatureIndexException {
|
111 |
throw new UnsupportedOperationException(); |
112 |
} |
113 |
|
114 |
public List range(Object value1, Object value2) |
115 |
throws FeatureIndexException {
|
116 |
throw new UnsupportedOperationException(); |
117 |
} |
118 |
|
119 |
public void clear() throws DataException { |
120 |
this.index.removeAll();
|
121 |
} |
122 |
} |