Revision 37378
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
4 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 |
|
5 |
http://maven.apache.org/maven-v4_0_0.xsd"> |
|
6 |
<modelVersion>4.0.0</modelVersion> |
|
7 |
<groupId>org.gvsig</groupId> |
|
8 |
<artifactId>org.gvsig.fmap.dal.index.spatial |
|
9 |
</artifactId> |
|
10 |
<packaging>jar</packaging> |
|
11 |
<version>2.0-SNAPSHOT</version> |
|
12 |
<name>libFMap_dalindex</name> |
|
13 |
<url>http://gvsig.org</url> |
|
14 |
<parent> |
|
15 |
<groupId>org.gvsig</groupId> |
|
16 |
<artifactId>gvsig-base-library-pom</artifactId> |
|
17 |
<version>2.0-SNAPSHOT</version> |
|
18 |
</parent> |
|
19 |
<distributionManagement> |
|
20 |
<site> |
|
21 |
<id>gvsig-repository</id> |
|
22 |
<url>${site-repository}/</url> |
|
23 |
</site> |
|
24 |
</distributionManagement> |
|
25 |
|
|
26 |
|
|
27 |
<properties> |
|
28 |
<!-- gt2 --> |
|
29 |
<gt2-jarIncludes>org/gvsig/fmap/dal/index/spatial/gt2/** |
|
30 |
</gt2-jarIncludes> |
|
31 |
<gt2-jarExcludes>NONE</gt2-jarExcludes> |
|
32 |
|
|
33 |
<!-- jts --> |
|
34 |
<jts-jarIncludes>org/gvsig/fmap/dal/index/spatial/jts/** |
|
35 |
</jts-jarIncludes> |
|
36 |
<jts-jarExcludes>NONE</jts-jarExcludes> |
|
37 |
|
|
38 |
<!-- jsi --> |
|
39 |
<jsi-jarIncludes>org/gvsig/fmap/dal/index/spatial/jsi/** |
|
40 |
</jsi-jarIncludes> |
|
41 |
<jsi-jarExcludes>NONE</jsi-jarExcludes> |
|
42 |
|
|
43 |
<!-- spatialindex --> |
|
44 |
<sptidx-jarIncludes>org/gvsig/fmap/dal/index/spatial/spatialindex/** |
|
45 |
</sptidx-jarIncludes> |
|
46 |
<sptidx-jarExcludes>NONE</sptidx-jarExcludes> |
|
47 |
|
|
48 |
<build-dir>${basedir}/../build</build-dir> |
|
49 |
<eclipse.project.name>libFMap_dalindex</eclipse.project.name> |
|
50 |
</properties> |
|
51 |
|
|
52 |
<dependencies> |
|
53 |
<dependency> |
|
54 |
<groupId>org.gvsig</groupId> |
|
55 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
56 |
<scope>compile</scope> |
|
57 |
</dependency> |
|
58 |
<dependency> |
|
59 |
<groupId>org.gvsig</groupId> |
|
60 |
<artifactId>org.gvsig.fmap.dal</artifactId> |
|
61 |
<scope>compile</scope> |
|
62 |
</dependency> |
|
63 |
<dependency> |
|
64 |
<groupId>org.gvsig</groupId> |
|
65 |
<artifactId>org.gvsig.fmap.dal</artifactId> |
|
66 |
<classifier>spi</classifier> |
|
67 |
<scope>compile</scope> |
|
68 |
</dependency> |
|
69 |
<dependency> |
|
70 |
<groupId>org.gvsig</groupId> |
|
71 |
<artifactId>org.gvsig.fmap.geometry</artifactId> |
|
72 |
<scope>compile</scope> |
|
73 |
</dependency> |
|
74 |
<dependency> |
|
75 |
<groupId>org.gvsig</groupId> |
|
76 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
77 |
<scope>compile</scope> |
|
78 |
</dependency> |
|
79 |
<dependency> |
|
80 |
<groupId>org.gvsig</groupId> |
|
81 |
<artifactId>org.gvsig.projection</artifactId> |
|
82 |
<scope>compile</scope> |
|
83 |
</dependency> |
|
84 |
<dependency> |
|
85 |
<groupId>com.vividsolutions</groupId> |
|
86 |
<artifactId>jts</artifactId> |
|
87 |
<scope>compile</scope> |
|
88 |
</dependency> |
|
89 |
<dependency> |
|
90 |
<groupId>net.sf</groupId> |
|
91 |
<artifactId>jsi</artifactId> |
|
92 |
<scope>compile</scope> |
|
93 |
</dependency> |
|
94 |
<dependency> |
|
95 |
<groupId>sil</groupId> |
|
96 |
<artifactId>sil</artifactId> |
|
97 |
<scope>compile</scope> |
|
98 |
</dependency> |
|
99 |
<dependency> |
|
100 |
<groupId>gnu.trove</groupId> |
|
101 |
<artifactId>trove</artifactId> |
|
102 |
<scope>compile</scope> |
|
103 |
</dependency> |
|
104 |
<dependency> |
|
105 |
<groupId>org.geotools</groupId> |
|
106 |
<artifactId>gt2-main</artifactId> |
|
107 |
<scope>compile</scope> |
|
108 |
</dependency> |
|
109 |
<dependency> |
|
110 |
<groupId>spatialindex</groupId> |
|
111 |
<artifactId>spatialindex</artifactId> |
|
112 |
<scope>compile</scope> |
|
113 |
</dependency> |
|
114 |
<dependency> |
|
115 |
<groupId>org.gvsig</groupId> |
|
116 |
<artifactId>org.gvsig.timesupport.lib.api</artifactId> |
|
117 |
<scope>compile</scope> |
|
118 |
</dependency> |
|
119 |
</dependencies> |
|
120 |
<build> |
|
121 |
<sourceDirectory>src</sourceDirectory> |
|
122 |
<testSourceDirectory>src-test</testSourceDirectory> |
|
123 |
<testResources> |
|
124 |
<testResource> |
|
125 |
<directory>src-test</directory> |
|
126 |
</testResource> |
|
127 |
</testResources> |
|
128 |
</build> |
|
129 |
|
|
130 |
<profiles> |
|
131 |
<profile> |
|
132 |
<id>se</id> |
|
133 |
<activation> |
|
134 |
<activeByDefault>true</activeByDefault> |
|
135 |
</activation> |
|
136 |
<build> |
|
137 |
<plugins> |
|
138 |
<plugin> |
|
139 |
<groupId>org.apache.maven.plugins |
|
140 |
</groupId> |
|
141 |
<artifactId>maven-jar-plugin</artifactId> |
|
142 |
<configuration> |
|
143 |
<excludes> |
|
144 |
<exclude>${gt2-jarIncludes}</exclude> |
|
145 |
<exclude>${jts-jarIncludes}</exclude> |
|
146 |
<exclude>${jsi-jarIncludes}</exclude> |
|
147 |
<exclude>${sptidx-jarIncludes}</exclude> |
|
148 |
</excludes> |
|
149 |
</configuration> |
|
150 |
<executions> |
|
151 |
<!-- |
|
152 |
Generates a jar file only with the GT2 based spatial index |
|
153 |
classes |
|
154 |
--> |
|
155 |
<execution> |
|
156 |
<id>gt2</id> |
|
157 |
<phase>package</phase> |
|
158 |
<goals> |
|
159 |
<goal>jar</goal> |
|
160 |
</goals> |
|
161 |
<configuration> |
|
162 |
<classifier>gt2</classifier> |
|
163 |
<includes> |
|
164 |
<include>${gt2-jarIncludes}</include> |
|
165 |
</includes> |
|
166 |
<excludes> |
|
167 |
<exclude>${gt2-jarExcludes}</exclude> |
|
168 |
</excludes> |
|
169 |
</configuration> |
|
170 |
</execution> |
|
171 |
<!-- |
|
172 |
Generates a jar file only with the JTS based spatial index |
|
173 |
classes |
|
174 |
--> |
|
175 |
<execution> |
|
176 |
<id>jts</id> |
|
177 |
<phase>package</phase> |
|
178 |
<goals> |
|
179 |
<goal>jar</goal> |
|
180 |
</goals> |
|
181 |
<configuration> |
|
182 |
<classifier>jts</classifier> |
|
183 |
<includes> |
|
184 |
<include>${jts-jarIncludes}</include> |
|
185 |
</includes> |
|
186 |
<excludes> |
|
187 |
<exclude>${jts-jarExcludes}</exclude> |
|
188 |
</excludes> |
|
189 |
</configuration> |
|
190 |
</execution> |
|
191 |
<!-- |
|
192 |
Generates a jar file only with the JSI based spatial index |
|
193 |
classes |
|
194 |
--> |
|
195 |
<execution> |
|
196 |
<id>jsi</id> |
|
197 |
<phase>package</phase> |
|
198 |
<goals> |
|
199 |
<goal>jar</goal> |
|
200 |
</goals> |
|
201 |
<configuration> |
|
202 |
<classifier>jsi</classifier> |
|
203 |
<includes> |
|
204 |
<include>${jsi-jarIncludes}</include> |
|
205 |
</includes> |
|
206 |
<excludes> |
|
207 |
<exclude>${jsi-jarExcludes}</exclude> |
|
208 |
</excludes> |
|
209 |
</configuration> |
|
210 |
</execution> |
|
211 |
<!-- |
|
212 |
Generates a jar file only with the spatialindex based spatial |
|
213 |
index classes |
|
214 |
--> |
|
215 |
<execution> |
|
216 |
<id>spatialindex</id> |
|
217 |
<phase>package</phase> |
|
218 |
<goals> |
|
219 |
<goal>jar</goal> |
|
220 |
</goals> |
|
221 |
<configuration> |
|
222 |
<classifier>spatialindex</classifier> |
|
223 |
<includes> |
|
224 |
<include>${sptidx-jarIncludes}</include> |
|
225 |
</includes> |
|
226 |
<excludes> |
|
227 |
<exclude>${sptidx-jarExcludes}</exclude> |
|
228 |
</excludes> |
|
229 |
</configuration> |
|
230 |
</execution> |
|
231 |
</executions> |
|
232 |
</plugin> |
|
233 |
<plugin> |
|
234 |
<artifactId>maven-antrun-plugin</artifactId> |
|
235 |
<executions> |
|
236 |
<execution> |
|
237 |
<id>services</id> |
|
238 |
<phase>package</phase> |
|
239 |
<goals> |
|
240 |
<goal>run</goal> |
|
241 |
</goals> |
|
242 |
<configuration> |
|
243 |
<tasks> |
|
244 |
<jar |
|
245 |
destfile="${project.build.directory}/${project.build.finalName}-gt2.jar" |
|
246 |
update="true"> |
|
247 |
<fileset dir="${basedir}/resources/gt2" /> |
|
248 |
</jar> |
|
249 |
<jar |
|
250 |
destfile="${project.build.directory}/${project.build.finalName}-jsi.jar" |
|
251 |
update="true"> |
|
252 |
<fileset dir="${basedir}/resources/jsi" /> |
|
253 |
</jar> |
|
254 |
<jar |
|
255 |
destfile="${project.build.directory}/${project.build.finalName}-jts.jar" |
|
256 |
update="true"> |
|
257 |
<fileset dir="${basedir}/resources/jts" /> |
|
258 |
</jar> |
|
259 |
<jar |
|
260 |
destfile="${project.build.directory}/${project.build.finalName}-spatialindex.jar" |
|
261 |
update="true"> |
|
262 |
<fileset dir="${basedir}/resources/spatialindex" /> |
|
263 |
</jar> |
|
264 |
</tasks> |
|
265 |
</configuration> |
|
266 |
</execution> |
|
267 |
</executions> |
|
268 |
</plugin> |
|
269 |
<plugin> |
|
270 |
<groupId>org.apache.maven.plugins |
|
271 |
</groupId> |
|
272 |
<artifactId>maven-surefire-plugin |
|
273 |
</artifactId> |
|
274 |
<configuration> |
|
275 |
<additionalClasspathElements> |
|
276 |
<additionalClasspathElement>${basedir}/resources/gt2 |
|
277 |
</additionalClasspathElement> |
|
278 |
<additionalClasspathElement>${basedir}/resources/jsi |
|
279 |
</additionalClasspathElement> |
|
280 |
<additionalClasspathElement>${basedir}/resources/jts |
|
281 |
</additionalClasspathElement> |
|
282 |
<additionalClasspathElement>${basedir}/resources/spatialindex |
|
283 |
</additionalClasspathElement> |
|
284 |
</additionalClasspathElements> |
|
285 |
</configuration> |
|
286 |
</plugin> |
|
287 |
|
|
288 |
</plugins> |
|
289 |
</build> |
|
290 |
</profile> |
|
291 |
<profile> |
|
292 |
<id>cdc</id> |
|
293 |
<activation> |
|
294 |
<activeByDefault>false</activeByDefault> |
|
295 |
</activation> |
|
296 |
<build> |
|
297 |
|
|
298 |
<plugins> |
|
299 |
<plugin> |
|
300 |
<groupId>org.apache.maven.plugins |
|
301 |
</groupId> |
|
302 |
<artifactId>maven-compiler-plugin |
|
303 |
</artifactId> |
|
304 |
<configuration> |
|
305 |
<source>1.4</source> |
|
306 |
<target>1.4</target> |
|
307 |
<!-- put your configurations here --> |
|
308 |
<encoding>ISO-8859-1</encoding> |
|
309 |
<excludes> |
|
310 |
<exclude>${jts-jarExcludes}</exclude> |
|
311 |
<exclude>**/gt2/**</exclude> |
|
312 |
<exclude>**/jsi/**</exclude> |
|
313 |
<exclude>**/spatialindex/**</exclude> |
|
314 |
</excludes> |
|
315 |
</configuration> |
|
316 |
</plugin> |
|
317 |
<plugin> |
|
318 |
<groupId>org.apache.maven.plugins |
|
319 |
</groupId> |
|
320 |
<artifactId>maven-jar-plugin</artifactId> |
|
321 |
<configuration> |
|
322 |
<excludes> |
|
323 |
<exclude>${jts-jarIncludes}</exclude> |
|
324 |
</excludes> |
|
325 |
</configuration> |
|
326 |
<executions> |
|
327 |
|
|
328 |
<!-- |
|
329 |
Generates a jar file only with the JTS based spatial index |
|
330 |
classes |
|
331 |
--> |
|
332 |
<execution> |
|
333 |
<id>jts</id> |
|
334 |
<phase>package</phase> |
|
335 |
<goals> |
|
336 |
<goal>jar</goal> |
|
337 |
</goals> |
|
338 |
<configuration> |
|
339 |
<classifier>jts</classifier> |
|
340 |
<includes> |
|
341 |
<include>${jts-jarIncludes}</include> |
|
342 |
</includes> |
|
343 |
<excludes> |
|
344 |
<exclude>${jts-jarExcludes}</exclude> |
|
345 |
<exclude>**/gt2/**</exclude> |
|
346 |
<exclude>**/jsi/**</exclude> |
|
347 |
<exclude>**/spatialindex/**</exclude> |
|
348 |
</excludes> |
|
349 |
</configuration> |
|
350 |
</execution> |
|
351 |
</executions> |
|
352 |
</plugin> |
|
353 |
</plugins> |
|
354 |
</build> |
|
355 |
</profile> |
|
356 |
<profile> |
|
357 |
<id>eclipse-project</id> |
|
358 |
<build> |
|
359 |
<defaultGoal>antrun:run</defaultGoal> |
|
360 |
<plugins> |
|
361 |
<plugin> |
|
362 |
<artifactId>maven-antrun-plugin</artifactId> |
|
363 |
<configuration> |
|
364 |
<tasks> |
|
365 |
<ant antfile="${build-dir}/ant-tasks/eclipse-tasks.xml" |
|
366 |
target="eclipse.all"/> |
|
367 |
</tasks> |
|
368 |
</configuration> |
|
369 |
</plugin> |
|
370 |
</plugins> |
|
371 |
</build> |
|
372 |
</profile> |
|
373 |
</profiles> |
|
374 |
|
|
375 |
|
|
376 |
</project> |
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/resources/gt2/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.fmap.dal.index.spatial.gt2.Gt2IndexLibrary |
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/resources/jts/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.fmap.dal.index.spatial.jts.JTSIndexLibrary |
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/resources/jsi/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.fmap.dal.index.spatial.jsi.JSIIndexLibrary |
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/resources/spatialindex/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.fmap.dal.index.spatial.spatialindex.SPTLIBIndexLibrary |
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/jsi/JSIRTree.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 15-may-2006 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib��ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id: RTreeJsi.java 13884 2007-09-19 16:26:04Z jaume $ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.5 2007-09-19 16:25:39 jaume |
|
49 |
* ReadExpansionFileException removed from this context and removed unnecessary imports |
|
50 |
* |
|
51 |
* Revision 1.4 2007/06/27 20:17:30 azabala |
|
52 |
* new spatial index (rix) |
|
53 |
* |
|
54 |
* Revision 1.3 2007/03/06 17:08:59 caballero |
|
55 |
* Exceptions |
|
56 |
* |
|
57 |
* Revision 1.2 2006/06/05 16:59:08 azabala |
|
58 |
* implementada busqueda de vecino mas proximo a partir de rectangulos |
|
59 |
* |
|
60 |
* Revision 1.1 2006/05/24 21:58:04 azabala |
|
61 |
* *** empty log message *** |
|
62 |
* |
|
63 |
* |
|
64 |
*/ |
|
65 |
package org.gvsig.fmap.dal.index.spatial.jsi; |
|
66 |
|
|
67 |
import java.util.ArrayList; |
|
68 |
import java.util.Iterator; |
|
69 |
import java.util.List; |
|
70 |
import java.util.Properties; |
|
71 |
|
|
72 |
import com.infomatiq.jsi.IntProcedure; |
|
73 |
import com.infomatiq.jsi.Rectangle; |
|
74 |
import com.infomatiq.jsi.rtree.RTree; |
|
75 |
|
|
76 |
import org.gvsig.fmap.dal.exception.DataException; |
|
77 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
78 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
|
79 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
80 |
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider; |
|
81 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
|
82 |
import org.gvsig.fmap.geom.Geometry; |
|
83 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
84 |
import org.gvsig.fmap.geom.primitive.Point; |
|
85 |
|
|
86 |
/** |
|
87 |
* RTree spatial index implementation based in library |
|
88 |
* JSI (java spatial index). |
|
89 |
* |
|
90 |
* http://jsi.sourceforge.net/ |
|
91 |
* |
|
92 |
* This RTree has better performance that Spatial Index Library |
|
93 |
* RTree, and that JTS'RTree, because |
|
94 |
* it uses the GNU's Trove Collections API. |
|
95 |
* |
|
96 |
* We are doing some probes with it, because it offers |
|
97 |
* a Nearest Neighbour algorithm implementation |
|
98 |
* (useful for Spatial Join geoprocess, for example). |
|
99 |
* |
|
100 |
* It isnt persistent, and We've found some problems |
|
101 |
* with delete operations. |
|
102 |
* |
|
103 |
* |
|
104 |
* |
|
105 |
* |
|
106 |
* @author azabala |
|
107 |
* @author jyarza |
|
108 |
* |
|
109 |
*/ |
|
110 |
public class JSIRTree extends AbstractFeatureIndexProvider implements |
|
111 |
FeatureIndexProvider { |
|
112 |
|
|
113 |
public static final String NAME = JSIRTree.class.getSimpleName(); |
|
114 |
|
|
115 |
protected RTree rtree; |
|
116 |
|
|
117 |
public JSIRTree() { |
|
118 |
} |
|
119 |
|
|
120 |
public void initialize() throws InitializeException { |
|
121 |
this.rtree = createRTree(); |
|
122 |
} |
|
123 |
|
|
124 |
private RTree createRTree() { |
|
125 |
RTree rtree = new RTree(); |
|
126 |
Properties props = new Properties(); |
|
127 |
// props.setProperty("MaxNodeEntries", "500"); |
|
128 |
// props.setProperty("MinNodeEntries", "200"); |
|
129 |
rtree.init(props); |
|
130 |
return rtree; |
|
131 |
} |
|
132 |
|
|
133 |
class ListIntProcedure implements IntProcedure { |
|
134 |
|
|
135 |
ArrayList solution = new ArrayList(); |
|
136 |
|
|
137 |
public boolean execute(int arg0) { |
|
138 |
solution.add(new Integer(arg0)); |
|
139 |
return true; |
|
140 |
} |
|
141 |
|
|
142 |
public List getSolution() { |
|
143 |
return solution; |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
protected List findNNearest(int numberOfNearest, Point point) { |
|
148 |
com.infomatiq.jsi.Point jsiPoint = |
|
149 |
new com.infomatiq.jsi.Point((float) point.getX(), |
|
150 |
(float) point.getY()); |
|
151 |
return (List) rtree.nearest(jsiPoint, numberOfNearest); |
|
152 |
} |
|
153 |
|
|
154 |
public Iterator iterator() { |
|
155 |
return rtree.iterator(); |
|
156 |
} |
|
157 |
|
|
158 |
public int size() { |
|
159 |
return rtree.size(); |
|
160 |
} |
|
161 |
|
|
162 |
protected Rectangle toJsiRect(Envelope env) { |
|
163 |
Point min = env.getLowerCorner(); |
|
164 |
Point max = env.getUpperCorner(); |
|
165 |
|
|
166 |
Rectangle jsiRect = |
|
167 |
new Rectangle((float) min.getX(), (float) min.getY(), |
|
168 |
(float) max.getX(), (float) max.getY()); |
|
169 |
return jsiRect; |
|
170 |
} |
|
171 |
|
|
172 |
public void insert(Object value, FeatureReferenceProviderServices fref) { |
|
173 |
Envelope env = getEnvelope(value); |
|
174 |
|
|
175 |
if (env == null) { |
|
176 |
throw new IllegalArgumentException( |
|
177 |
"value is neither Geometry or Envelope"); |
|
178 |
} |
|
179 |
|
|
180 |
Object oid = fref.getOID(); |
|
181 |
if (!isCompatibleOID(oid)) { |
|
182 |
throw new IllegalArgumentException("OID type not compatible: " |
|
183 |
+ oid.getClass().getName()); |
|
184 |
} |
|
185 |
|
|
186 |
rtree.add(toJsiRect(env), ((Number) oid).intValue()); |
|
187 |
} |
|
188 |
|
|
189 |
public void delete(Object value, FeatureReferenceProviderServices fref) { |
|
190 |
Envelope env = getEnvelope(value); |
|
191 |
|
|
192 |
if (env == null) { |
|
193 |
throw new IllegalArgumentException( |
|
194 |
"value is neither Geometry or Envelope"); |
|
195 |
} |
|
196 |
|
|
197 |
Object oid = fref.getOID(); |
|
198 |
if (!isCompatibleOID(oid)) { |
|
199 |
throw new IllegalArgumentException("OID type not compatible: " |
|
200 |
+ oid.getClass().getName()); |
|
201 |
} |
|
202 |
|
|
203 |
rtree.delete(toJsiRect(env), ((Number) oid).intValue()); |
|
204 |
} |
|
205 |
|
|
206 |
public List match(Object value) throws FeatureIndexException { |
|
207 |
Envelope env = getEnvelope(value); |
|
208 |
|
|
209 |
if (env == null) { |
|
210 |
throw new IllegalArgumentException( |
|
211 |
"value is neither Geometry or Envelope"); |
|
212 |
} |
|
213 |
ListIntProcedure solution = new ListIntProcedure(); |
|
214 |
rtree.intersects(toJsiRect(env), solution); |
|
215 |
return new LongList(solution.getSolution()); |
|
216 |
} |
|
217 |
|
|
218 |
public List nearest(int count, Object value) { |
|
219 |
if (value == null) { |
|
220 |
throw new IllegalArgumentException("value is null"); |
|
221 |
} |
|
222 |
|
|
223 |
if (value instanceof Point) { |
|
224 |
Point p = (Point) value; |
|
225 |
com.infomatiq.jsi.Point jsiPoint = |
|
226 |
new com.infomatiq.jsi.Point((float) p.getDirectPosition() |
|
227 |
.getOrdinate(0), (float) p.getDirectPosition().getOrdinate( |
|
228 |
1)); |
|
229 |
return (List) rtree.nearest(jsiPoint, count); |
|
230 |
} else { |
|
231 |
Envelope env = getEnvelope(value); |
|
232 |
|
|
233 |
if (env == null) { |
|
234 |
throw new IllegalArgumentException( |
|
235 |
"value is neither Geometry or Envelope"); |
|
236 |
} |
|
237 |
return new LongList((List) rtree.nearest(toJsiRect(env), count)); |
|
238 |
} |
|
239 |
} |
|
240 |
|
|
241 |
public boolean isMatchSupported() { |
|
242 |
return true; |
|
243 |
} |
|
244 |
|
|
245 |
public boolean isNearestSupported() { |
|
246 |
return true; |
|
247 |
} |
|
248 |
|
|
249 |
public boolean isNearestToleranceSupported() { |
|
250 |
return false; |
|
251 |
} |
|
252 |
|
|
253 |
public boolean isRangeSupported() { |
|
254 |
return false; |
|
255 |
} |
|
256 |
|
|
257 |
public List nearest(int count, Object value, Object tolerance) |
|
258 |
throws FeatureIndexException { |
|
259 |
throw new UnsupportedOperationException(); |
|
260 |
} |
|
261 |
|
|
262 |
public List range(Object value1, Object value2) |
|
263 |
throws FeatureIndexException { |
|
264 |
throw new UnsupportedOperationException(); |
|
265 |
} |
|
266 |
|
|
267 |
/** |
|
268 |
* Indicates whether the given OID's type is compatible |
|
269 |
* with this provider |
|
270 |
* |
|
271 |
* @param oid |
|
272 |
* |
|
273 |
* @return |
|
274 |
* true if this index provider supports the given oid type |
|
275 |
*/ |
|
276 |
private boolean isCompatibleOID(Object oid) { |
|
277 |
if (!(oid instanceof Number)) { |
|
278 |
return false; |
|
279 |
} |
|
280 |
|
|
281 |
long num = ((Number) oid).longValue(); |
|
282 |
|
|
283 |
if (num > Integer.MAX_VALUE || num < Integer.MIN_VALUE) { |
|
284 |
return false; |
|
285 |
} |
|
286 |
|
|
287 |
return true; |
|
288 |
} |
|
289 |
|
|
290 |
protected Envelope getEnvelope(Object value) { |
|
291 |
Envelope env = null; |
|
292 |
|
|
293 |
if (value instanceof Envelope) { |
|
294 |
env = (Envelope) value; |
|
295 |
} else |
|
296 |
if (value instanceof Geometry) { |
|
297 |
env = ((Geometry) value).getEnvelope(); |
|
298 |
} |
|
299 |
return env; |
|
300 |
} |
|
301 |
|
|
302 |
public void clear() throws DataException { |
|
303 |
rtree = createRTree(); |
|
304 |
} |
|
305 |
} |
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/jsi/JSIPersistentRTree.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 13-jun-2007 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib��ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id: PersistentRTreeJsi.java 12380 2007-06-27 20:17:30Z azabala $ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.1 2007-06-27 20:17:30 azabala |
|
49 |
* new spatial index (rix) |
|
50 |
* |
|
51 |
* |
|
52 |
*/ |
|
53 |
package org.gvsig.fmap.dal.index.spatial.jsi; |
|
54 |
|
|
55 |
import java.awt.geom.Point2D; |
|
56 |
import java.io.File; |
|
57 |
import java.io.FileNotFoundException; |
|
58 |
import java.io.IOException; |
|
59 |
import java.io.RandomAccessFile; |
|
60 |
import java.nio.ByteOrder; |
|
61 |
import java.nio.MappedByteBuffer; |
|
62 |
import java.nio.channels.FileChannel; |
|
63 |
import java.util.Iterator; |
|
64 |
import java.util.LinkedHashMap; |
|
65 |
import java.util.List; |
|
66 |
import java.util.Properties; |
|
67 |
|
|
68 |
import javax.imageio.stream.FileImageOutputStream; |
|
69 |
|
|
70 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
71 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
|
72 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
73 |
import org.gvsig.fmap.geom.Geometry; |
|
74 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
75 |
|
|
76 |
import com.infomatiq.jsi.Rectangle; |
|
77 |
import com.infomatiq.jsi.rtree.RTree; |
|
78 |
|
|
79 |
/** |
|
80 |
* Persistent spatial index which can resolve nearest neighbour queries. |
|
81 |
* <br> |
|
82 |
* |
|
83 |
* To use: |
|
84 |
* |
|
85 |
* PersistentRTreeJsi sptidx = new PersistentRtreeJsi("/home/kk"); |
|
86 |
* if(sptidx.exists()) |
|
87 |
* sptidx.load(); |
|
88 |
* |
|
89 |
* |
|
90 |
* sptidx.add(rect, int); |
|
91 |
* ... |
|
92 |
* sptidx.add(rect2,int2); |
|
93 |
* sptidx.flush(); |
|
94 |
* |
|
95 |
* @author azabala |
|
96 |
* |
|
97 |
*/ |
|
98 |
public class JSIPersistentRTree extends JSIRTree { |
|
99 |
|
|
100 |
public static final String NAME = JSIPersistentRTree.class.getSimpleName(); |
|
101 |
|
|
102 |
/** |
|
103 |
* Spatial index file |
|
104 |
*/ |
|
105 |
private File file; |
|
106 |
|
|
107 |
private boolean hasChanged = false; |
|
108 |
/** |
|
109 |
* Spatial index file extension |
|
110 |
*/ |
|
111 |
final String rExt = ".rix"; |
|
112 |
|
|
113 |
private LinkedHashMap rectangles; |
|
114 |
|
|
115 |
public JSIPersistentRTree() { |
|
116 |
super(); |
|
117 |
} |
|
118 |
|
|
119 |
public void initialize() throws InitializeException { |
|
120 |
super.initialize(); |
|
121 |
try { |
|
122 |
file = File.createTempFile("RTreeJsi" + getFeatureIndexProviderServices().getTemporaryFileName(), rExt); |
|
123 |
rectangles = new LinkedHashMap(); |
|
124 |
load(file); |
|
125 |
} catch (IOException e) { |
|
126 |
throw new InitializeException(e); |
|
127 |
} catch (FeatureIndexException e) { |
|
128 |
throw new InitializeException(e); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
public void flush(File f) throws FeatureIndexException { |
|
133 |
try { |
|
134 |
if(! hasChanged) { |
|
135 |
return; |
|
136 |
} |
|
137 |
RandomAccessFile file = new RandomAccessFile(f, |
|
138 |
"rw"); |
|
139 |
FileImageOutputStream output = new FileImageOutputStream(file); |
|
140 |
output.setByteOrder(ByteOrder.LITTLE_ENDIAN); |
|
141 |
int numShapes = rtree.size(); |
|
142 |
output.writeInt(numShapes); |
|
143 |
|
|
144 |
Iterator iterator = rtree.iterator(); |
|
145 |
int count = 0; |
|
146 |
while(iterator.hasNext()){ |
|
147 |
Integer idx = (Integer) iterator.next(); |
|
148 |
Rectangle nr = (Rectangle) rectangles.get(idx); |
|
149 |
float xmin = nr.min[0]; |
|
150 |
float ymin = nr.min[1]; |
|
151 |
|
|
152 |
float xmax = nr.max[0]; |
|
153 |
float ymax = nr.max[1]; |
|
154 |
|
|
155 |
output.writeFloat(xmin); |
|
156 |
output.writeFloat(ymin); |
|
157 |
output.writeFloat(xmax); |
|
158 |
output.writeFloat(ymax); |
|
159 |
|
|
160 |
output.writeInt(idx.intValue()); |
|
161 |
count++; |
|
162 |
} |
|
163 |
output.flush(); |
|
164 |
output.close(); |
|
165 |
file.close(); |
|
166 |
hasChanged = false; |
|
167 |
} catch (FileNotFoundException e) { |
|
168 |
throw new FeatureIndexException(e); |
|
169 |
} catch (IOException e) { |
|
170 |
throw new FeatureIndexException(e); |
|
171 |
} |
|
172 |
|
|
173 |
} |
|
174 |
|
|
175 |
private void load(File f) throws FeatureIndexException { |
|
176 |
if (f == null) { |
|
177 |
throw new IllegalArgumentException("File f cannot be null"); |
|
178 |
} |
|
179 |
|
|
180 |
try { |
|
181 |
if(! f.exists()){ |
|
182 |
return; |
|
183 |
} |
|
184 |
RandomAccessFile file = new RandomAccessFile(f, "r"); |
|
185 |
FileChannel channel = file.getChannel(); |
|
186 |
MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); |
|
187 |
buf.order(ByteOrder.LITTLE_ENDIAN); |
|
188 |
int numShapes = buf.getInt(); |
|
189 |
for(int i = 0; i < numShapes; i++){ |
|
190 |
float xmin, ymin, xmax, ymax; |
|
191 |
int shapeIndex; |
|
192 |
xmin = buf.getFloat(); |
|
193 |
ymin = buf.getFloat(); |
|
194 |
xmax = buf.getFloat(); |
|
195 |
ymax = buf.getFloat(); |
|
196 |
shapeIndex = buf.getInt(); |
|
197 |
|
|
198 |
Rectangle jsiRect = new Rectangle(xmin, ymin, xmax, ymax); |
|
199 |
rtree.add(jsiRect, shapeIndex); |
|
200 |
} |
|
201 |
}catch(Exception e){ |
|
202 |
throw new FeatureIndexException(e); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
public void insert(Object value, FeatureReferenceProviderServices fref) { |
|
207 |
super.insert(value, fref); |
|
208 |
Envelope env = getEnvelope(value); |
|
209 |
rectangles.put(fref.getOID(), toJsiRect(env)); |
|
210 |
hasChanged = true; |
|
211 |
} |
|
212 |
|
|
213 |
|
|
214 |
public void delete(Object value, FeatureReferenceProviderServices fref) { |
|
215 |
super.delete(value, fref); |
|
216 |
rectangles.remove(fref.getOID()); |
|
217 |
hasChanged = true; |
|
218 |
} |
|
219 |
|
|
220 |
} |
|
221 |
|
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/jsi/JSIIndexLibrary.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 {{Company}} {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.index.spatial.jsi; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.DALLibrary; |
|
31 |
import org.gvsig.fmap.dal.DALLocator; |
|
32 |
import org.gvsig.fmap.dal.DataTypes; |
|
33 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
34 |
import org.gvsig.tools.library.AbstractLibrary; |
|
35 |
import org.gvsig.tools.library.LibraryException; |
|
36 |
|
|
37 |
public class JSIIndexLibrary extends AbstractLibrary { |
|
38 |
|
|
39 |
@Override |
|
40 |
public void doRegistration() { |
|
41 |
registerAsServiceOf(DALLibrary.class); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void doInitialize() throws LibraryException { |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doPostInitialize() throws LibraryException { |
|
50 |
DataManagerProviderServices man = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
51 |
|
|
52 |
if (!man.getFeatureIndexProviders().contains(JSIPersistentRTree.NAME)) { |
|
53 |
man.registerFeatureIndexProvider(JSIPersistentRTree.NAME, "Persistent RTree index based on JSI", |
|
54 |
JSIPersistentRTree.class, DataTypes.GEOMETRY); |
|
55 |
} |
|
56 |
|
|
57 |
if (!man.getFeatureIndexProviders().contains(JSIRTree.NAME)) { |
|
58 |
man.registerFeatureIndexProvider(JSIRTree.NAME, "RTree index based on JSI", |
|
59 |
JSIRTree.class, DataTypes.GEOMETRY); |
|
60 |
} |
|
61 |
} |
|
62 |
} |
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/spatialindex/SPTLIBRTree.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.index.spatial.spatialindex; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileNotFoundException; |
|
5 |
import java.io.IOException; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
import org.gvsig.fmap.dal.exception.DataException; |
|
10 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
11 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
|
12 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
13 |
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider; |
|
14 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
|
15 |
import org.gvsig.fmap.geom.Geometry; |
|
16 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
17 |
import org.gvsig.fmap.geom.primitive.Point; |
|
18 |
|
|
19 |
import spatialindex.rtree.RTree; |
|
20 |
import spatialindex.spatialindex.IData; |
|
21 |
import spatialindex.spatialindex.INode; |
|
22 |
import spatialindex.spatialindex.IVisitor; |
|
23 |
import spatialindex.spatialindex.Region; |
|
24 |
import spatialindex.storagemanager.DiskStorageManager; |
|
25 |
import spatialindex.storagemanager.IBuffer; |
|
26 |
import spatialindex.storagemanager.IStorageManager; |
|
27 |
import spatialindex.storagemanager.PropertySet; |
|
28 |
import spatialindex.storagemanager.RandomEvictionsBuffer; |
|
29 |
|
|
30 |
/** |
|
31 |
* <p> |
|
32 |
* RTree spatial index based in spatial index library: <br> |
|
33 |
* http://u-foria.org/marioh/spatialindex/index.html <br> |
|
34 |
* marioh@cs.ucr.edu |
|
35 |
* </p> |
|
36 |
* It has the problem that spatial index file creation is a bit slowly (in |
|
37 |
* comparation with other indexes). |
|
38 |
*/ |
|
39 |
public class SPTLIBRTree extends AbstractFeatureIndexProvider implements |
|
40 |
FeatureIndexProvider { |
|
41 |
|
|
42 |
public static final String NAME = SPTLIBRTree.class.getSimpleName(); |
|
43 |
/** |
|
44 |
* Page size of associated file |
|
45 |
*/ |
|
46 |
private static final int defaultPageSize = 32 * 1024; |
|
47 |
private static final double defaultFillFactor = 0.85d; |
|
48 |
|
|
49 |
/** |
|
50 |
* Size of memory buffer of the index |
|
51 |
*/ |
|
52 |
private static final int BUFFER_SIZE = 25000; |
|
53 |
RTree rtree; |
|
54 |
String fileName; |
|
55 |
IStorageManager diskfile; |
|
56 |
|
|
57 |
public SPTLIBRTree() { |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
public void initialize() throws InitializeException { |
|
62 |
try { |
|
63 |
PropertySet ps = new PropertySet(); |
|
64 |
ps.setProperty("Overwrite", new Boolean(false)); |
|
65 |
// .idx and .dat extensions will be added. |
|
66 |
fileName = |
|
67 |
getFeatureIndexProviderServices().getNewFileName(null, null); |
|
68 |
ps.setProperty("FileName", fileName); |
|
69 |
ps.setProperty("PageSize", new Integer(defaultPageSize)); |
|
70 |
diskfile = new DiskStorageManager(ps); |
|
71 |
rtree = createRTree(); |
|
72 |
} catch (SecurityException e) { |
|
73 |
throw new InitializeException(e); |
|
74 |
} catch (FileNotFoundException e) { |
|
75 |
throw new InitializeException(e); |
|
76 |
} catch (IOException e) { |
|
77 |
throw new InitializeException(e); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* If the spatial index file exists and has content |
|
83 |
*/ |
|
84 |
public boolean exists() { |
|
85 |
return (new File(fileName + ".dat").length() != 0); |
|
86 |
} |
|
87 |
|
|
88 |
class RTreeVisitor implements IVisitor { |
|
89 |
|
|
90 |
ArrayList solution = new ArrayList(); |
|
91 |
|
|
92 |
public void visitNode(INode n) { |
|
93 |
} |
|
94 |
|
|
95 |
public void visitData(IData d) { |
|
96 |
solution.add(new Integer(d.getIdentifier())); |
|
97 |
} |
|
98 |
|
|
99 |
public List getSolution() { |
|
100 |
return solution; |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
public List containtmentQuery(Envelope env) { |
|
105 |
List solution = null; |
|
106 |
Region region = createRegion(env); |
|
107 |
RTreeVisitor visitor = new RTreeVisitor(); |
|
108 |
rtree.containmentQuery(region, visitor); |
|
109 |
solution = visitor.getSolution(); |
|
110 |
return solution; |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Warn! This RTree implemention doesnt care if 'index' entry has been |
|
115 |
* indexed yet |
|
116 |
*/ |
|
117 |
public void insert(Envelope env, int index) { |
|
118 |
rtree.insertData(null, createRegion(env), index); |
|
119 |
} |
|
120 |
|
|
121 |
private Region createRegion(Envelope env) { |
|
122 |
double[] x = new double[2]; |
|
123 |
double[] y = new double[2]; |
|
124 |
x[0] = env.getLowerCorner().getX(); |
|
125 |
y[0] = env.getLowerCorner().getY(); |
|
126 |
x[1] = env.getUpperCorner().getX(); |
|
127 |
y[1] = env.getUpperCorner().getY(); |
|
128 |
return new Region(x, y); |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Looks for N indexes nearest to the specified rect. |
|
133 |
* |
|
134 |
* @param numberOfNearest |
|
135 |
* @param rect |
|
136 |
* @return |
|
137 |
*/ |
|
138 |
public List findNNearest(int numberOfNearest, Envelope env) { |
|
139 |
List solution = null; |
|
140 |
Region region = createRegion(env); |
|
141 |
RTreeVisitor visitor = new RTreeVisitor(); |
|
142 |
rtree.nearestNeighborQuery(numberOfNearest, region, visitor); |
|
143 |
solution = visitor.getSolution(); |
|
144 |
return solution; |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* Looks for the N indexes nearest to the specified point |
|
149 |
* |
|
150 |
* @param numberOfNearest |
|
151 |
* @param point |
|
152 |
* @return |
|
153 |
*/ |
|
154 |
public List findNNearest(int numberOfNearest, Point point) { |
|
155 |
List solution = null; |
|
156 |
spatialindex.spatialindex.Point sptPoint = |
|
157 |
new spatialindex.spatialindex.Point(new double[] { point.getX(), |
|
158 |
point.getY() }); |
|
159 |
RTreeVisitor visitor = new RTreeVisitor(); |
|
160 |
rtree.nearestNeighborQuery(numberOfNearest, sptPoint, visitor); |
|
161 |
solution = visitor.getSolution(); |
|
162 |
return solution; |
|
163 |
} |
|
164 |
|
|
165 |
public void flush() { |
|
166 |
rtree.flush(); |
|
167 |
} |
|
168 |
|
|
169 |
private RTree createRTree() { |
|
170 |
// applies a main memory random buffer on top of the persistent |
|
171 |
// storage manager |
|
172 |
IBuffer buffer = |
|
173 |
new RandomEvictionsBuffer(diskfile, BUFFER_SIZE, false); |
|
174 |
|
|
175 |
// Create a new, empty, RTree with dimensionality 2, minimum load |
|
176 |
// 70%, using "file" as |
|
177 |
// the StorageManager and the RSTAR splitting policy. |
|
178 |
PropertySet ps2 = new PropertySet(); |
|
179 |
|
|
180 |
Double f = new Double(defaultFillFactor); |
|
181 |
ps2.setProperty("FillFactor", f); |
|
182 |
|
|
183 |
Integer i = new Integer(2); |
|
184 |
ps2.setProperty("Dimension", i); |
|
185 |
|
|
186 |
File file = new File(fileName + ".dat"); |
|
187 |
if (file.length() != 0) { |
|
188 |
ps2.setProperty("IndexIdentifier", new Integer(1)); |
|
189 |
} |
|
190 |
return new RTree(ps2, buffer); |
|
191 |
} |
|
192 |
|
|
193 |
public void load(File f) throws FeatureIndexException { |
|
194 |
createRTree(); |
|
195 |
} |
|
196 |
|
|
197 |
public void flush(File f) throws FeatureIndexException { |
|
198 |
flush(); |
|
199 |
} |
|
200 |
|
|
201 |
public void close() { |
|
202 |
} |
|
203 |
|
|
204 |
public File getFile() { |
|
205 |
return new File(fileName + ".dat"); |
|
206 |
} |
|
207 |
|
|
208 |
public void delete(Object value, FeatureReferenceProviderServices fref) { |
|
209 |
rtree.deleteData(createRegion(((Geometry) value).getEnvelope()), |
|
210 |
((Integer) fref.getOID()).intValue()); |
|
211 |
} |
|
212 |
|
|
213 |
public void insert(Object value, FeatureReferenceProviderServices fref) { |
|
214 |
Envelope env = null; |
|
215 |
if (value instanceof Envelope) { |
|
216 |
env = (Envelope) value; |
|
217 |
} else |
|
218 |
if (value instanceof Geometry) { |
|
219 |
env = ((Geometry) value).getEnvelope(); |
|
220 |
} |
|
221 |
rtree.insertData(null, createRegion(env), |
|
222 |
((Integer) fref.getOID()).intValue()); |
|
223 |
} |
|
224 |
|
|
225 |
public List match(Object value) throws FeatureIndexException { |
|
226 |
List solution = null; |
|
227 |
Envelope env = null; |
|
228 |
if (value instanceof Envelope) { |
|
229 |
env = (Envelope) value; |
|
230 |
} else |
|
231 |
if (value instanceof Geometry) { |
|
232 |
env = ((Geometry) value).getEnvelope(); |
|
233 |
} |
|
234 |
Region region = createRegion(env); |
|
235 |
RTreeVisitor visitor = new RTreeVisitor(); |
|
236 |
rtree.intersectionQuery(region, visitor); |
|
237 |
solution = visitor.getSolution(); |
|
238 |
return new LongList(solution); |
|
239 |
} |
|
240 |
|
|
241 |
public List match(Object min, Object max) { |
|
242 |
throw new UnsupportedOperationException(); |
|
243 |
} |
|
244 |
|
|
245 |
public List nearest(int count, Object value) throws FeatureIndexException { |
|
246 |
if (value instanceof Envelope) { |
|
247 |
return this.findNNearest(count, (Envelope) value); |
|
248 |
} else |
|
249 |
if (value instanceof Point) { |
|
250 |
return this.findNNearest(count, (Point) value); |
|
251 |
} else |
|
252 |
if (value instanceof Geometry) { |
|
253 |
return this.findNNearest(count, |
|
254 |
((Geometry) value).getEnvelope()); |
|
255 |
} else { |
|
256 |
throw new IllegalArgumentException( |
|
257 |
"value must be either an Envelope or either a Point2D"); |
|
258 |
} |
|
259 |
} |
|
260 |
|
|
261 |
public boolean isMatchSupported() { |
|
262 |
return true; |
|
263 |
} |
|
264 |
|
|
265 |
public boolean isNearestSupported() { |
|
266 |
return true; |
|
267 |
} |
|
268 |
|
|
269 |
public boolean isNearestToleranceSupported() { |
|
270 |
return false; |
|
271 |
} |
|
272 |
|
|
273 |
public boolean isRangeSupported() { |
|
274 |
// TODO Auto-generated method stub |
|
275 |
return false; |
|
276 |
} |
|
277 |
|
|
278 |
public List nearest(int count, Object value, Object tolerance) |
|
279 |
throws FeatureIndexException { |
|
280 |
throw new UnsupportedOperationException(); |
|
281 |
} |
|
282 |
|
|
283 |
public List range(Object value1, Object value2) |
|
284 |
throws FeatureIndexException { |
|
285 |
throw new UnsupportedOperationException(); |
|
286 |
} |
|
287 |
|
|
288 |
public void clear() throws DataException { |
|
289 |
rtree = createRTree(); |
|
290 |
} |
|
291 |
} |
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/spatialindex/SPTLIBIndexLibrary.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 {{Company}} {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.index.spatial.spatialindex; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.DALLibrary; |
|
31 |
import org.gvsig.fmap.dal.DALLocator; |
|
32 |
import org.gvsig.fmap.dal.DataTypes; |
|
33 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
34 |
import org.gvsig.tools.library.AbstractLibrary; |
|
35 |
import org.gvsig.tools.library.LibraryException; |
|
36 |
|
|
37 |
public class SPTLIBIndexLibrary extends AbstractLibrary { |
|
38 |
|
|
39 |
@Override |
|
40 |
public void doRegistration() { |
|
41 |
registerAsServiceOf(DALLibrary.class); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void doInitialize() throws LibraryException { |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doPostInitialize() throws LibraryException { |
|
50 |
DataManagerProviderServices man = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
51 |
|
|
52 |
|
|
53 |
if (!man.getFeatureIndexProviders().contains(SPTLIBRTree.NAME)) { |
|
54 |
man.registerFeatureIndexProvider(SPTLIBRTree.NAME, "RTree index based on spatialindex", |
|
55 |
SPTLIBRTree.class, DataTypes.GEOMETRY); |
|
56 |
} |
|
57 |
} |
|
58 |
} |
|
59 |
|
tags/v2_0_0_Build_2041/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/gt2/GT2Quadtree.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 16-may-2006 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib��ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id: QuadtreeGt2.java 10627 2007-03-06 17:10:21Z caballero $ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.3 2007-03-06 17:08:59 caballero |
|
49 |
* Exceptions |
|
50 |
* |
|
51 |
* Revision 1.2 2006/11/29 19:27:59 azabala |
|
52 |
* bug fixed (caused when we query for a bbox which is greater or equal to a layer bbox) |
|
53 |
* |
|
54 |
* Revision 1.1 2006/05/24 21:58:04 azabala |
|
55 |
* *** empty log message *** |
|
56 |
* |
|
57 |
* |
|
58 |
*/ |
|
59 |
package org.gvsig.fmap.dal.index.spatial.gt2; |
|
60 |
|
|
61 |
import java.io.File; |
|
62 |
import java.io.IOException; |
|
63 |
import java.util.List; |
|
64 |
import java.util.Stack; |
|
65 |
|
|
66 |
import com.vividsolutions.jts.geom.Envelope; |
|
67 |
|
|
68 |
import org.geotools.index.quadtree.Node; |
|
69 |
import org.geotools.index.quadtree.QuadTree; |
|
70 |
import org.geotools.index.quadtree.StoreException; |
|
71 |
import org.geotools.index.quadtree.fs.FileSystemIndexStore; |
|
72 |
import org.geotools.index.quadtree.fs.IndexHeader; |
|
73 |
|
|
74 |
import org.gvsig.fmap.dal.exception.DataException; |
|
75 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
76 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
77 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
|
78 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
79 |
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider; |
|
80 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
|
81 |
import org.gvsig.fmap.geom.Geometry; |
|
82 |
import org.gvsig.fmap.geom.primitive.Point; |
|
83 |
import org.gvsig.tools.exception.BaseException; |
|
84 |
|
|
85 |
/** |
|
86 |
* This Quadtree spatial index implementation is based in a fork of |
|
87 |
* org.geotools.index.quadtree.Quadtree implementation. <br> |
|
88 |
* This implementation offers us: |
|
89 |
* <ol> |
|
90 |
* <li>Persistence of spatial index</li> |
|
91 |
* </ol> |
|
92 |
* We had to fork geotools quadtree for many reasons: |
|
93 |
* <ol> |
|
94 |
* <li>It was strongly dependent of SHP format, so it returned not only a num of |
|
95 |
* rectangle, it also returned byte offset of this rectangle in shp file</li> |
|
96 |
* <li>Query artifact wasnt run well at all</li> |
|
97 |
* </ol> |
|
98 |
* |
|
99 |
* @author azabala |
|
100 |
* |
|
101 |
*/ |
|
102 |
public class GT2Quadtree extends AbstractFeatureIndexProvider implements |
|
103 |
FeatureIndexProvider { |
|
104 |
|
|
105 |
public static final String NAME = GT2Quadtree.class.getSimpleName(); |
|
106 |
/** |
|
107 |
* Geotools quadtree implementation |
|
108 |
*/ |
|
109 |
QuadTree quadtree; |
|
110 |
/** |
|
111 |
* Persistent storage |
|
112 |
*/ |
|
113 |
String fileName; |
|
114 |
/** |
|
115 |
* Spatial index file extension |
|
116 |
*/ |
|
117 |
final String qExt = ".qix"; |
|
118 |
/** |
|
119 |
* qix format has many versions, and allows different byte orders. |
|
120 |
*/ |
|
121 |
String byteOrder; |
|
122 |
/** |
Also available in: Unified diff