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 @ 43371
History | View | Annotate | Download (3.62 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 |
|
37 |
public class MemorySpatialIndexProvider extends AbstractFeatureIndexProvider { |
38 |
|
39 |
public static final String NAME = "MemorySpatialIndexProvider"; |
40 |
|
41 |
private SpatialIndex index = null; |
42 |
|
43 |
public MemorySpatialIndexProvider() {
|
44 |
|
45 |
} |
46 |
|
47 |
public void initialize() { |
48 |
try {
|
49 |
this.index = GeometryLocator.getGeometryManager().createDefaultMemorySpatialIndex();
|
50 |
} catch (Exception e) { |
51 |
throw new RuntimeException(); |
52 |
} |
53 |
} |
54 |
|
55 |
public void delete(Object o, FeatureReferenceProviderServices fref) { |
56 |
Geometry geom = (Geometry) o; |
57 |
this.index.remove(geom, fref.getOID());
|
58 |
} |
59 |
|
60 |
public void insert(Object o, FeatureReferenceProviderServices fref) { |
61 |
if (o == null ) { |
62 |
return;
|
63 |
} |
64 |
Geometry geom = (Geometry) o; |
65 |
this.index.insert(geom, fref.getOID());
|
66 |
|
67 |
} |
68 |
|
69 |
public List match(Object value) throws FeatureIndexException { |
70 |
Envelope env = null;
|
71 |
if (value instanceof Envelope) { |
72 |
env = (Envelope) value; |
73 |
} else {
|
74 |
if (value instanceof Geometry) { |
75 |
env = ((Geometry) value).getEnvelope(); |
76 |
} |
77 |
} |
78 |
return new LongList(this.index.queryAsList(env)); |
79 |
|
80 |
} |
81 |
|
82 |
public List match(Object min, Object max) { |
83 |
throw new UnsupportedOperationException( |
84 |
"Can't perform this kind of search.");
|
85 |
} |
86 |
|
87 |
public List nearest(int count, Object value) throws FeatureIndexException { |
88 |
throw new UnsupportedOperationException( |
89 |
"Can't perform this kind of search.");
|
90 |
} |
91 |
|
92 |
public boolean isMatchSupported() { |
93 |
return true; |
94 |
} |
95 |
|
96 |
public boolean isNearestSupported() { |
97 |
return false; |
98 |
} |
99 |
|
100 |
public boolean isNearestToleranceSupported() { |
101 |
return false; |
102 |
} |
103 |
|
104 |
public boolean isRangeSupported() { |
105 |
return false; |
106 |
} |
107 |
|
108 |
public List nearest(int count, Object value, Object tolerance) |
109 |
throws FeatureIndexException {
|
110 |
throw new UnsupportedOperationException(); |
111 |
} |
112 |
|
113 |
public List range(Object value1, Object value2) |
114 |
throws FeatureIndexException {
|
115 |
throw new UnsupportedOperationException(); |
116 |
} |
117 |
|
118 |
public void clear() throws DataException { |
119 |
this.index.removeAll();
|
120 |
} |
121 |
} |