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