Revision 43371
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/WrappedSpatialIndex.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2017 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.fmap.dal.feature.impl; |
|
24 |
|
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.Iterator; |
|
27 |
import java.util.List; |
|
28 |
import org.gvsig.fmap.dal.feature.Feature; |
|
29 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
30 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
31 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
32 |
import org.gvsig.fmap.geom.Geometry; |
|
33 |
import org.gvsig.fmap.geom.SpatialIndex; |
|
34 |
import org.gvsig.fmap.geom.SpatialIndexFactory; |
|
35 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
36 |
import org.gvsig.tools.exception.BaseException; |
|
37 |
import org.gvsig.tools.service.Manager; |
|
38 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
39 |
import org.gvsig.tools.visitor.Visitor; |
|
40 |
|
|
41 |
/** |
|
42 |
* @author fdiaz |
|
43 |
* |
|
44 |
*/ |
|
45 |
public class WrappedSpatialIndex implements SpatialIndex { |
|
46 |
|
|
47 |
private final SpatialIndex index; |
|
48 |
private final FeatureStore store; |
|
49 |
|
|
50 |
protected class Oid2FeatureReferenceVisitor implements Visitor { |
|
51 |
|
|
52 |
private final Visitor wrapedVisitor; |
|
53 |
|
|
54 |
public Oid2FeatureReferenceVisitor(Visitor wrapedVisitor) { |
|
55 |
this.wrapedVisitor = wrapedVisitor; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public void visit(Object oid) throws VisitCanceledException, BaseException { |
|
60 |
DefaultFeatureReference ref = new DefaultFeatureReference(store, oid); |
|
61 |
wrapedVisitor.visit(ref); |
|
62 |
} |
|
63 |
|
|
64 |
} |
|
65 |
|
|
66 |
protected class Oid2FeatureReferenceIterator implements Iterator { |
|
67 |
|
|
68 |
private final Iterator wrapedIterator; |
|
69 |
|
|
70 |
public Oid2FeatureReferenceIterator(Iterator wrapedIterator) { |
|
71 |
this.wrapedIterator = wrapedIterator; |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public boolean hasNext() { |
|
76 |
return this.wrapedIterator.hasNext(); |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public Object next() { |
|
81 |
Object oid = this.wrapedIterator.next(); |
|
82 |
DefaultFeatureReference ref = new DefaultFeatureReference(store, oid); |
|
83 |
return ref; |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public void remove() { |
|
88 |
this.wrapedIterator.remove(); |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
public WrappedSpatialIndex(SpatialIndex index, FeatureStore store) { |
|
93 |
this.index = index; |
|
94 |
this.store = store; |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public SpatialIndexFactory getFactory() { |
|
99 |
return this.index.getFactory(); |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public void open() { |
|
104 |
this.index.open(); |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public void close() { |
|
109 |
this.index.close(); |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public void query(Envelope envelope, Visitor visitor) { |
|
114 |
this.index.query(envelope, new Oid2FeatureReferenceVisitor(visitor)); |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public void query(Geometry geom, Visitor visitor) { |
|
119 |
this.index.query(geom, new Oid2FeatureReferenceVisitor(visitor)); |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public Iterator query(Envelope envelope, long limit) { |
|
124 |
return new Oid2FeatureReferenceIterator(this.index.query(envelope, limit)); |
|
125 |
} |
|
126 |
|
|
127 |
@Override |
|
128 |
public Iterator query(Envelope envelope) { |
|
129 |
return new Oid2FeatureReferenceIterator(this.index.query(envelope)); |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
public Iterator query(Geometry geom, long limit) { |
|
134 |
return new Oid2FeatureReferenceIterator(this.index.query(geom, limit)); |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
public Iterator query(Geometry geom) { |
|
139 |
return new Oid2FeatureReferenceIterator(this.index.query(geom)); |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public Iterator queryNearest(Envelope envelope, long limit) { |
|
144 |
return new Oid2FeatureReferenceIterator(this.index.queryNearest(envelope, limit)); |
|
145 |
} |
|
146 |
|
|
147 |
@Override |
|
148 |
public Iterator queryNearest(Envelope envelope) { |
|
149 |
return new Oid2FeatureReferenceIterator(this.index.queryNearest(envelope)); |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public Iterator queryNearest(Geometry geom, long limit) { |
|
154 |
return new Oid2FeatureReferenceIterator(this.index.queryNearest(geom, limit)); |
|
155 |
} |
|
156 |
|
|
157 |
@Override |
|
158 |
public Iterator queryNearest(Geometry geom) { |
|
159 |
return new Oid2FeatureReferenceIterator(this.index.queryNearest(geom)); |
|
160 |
} |
|
161 |
|
|
162 |
@Override |
|
163 |
public Iterator queryAll() { |
|
164 |
return new Oid2FeatureReferenceIterator(this.index.queryAll()); |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public List queryAsList(Envelope envelope) { |
|
169 |
return asList( this.query(envelope)); |
|
170 |
} |
|
171 |
|
|
172 |
@Override |
|
173 |
public List queryAsList(Geometry geom) { |
|
174 |
return asList( this.query(geom)); |
|
175 |
} |
|
176 |
|
|
177 |
@Override |
|
178 |
public List queryAllAsList() { |
|
179 |
return asList( this.queryAll()); |
|
180 |
} |
|
181 |
|
|
182 |
@Override |
|
183 |
public void insert(Envelope envelope, Object data) { |
|
184 |
this.index.insert(envelope, getOID(data)); |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
188 |
public void insert(Geometry geom, Object data) { |
|
189 |
this.index.insert(geom, getOID(data)); |
|
190 |
} |
|
191 |
|
|
192 |
@Override |
|
193 |
public void insert(Geometry geom) { |
|
194 |
this.index.insert(geom); |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public boolean remove(Envelope envelope, Object data) { |
|
199 |
return this.index.remove(envelope, getOID(data)); |
|
200 |
} |
|
201 |
|
|
202 |
@Override |
|
203 |
public boolean remove(Geometry geom, Object data) { |
|
204 |
return this.index.remove(geom, getOID(data)); |
|
205 |
} |
|
206 |
|
|
207 |
@Override |
|
208 |
public boolean remove(Geometry geom) { |
|
209 |
return this.index.remove(geom); |
|
210 |
} |
|
211 |
|
|
212 |
@Override |
|
213 |
public void removeAll() { |
|
214 |
this.index.removeAll(); |
|
215 |
} |
|
216 |
|
|
217 |
@Override |
|
218 |
public long size() { |
|
219 |
return this.index.size(); |
|
220 |
} |
|
221 |
|
|
222 |
@Override |
|
223 |
public void flush() { |
|
224 |
this.index.flush(); |
|
225 |
} |
|
226 |
|
|
227 |
@Override |
|
228 |
public Manager getManager() { |
|
229 |
return this.index.getManager(); |
|
230 |
} |
|
231 |
|
|
232 |
protected Object getOID(Object obj) { |
|
233 |
if( obj == null ) { |
|
234 |
return null; |
|
235 |
} |
|
236 |
if( obj instanceof FeatureReferenceProviderServices ) { |
|
237 |
return ((FeatureReferenceProviderServices)obj).getOID(); |
|
238 |
} |
|
239 |
if( obj instanceof Feature ) { |
|
240 |
FeatureReference f = ((Feature)obj).getReference(); |
|
241 |
return ((FeatureReferenceProviderServices)f).getOID(); |
|
242 |
} |
|
243 |
if( obj instanceof Number ) { |
|
244 |
return obj; |
|
245 |
} |
|
246 |
throw new IllegalArgumentException("Can't get OID from object of type '"+obj.getClass().getName()+"'."); |
|
247 |
} |
|
248 |
|
|
249 |
protected List asList(Iterator it) { |
|
250 |
List l = new ArrayList(); |
|
251 |
while (it.hasNext()) { |
|
252 |
l.add(it.next()); |
|
253 |
} |
|
254 |
return l; |
|
255 |
} |
|
256 |
} |
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/DefaultFeatureStore.java | ||
---|---|---|
36 | 36 |
import java.util.Map; |
37 | 37 |
import java.util.Map.Entry; |
38 | 38 |
import java.util.Set; |
39 |
|
|
39 | 40 |
import org.apache.commons.io.FilenameUtils; |
40 |
|
|
41 | 41 |
import org.cresques.cts.IProjection; |
42 | 42 |
|
43 | 43 |
import org.gvsig.fmap.dal.DALLocator; |
... | ... | |
2587 | 2587 |
public Throwable getBreakingsCause() { |
2588 | 2588 |
return this.state.getBreakingsCause(); |
2589 | 2589 |
} |
2590 |
|
|
2591 |
@Override |
|
2592 |
public SpatialIndex wrapSpatialIndex(SpatialIndex index) { |
|
2593 |
// FeatureStoreProviderFactory factory = (FeatureStoreProviderFactory) this.getProviderFactory(); |
|
2594 |
// if( !factory.supportNumericOID() ) { |
|
2595 |
// return null; |
|
2596 |
// } |
|
2597 |
SpatialIndex wrappedIndex = new WrappedSpatialIndex(index, this); |
|
2598 |
return wrappedIndex; |
|
2599 |
} |
|
2590 | 2600 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStore.java | ||
---|---|---|
39 | 39 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
40 | 40 |
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException; |
41 | 41 |
import org.gvsig.fmap.geom.Geometry; |
42 |
import org.gvsig.fmap.geom.SpatialIndex; |
|
42 | 43 |
import org.gvsig.fmap.geom.primitive.Envelope; |
43 | 44 |
import org.gvsig.tools.dispose.DisposableIterator; |
44 | 45 |
import org.gvsig.tools.dynobject.DynObject; |
... | ... | |
260 | 261 |
|
261 | 262 |
/** |
262 | 263 |
* Return a paginated list of Features filtered by the query. |
263 |
*
|
|
264 |
* |
|
264 | 265 |
* The returned List of Features is paginated, and the page size |
265 | 266 |
* used is "pageSize". |
266 |
*
|
|
267 |
* |
|
267 | 268 |
* @param query to filter the returned feature list |
268 | 269 |
* @param pageSize the page size of the list |
269 | 270 |
* @return the list of features |
270 | 271 |
*/ |
271 | 272 |
public List<Feature> getFeatures(FeatureQuery query, int pageSize); |
272 |
|
|
273 |
|
|
273 | 274 |
public List<Feature> getFeatures(); |
274 |
|
|
275 |
|
|
275 | 276 |
/** |
276 | 277 |
* Returns the feature given its reference. |
277 | 278 |
* |
... | ... | |
498 | 499 |
throws DataException; |
499 | 500 |
|
500 | 501 |
/** |
501 |
* Creates a new feature of default {@link FeatureType}.
|
|
502 |
* The new feature should be initialized with the values of the feature
|
|
502 |
* Creates a new feature of default {@link FeatureType}. |
|
503 |
* The new feature should be initialized with the values of the feature |
|
503 | 504 |
* passed as parameter. |
504 | 505 |
* Values are inicialiced by name from the feature specified. Error in |
505 | 506 |
* value assignement are ignoreds. |
506 |
*
|
|
507 |
* |
|
507 | 508 |
* @param defaultValues the values to initialize the new feature. |
508 | 509 |
* @return the new feature |
509 |
* @throws DataException
|
|
510 |
* @throws DataException |
|
510 | 511 |
*/ |
511 | 512 |
public EditableFeature createNewFeature(Feature defaultValues) |
512 | 513 |
throws DataException; |
... | ... | |
850 | 851 |
* @return |
851 | 852 |
*/ |
852 | 853 |
public Feature getFeature(DynObject dynobject); |
853 |
|
|
854 |
|
|
854 | 855 |
public Iterator iterator(); |
855 |
|
|
856 |
|
|
856 | 857 |
public ExpressionEvaluator createExpression(); |
857 |
|
|
858 |
|
|
858 | 859 |
public void createCache(String name, DynObject parameters) |
859 | 860 |
throws DataException; |
860 | 861 |
|
861 |
public FeatureCache getCache();
|
|
862 |
|
|
862 |
public FeatureCache getCache(); |
|
863 |
|
|
863 | 864 |
public boolean isBroken(); |
864 |
|
|
865 |
|
|
865 | 866 |
public Throwable getBreakingsCause(); |
867 |
|
|
868 |
/** |
|
869 |
* @param index |
|
870 |
* @return |
|
871 |
*/ |
|
872 |
SpatialIndex wrapSpatialIndex(SpatialIndex index); |
|
866 | 873 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/test/java/org/gvsig/fmap/dal/feature/DummyFetureStore.java | ||
---|---|---|
17 | 17 |
import org.gvsig.fmap.dal.exception.DataException; |
18 | 18 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
19 | 19 |
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException; |
20 |
import org.gvsig.fmap.geom.SpatialIndex; |
|
20 | 21 |
import org.gvsig.fmap.geom.primitive.Envelope; |
21 | 22 |
import org.gvsig.metadata.exceptions.MetadataException; |
22 | 23 |
import org.gvsig.timesupport.Interval; |
... | ... | |
621 | 622 |
return false; |
622 | 623 |
} |
623 | 624 |
|
625 |
@Override |
|
626 |
public SpatialIndex wrapSpatialIndex(SpatialIndex index) { |
|
627 |
return null; |
|
628 |
} |
|
629 |
|
|
624 | 630 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geometry.app/org.gvsig.geometry.app.jts/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
59 | 59 |
<include>org.gvsig:org.gvsig.fmap.geometry.jts</include> |
60 | 60 |
<include>org.gvsig:org.gvsig.fmap.geometry.operation.jts</include> |
61 | 61 |
<include>org.hibernate:hibernate-spatial</include> |
62 |
<include>net.sf:jsi</include> |
|
63 |
<include>gnu.trove:trove</include> |
|
62 | 64 |
</includes> |
63 | 65 |
</dependencySet> |
64 | 66 |
</dependencySets> |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geometry.app/org.gvsig.geometry.app.jts/pom.xml | ||
---|---|---|
77 | 77 |
<version>4.0</version> |
78 | 78 |
<scope>runtime</scope> |
79 | 79 |
</dependency> |
80 |
|
|
81 |
<dependency> |
|
82 |
<groupId>net.sf</groupId> |
|
83 |
<artifactId>jsi</artifactId> |
|
84 |
<version>unknown</version> |
|
85 |
</dependency> |
|
86 |
|
|
87 |
<dependency> |
|
88 |
<groupId>gnu.trove</groupId> |
|
89 |
<artifactId>trove</artifactId> |
|
90 |
<scope>runtime</scope> |
|
91 |
</dependency> |
|
80 | 92 |
</dependencies> |
81 | 93 |
|
82 | 94 |
<properties> |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
60 | 60 |
<include>java3d:vecmath</include> |
61 | 61 |
<include>joda-time:joda-time</include> |
62 | 62 |
<include>net.sf:sqljep</include> |
63 |
<include>net.sf:jsi</include> |
|
64 |
<include>gnu.trove:trove</include> |
|
65 | 63 |
|
66 | 64 |
<include>org.gvsig:org.gvsig.fmap.control</include> |
67 | 65 |
<include>org.gvsig:org.gvsig.fmap.dal.api</include> |
Also available in: Unified diff