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 / GeometryIndexProvider.java @ 44111
History | View | Annotate | Download (3.65 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.primitive.Envelope; |
34 |
import java.util.Iterator; |
35 |
import org.apache.commons.collections4.IteratorUtils; |
36 |
import org.gvsig.fmap.geom.SpatialIndex; |
37 |
|
38 |
public class GeometryIndexProvider extends AbstractFeatureIndexProvider { |
39 |
|
40 |
private SpatialIndex index = null; |
41 |
|
42 |
public GeometryIndexProvider() {
|
43 |
|
44 |
} |
45 |
|
46 |
@Override
|
47 |
public void initialize() { |
48 |
} |
49 |
|
50 |
protected Envelope getEnvelope(Object value) { |
51 |
Envelope env = null;
|
52 |
|
53 |
if (value instanceof Envelope) { |
54 |
env = (Envelope) value; |
55 |
} else
|
56 |
if (value instanceof Geometry) { |
57 |
env = ((Geometry) value).getEnvelope(); |
58 |
} |
59 |
return env;
|
60 |
} |
61 |
|
62 |
@Override
|
63 |
public void insert(Object value, FeatureReferenceProviderServices fref) { |
64 |
this.index.insert(getEnvelope(value), fref);
|
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void delete(Object value, FeatureReferenceProviderServices fref) { |
69 |
this.index.remove(getEnvelope(value), fref);
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
public List match(Object value) throws FeatureIndexException { |
74 |
return this.index.queryAsList(getEnvelope(value)); |
75 |
} |
76 |
|
77 |
@Override
|
78 |
public List nearest(int count, Object value) { |
79 |
if( !this.index.getFactory().isNearestQuerySupported() ) { |
80 |
throw new UnsupportedOperationException(); |
81 |
} |
82 |
if (value == null) { |
83 |
throw new IllegalArgumentException("value is null"); |
84 |
} |
85 |
|
86 |
Iterator x = this.index.queryNearest(getEnvelope(value), count); |
87 |
return IteratorUtils.toList(x);
|
88 |
} |
89 |
|
90 |
@Override
|
91 |
public boolean isMatchSupported() { |
92 |
return true; |
93 |
} |
94 |
|
95 |
@Override
|
96 |
public boolean isNearestSupported() { |
97 |
return this.index.getFactory().isNearestQuerySupported(); |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public boolean isNearestToleranceSupported() { |
102 |
return false; |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public boolean isRangeSupported() { |
107 |
return false; |
108 |
} |
109 |
|
110 |
@Override
|
111 |
public List nearest(int count, Object value, Object tolerance) |
112 |
throws FeatureIndexException {
|
113 |
throw new UnsupportedOperationException(); |
114 |
} |
115 |
|
116 |
@Override
|
117 |
public List range(Object value1, Object value2) |
118 |
throws FeatureIndexException {
|
119 |
throw new UnsupportedOperationException(); |
120 |
} |
121 |
|
122 |
@Override
|
123 |
public void clear() throws DataException { |
124 |
this.index.removeAll();
|
125 |
} |
126 |
} |