Revision 34363
tags/v2_0_0_Build_2023/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 |
</properties> |
|
50 |
|
|
51 |
<dependencies> |
|
52 |
<dependency> |
|
53 |
<groupId>org.gvsig</groupId> |
|
54 |
<artifactId>org.gvsig.fmap.dal</artifactId> |
|
55 |
<version>2.0-SNAPSHOT</version> |
|
56 |
</dependency> |
|
57 |
<dependency> |
|
58 |
<groupId>org.gvsig</groupId> |
|
59 |
<artifactId>org.gvsig.fmap.dal</artifactId> |
|
60 |
<version>2.0-SNAPSHOT</version> |
|
61 |
<classifier>spi</classifier> |
|
62 |
</dependency> |
|
63 |
<dependency> |
|
64 |
<groupId>com.vividsolutions</groupId> |
|
65 |
<artifactId>jts</artifactId> |
|
66 |
</dependency> |
|
67 |
<dependency> |
|
68 |
<groupId>net.sf</groupId> |
|
69 |
<artifactId>jsi</artifactId> |
|
70 |
</dependency> |
|
71 |
<dependency> |
|
72 |
<groupId>sil</groupId> |
|
73 |
<artifactId>sil</artifactId> |
|
74 |
<version>0.43b-am1</version> |
|
75 |
</dependency> |
|
76 |
<dependency> |
|
77 |
<groupId>gnu.trove</groupId> |
|
78 |
<artifactId>trove</artifactId> |
|
79 |
<version>0.1.8</version> |
|
80 |
</dependency> |
|
81 |
<dependency> |
|
82 |
<groupId>org.geotools</groupId> |
|
83 |
<artifactId>gt2-main</artifactId> |
|
84 |
</dependency> |
|
85 |
<dependency> |
|
86 |
<groupId>spatialindex</groupId> |
|
87 |
<artifactId>spatialindex</artifactId> |
|
88 |
</dependency> |
|
89 |
</dependencies> |
|
90 |
<build> |
|
91 |
<sourceDirectory>src</sourceDirectory> |
|
92 |
<testSourceDirectory>src-test</testSourceDirectory> |
|
93 |
<testResources> |
|
94 |
<testResource> |
|
95 |
<directory>src-test</directory> |
|
96 |
</testResource> |
|
97 |
</testResources> |
|
98 |
</build> |
|
99 |
|
|
100 |
<profiles> |
|
101 |
<profile> |
|
102 |
<id>se</id> |
|
103 |
<activation> |
|
104 |
<activeByDefault>true</activeByDefault> |
|
105 |
</activation> |
|
106 |
<build> |
|
107 |
<plugins> |
|
108 |
<plugin> |
|
109 |
<groupId>org.apache.maven.plugins |
|
110 |
</groupId> |
|
111 |
<artifactId>maven-jar-plugin</artifactId> |
|
112 |
<configuration> |
|
113 |
<excludes> |
|
114 |
<exclude>${gt2-jarIncludes}</exclude> |
|
115 |
<exclude>${jts-jarIncludes}</exclude> |
|
116 |
<exclude>${jsi-jarIncludes}</exclude> |
|
117 |
<exclude>${sptidx-jarIncludes}</exclude> |
|
118 |
</excludes> |
|
119 |
</configuration> |
|
120 |
<executions> |
|
121 |
<!-- |
|
122 |
Generates a jar file only with the GT2 based spatial index |
|
123 |
classes |
|
124 |
--> |
|
125 |
<execution> |
|
126 |
<id>gt2</id> |
|
127 |
<phase>package</phase> |
|
128 |
<goals> |
|
129 |
<goal>jar</goal> |
|
130 |
</goals> |
|
131 |
<configuration> |
|
132 |
<classifier>gt2</classifier> |
|
133 |
<includes> |
|
134 |
<include>${gt2-jarIncludes}</include> |
|
135 |
</includes> |
|
136 |
<excludes> |
|
137 |
<exclude>${gt2-jarExcludes}</exclude> |
|
138 |
</excludes> |
|
139 |
</configuration> |
|
140 |
</execution> |
|
141 |
<!-- |
|
142 |
Generates a jar file only with the JTS based spatial index |
|
143 |
classes |
|
144 |
--> |
|
145 |
<execution> |
|
146 |
<id>jts</id> |
|
147 |
<phase>package</phase> |
|
148 |
<goals> |
|
149 |
<goal>jar</goal> |
|
150 |
</goals> |
|
151 |
<configuration> |
|
152 |
<classifier>jts</classifier> |
|
153 |
<includes> |
|
154 |
<include>${jts-jarIncludes}</include> |
|
155 |
</includes> |
|
156 |
<excludes> |
|
157 |
<exclude>${jts-jarExcludes}</exclude> |
|
158 |
</excludes> |
|
159 |
</configuration> |
|
160 |
</execution> |
|
161 |
<!-- |
|
162 |
Generates a jar file only with the JSI based spatial index |
|
163 |
classes |
|
164 |
--> |
|
165 |
<execution> |
|
166 |
<id>jsi</id> |
|
167 |
<phase>package</phase> |
|
168 |
<goals> |
|
169 |
<goal>jar</goal> |
|
170 |
</goals> |
|
171 |
<configuration> |
|
172 |
<classifier>jsi</classifier> |
|
173 |
<includes> |
|
174 |
<include>${jsi-jarIncludes}</include> |
|
175 |
</includes> |
|
176 |
<excludes> |
|
177 |
<exclude>${jsi-jarExcludes}</exclude> |
|
178 |
</excludes> |
|
179 |
</configuration> |
|
180 |
</execution> |
|
181 |
<!-- |
|
182 |
Generates a jar file only with the spatialindex based spatial |
|
183 |
index classes |
|
184 |
--> |
|
185 |
<execution> |
|
186 |
<id>spatialindex</id> |
|
187 |
<phase>package</phase> |
|
188 |
<goals> |
|
189 |
<goal>jar</goal> |
|
190 |
</goals> |
|
191 |
<configuration> |
|
192 |
<classifier>spatialindex</classifier> |
|
193 |
<includes> |
|
194 |
<include>${sptidx-jarIncludes}</include> |
|
195 |
</includes> |
|
196 |
<excludes> |
|
197 |
<exclude>${sptidx-jarExcludes}</exclude> |
|
198 |
</excludes> |
|
199 |
</configuration> |
|
200 |
</execution> |
|
201 |
</executions> |
|
202 |
</plugin> |
|
203 |
<plugin> |
|
204 |
<artifactId>maven-antrun-plugin</artifactId> |
|
205 |
<executions> |
|
206 |
<execution> |
|
207 |
<id>services</id> |
|
208 |
<phase>package</phase> |
|
209 |
<goals> |
|
210 |
<goal>run</goal> |
|
211 |
</goals> |
|
212 |
<configuration> |
|
213 |
<tasks> |
|
214 |
<jar |
|
215 |
destfile="${project.build.directory}/${project.build.finalName}-gt2.jar" |
|
216 |
update="true"> |
|
217 |
<fileset dir="${basedir}/resources/gt2" /> |
|
218 |
</jar> |
|
219 |
<jar |
|
220 |
destfile="${project.build.directory}/${project.build.finalName}-jsi.jar" |
|
221 |
update="true"> |
|
222 |
<fileset dir="${basedir}/resources/jsi" /> |
|
223 |
</jar> |
|
224 |
<jar |
|
225 |
destfile="${project.build.directory}/${project.build.finalName}-jts.jar" |
|
226 |
update="true"> |
|
227 |
<fileset dir="${basedir}/resources/jts" /> |
|
228 |
</jar> |
|
229 |
<jar |
|
230 |
destfile="${project.build.directory}/${project.build.finalName}-spatialindex.jar" |
|
231 |
update="true"> |
|
232 |
<fileset dir="${basedir}/resources/spatialindex" /> |
|
233 |
</jar> |
|
234 |
</tasks> |
|
235 |
</configuration> |
|
236 |
</execution> |
|
237 |
</executions> |
|
238 |
</plugin> |
|
239 |
<plugin> |
|
240 |
<groupId>org.apache.maven.plugins |
|
241 |
</groupId> |
|
242 |
<artifactId>maven-surefire-plugin |
|
243 |
</artifactId> |
|
244 |
<configuration> |
|
245 |
<additionalClasspathElements> |
|
246 |
<additionalClasspathElement>${basedir}/resources/gt2 |
|
247 |
</additionalClasspathElement> |
|
248 |
<additionalClasspathElement>${basedir}/resources/jsi |
|
249 |
</additionalClasspathElement> |
|
250 |
<additionalClasspathElement>${basedir}/resources/jts |
|
251 |
</additionalClasspathElement> |
|
252 |
<additionalClasspathElement>${basedir}/resources/spatialindex |
|
253 |
</additionalClasspathElement> |
|
254 |
</additionalClasspathElements> |
|
255 |
</configuration> |
|
256 |
</plugin> |
|
257 |
|
|
258 |
</plugins> |
|
259 |
</build> |
|
260 |
</profile> |
|
261 |
<profile> |
|
262 |
<id>cdc</id> |
|
263 |
<activation> |
|
264 |
<activeByDefault>false</activeByDefault> |
|
265 |
</activation> |
|
266 |
<build> |
|
267 |
|
|
268 |
<plugins> |
|
269 |
<plugin> |
|
270 |
<groupId>org.apache.maven.plugins |
|
271 |
</groupId> |
|
272 |
<artifactId>maven-compiler-plugin |
|
273 |
</artifactId> |
|
274 |
<configuration> |
|
275 |
<source>1.4</source> |
|
276 |
<target>1.4</target> |
|
277 |
<!-- put your configurations here --> |
|
278 |
<encoding>ISO-8859-1</encoding> |
|
279 |
<excludes> |
|
280 |
<exclude>${jts-jarExcludes}</exclude> |
|
281 |
<exclude>**/gt2/**</exclude> |
|
282 |
<exclude>**/jsi/**</exclude> |
|
283 |
<exclude>**/spatialindex/**</exclude> |
|
284 |
</excludes> |
|
285 |
</configuration> |
|
286 |
</plugin> |
|
287 |
<plugin> |
|
288 |
<groupId>org.apache.maven.plugins |
|
289 |
</groupId> |
|
290 |
<artifactId>maven-jar-plugin</artifactId> |
|
291 |
<configuration> |
|
292 |
<excludes> |
|
293 |
<exclude>${jts-jarIncludes}</exclude> |
|
294 |
</excludes> |
|
295 |
</configuration> |
|
296 |
<executions> |
|
297 |
|
|
298 |
<!-- |
|
299 |
Generates a jar file only with the JTS based spatial index |
|
300 |
classes |
|
301 |
--> |
|
302 |
<execution> |
|
303 |
<id>jts</id> |
|
304 |
<phase>package</phase> |
|
305 |
<goals> |
|
306 |
<goal>jar</goal> |
|
307 |
</goals> |
|
308 |
<configuration> |
|
309 |
<classifier>jts</classifier> |
|
310 |
<includes> |
|
311 |
<include>${jts-jarIncludes}</include> |
|
312 |
</includes> |
|
313 |
<excludes> |
|
314 |
<exclude>${jts-jarExcludes}</exclude> |
|
315 |
<exclude>**/gt2/**</exclude> |
|
316 |
<exclude>**/jsi/**</exclude> |
|
317 |
<exclude>**/spatialindex/**</exclude> |
|
318 |
</excludes> |
|
319 |
</configuration> |
|
320 |
</execution> |
|
321 |
</executions> |
|
322 |
</plugin> |
|
323 |
</plugins> |
|
324 |
</build> |
|
325 |
</profile> |
|
326 |
<profile> |
|
327 |
<id>eclipse-project</id> |
|
328 |
<build> |
|
329 |
<defaultGoal>antrun:run</defaultGoal> |
|
330 |
<plugins> |
|
331 |
<plugin> |
|
332 |
<artifactId>maven-antrun-plugin</artifactId> |
|
333 |
<configuration> |
|
334 |
<tasks> |
|
335 |
<ant antfile="${build-dir}/ant-tasks/eclipse-tasks.xml" |
|
336 |
target="eclipse.all"/> |
|
337 |
</tasks> |
|
338 |
</configuration> |
|
339 |
</plugin> |
|
340 |
</plugins> |
|
341 |
</build> |
|
342 |
</profile> |
|
343 |
</profiles> |
|
344 |
|
|
345 |
|
|
346 |
</project> |
tags/v2_0_0_Build_2023/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_2023/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_2023/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_2023/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_2023/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 org.geotools.index.quadtree.Node; |
|
67 |
import org.geotools.index.quadtree.QuadTree; |
|
68 |
import org.geotools.index.quadtree.StoreException; |
|
69 |
import org.geotools.index.quadtree.fs.FileSystemIndexStore; |
|
70 |
import org.geotools.index.quadtree.fs.IndexHeader; |
|
71 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
72 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
73 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
|
74 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
75 |
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider; |
|
76 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
|
77 |
import org.gvsig.fmap.geom.Geometry; |
|
78 |
import org.gvsig.fmap.geom.primitive.Point; |
|
79 |
import org.gvsig.tools.exception.BaseException; |
|
80 |
|
|
81 |
import com.vividsolutions.jts.geom.Envelope; |
|
82 |
|
|
83 |
/** |
|
84 |
* This Quadtree spatial index implementation is based in a fork of |
|
85 |
* org.geotools.index.quadtree.Quadtree implementation. <br> |
|
86 |
* This implementation offers us: |
|
87 |
* <ol> |
|
88 |
* <li>Persistence of spatial index</li> |
|
89 |
* </ol> |
|
90 |
* We had to fork geotools quadtree for many reasons: |
|
91 |
* <ol> |
|
92 |
* <li>It was strongly dependent of SHP format, so it returned not only a num |
|
93 |
* of rectangle, it also returned byte offset of this rectangle in shp file</li> |
|
94 |
* <li> Query artifact wasnt run well at all </li> |
|
95 |
* </ol> |
|
96 |
* |
|
97 |
* @author azabala |
|
98 |
* |
|
99 |
*/ |
|
100 |
public class GT2Quadtree extends AbstractFeatureIndexProvider implements FeatureIndexProvider { |
|
101 |
|
|
102 |
public static final String NAME = GT2Quadtree.class.getSimpleName(); |
|
103 |
/** |
|
104 |
* Geotools quadtree implementation |
|
105 |
*/ |
|
106 |
QuadTree quadtree; |
|
107 |
/** |
|
108 |
* Persistent storage |
|
109 |
*/ |
|
110 |
String fileName; |
|
111 |
/** |
|
112 |
* Spatial index file extension |
|
113 |
*/ |
|
114 |
final String qExt = ".qix"; |
|
115 |
/** |
|
116 |
* qix format has many versions, and allows different byte orders. |
|
117 |
*/ |
|
118 |
String byteOrder; |
|
119 |
/** |
|
120 |
* Bounds of the layer to index |
|
121 |
*/ |
|
122 |
//Envelope bounds; |
|
123 |
/** |
|
124 |
* Number of records of the layer to index |
|
125 |
*/ |
|
126 |
//int numRecs = 0; |
|
127 |
|
|
128 |
boolean inMemory = false; |
|
129 |
|
|
130 |
public GT2Quadtree() { |
|
131 |
|
|
132 |
} |
|
133 |
|
|
134 |
public void initialize() throws InitializeException { |
|
135 |
try { |
|
136 |
File file = File.createTempFile(getFeatureStore().getName(), ".qix"); |
|
137 |
this.fileName = file.getAbsolutePath(); |
|
138 |
org.gvsig.fmap.geom.primitive.Envelope env = getFeatureStore() |
|
139 |
.getEnvelope(); |
|
140 |
int featureCount = (int) getFeatureStore().getFeatureCount(); |
|
141 |
this.byteOrder = "NM"; |
|
142 |
quadtree = new QuadTree(featureCount, toJtsEnvelope(env)); |
|
143 |
if (exists()) { |
|
144 |
load(); |
|
145 |
} |
|
146 |
} catch (IOException e) { |
|
147 |
throw new InitializeException(e); |
|
148 |
} catch (BaseException e) { |
|
149 |
throw new InitializeException(e); |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* If the spatial index file exists and has content |
|
155 |
*/ |
|
156 |
public boolean exists() { |
|
157 |
return (new File(fileName).length() != 0); |
|
158 |
} |
|
159 |
|
|
160 |
public void load() throws FeatureIndexException { |
|
161 |
if (quadtree == null) { |
|
162 |
load(new File(fileName)); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
public void load(File f) throws FeatureIndexException { |
|
167 |
try { |
|
168 |
FileSystemIndexStore store = new FileSystemIndexStore(f); |
|
169 |
quadtree = store.load(); |
|
170 |
this.fileName = f.getAbsolutePath(); |
|
171 |
} catch (StoreException e) { |
|
172 |
throw new FeatureIndexException(e); |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Inserts an object in the index |
|
178 |
*/ |
|
179 |
public void insert(org.gvsig.fmap.geom.primitive.Envelope env, int index) { |
|
180 |
if (env == null) { |
|
181 |
throw new IllegalArgumentException("Envelope cannot be null"); |
|
182 |
} |
|
183 |
Envelope e = toJtsEnvelope(env); |
|
184 |
if (e == null) { |
|
185 |
throw new IllegalStateException( |
|
186 |
"JTS Envelope conversion returns null"); |
|
187 |
} |
|
188 |
System.out.println("recno=" + index); |
|
189 |
if (quadtree == null) { |
|
190 |
throw new IllegalStateException("quadtree is null"); |
|
191 |
} |
|
192 |
try { |
|
193 |
quadtree.insert(index, toJtsEnvelope(env)); |
|
194 |
} catch (StoreException se) { |
|
195 |
// TODO Auto-generated catch block |
|
196 |
se.printStackTrace(); |
|
197 |
} |
|
198 |
} |
|
199 |
|
|
200 |
public void delete(org.gvsig.fmap.geom.primitive.Envelope env, int index) { |
|
201 |
if (inMemory) { |
|
202 |
quadtree.delete(toJtsEnvelope(env), index); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
public Envelope toJtsEnvelope(org.gvsig.fmap.geom.primitive.Envelope env) { |
|
207 |
if (env == null) { |
|
208 |
return null; |
|
209 |
} |
|
210 |
Point min = env.getLowerCorner(); |
|
211 |
Point max = env.getUpperCorner(); |
|
212 |
|
|
213 |
return new Envelope(min.getX(), max.getX(), min.getY(), max.getY()); |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* |
|
218 |
* @throws StoreException |
|
219 |
* @deprecated |
|
220 |
*/ |
|
221 |
void openQuadTree() throws StoreException { |
|
222 |
if (quadtree == null) { |
|
223 |
File file = new File(this.fileName); |
|
224 |
// Intento de cargar todo el quadtree en memoria |
|
225 |
FileSystemIndexStore store = new FileSystemIndexStore(file); |
|
226 |
quadtree = store.load(); |
|
227 |
} |
|
228 |
} |
|
229 |
|
|
230 |
void openQuadTreeInMemory() throws StoreException { |
|
231 |
if (quadtree == null) { |
|
232 |
File file = new File(fileName); |
|
233 |
// Intento de cargar todo el quadtree en memoria |
|
234 |
FileSystemIndexStore store = new FileSystemIndexStore(file); |
|
235 |
QuadTree filequadtree = store.load(); |
|
236 |
quadtree = new QuadTree(filequadtree.getNumShapes(), filequadtree |
|
237 |
.getMaxDepth(), filequadtree.getRoot().getBounds()); |
|
238 |
Stack nodes = new Stack(); |
|
239 |
nodes.push(filequadtree.getRoot()); |
|
240 |
while (nodes.size() != 0) { |
|
241 |
Node node = (Node) nodes.pop(); |
|
242 |
Envelope nodeEnv = node.getBounds(); |
|
243 |
int[] shapeIds = node.getShapesId(); |
|
244 |
for (int i = 0; i < shapeIds.length; i++) { |
|
245 |
quadtree.insert(shapeIds[i], nodeEnv); |
|
246 |
} |
|
247 |
int numSubnodes = node.getNumSubNodes(); |
|
248 |
for (int i = 0; i < numSubnodes; i++) { |
|
249 |
nodes.push(node.getSubNode(i)); |
|
250 |
} |
|
251 |
}// while |
|
252 |
filequadtree.close(); |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
public void flush() throws FeatureIndexException { |
|
257 |
flush(new File(fileName)); |
|
258 |
} |
|
259 |
|
|
260 |
public void flush(File f) throws FeatureIndexException { |
|
261 |
byte order = 0; |
|
262 |
if ((byteOrder == null) || byteOrder.equalsIgnoreCase("NM")) { |
|
263 |
order = IndexHeader.NEW_MSB_ORDER; |
|
264 |
} else if (byteOrder.equalsIgnoreCase("NL")) { |
|
265 |
order = IndexHeader.NEW_LSB_ORDER; |
|
266 |
} |
|
267 |
FileSystemIndexStore store = new FileSystemIndexStore(f, order); |
|
268 |
try { |
|
269 |
store.store(quadtree); |
|
270 |
this.fileName = f.getAbsolutePath(); |
|
271 |
} catch (StoreException e) { |
|
272 |
throw new FeatureIndexException(e); |
|
273 |
} |
|
274 |
} |
|
275 |
|
|
276 |
public File getFile() { |
|
277 |
return new File(this.fileName); |
|
278 |
} |
|
279 |
|
|
280 |
private FeatureStore getFeatureStore() { |
|
281 |
return getFeatureIndexProviderServices() |
|
282 |
.getFeatureStoreProviderServices().getFeatureStore(); |
|
283 |
} |
|
284 |
|
|
285 |
public void delete(Object value, FeatureReferenceProviderServices fref) { |
|
286 |
|
|
287 |
if (!isCompatibleOID(fref.getOID())) { |
|
288 |
throw new IllegalArgumentException("OID not compatible. Must be an instance of Number within the Integer range."); |
|
289 |
} |
|
290 |
|
|
291 |
delete(((org.gvsig.fmap.geom.Geometry) value).getEnvelope(), ((Number) fref.getOID()).intValue()); |
|
292 |
} |
|
293 |
|
|
294 |
public void insert(Object value, FeatureReferenceProviderServices fref) { |
|
295 |
|
|
296 |
if (!isCompatibleOID(fref.getOID())) { |
|
297 |
throw new IllegalArgumentException("OID not compatible. Must be an instance of Number within the Integer range."); |
|
298 |
} |
|
299 |
|
|
300 |
insert(((org.gvsig.fmap.geom.Geometry) value).getEnvelope(), ((Number) fref.getOID()).intValue()); |
|
301 |
} |
|
302 |
|
|
303 |
public List match(Object value) throws FeatureIndexException { |
|
304 |
if (quadtree == null) { |
|
305 |
throw new IllegalStateException("This quadtree is null."); |
|
306 |
} |
|
307 |
if (value == null) { |
|
308 |
throw new IllegalArgumentException("Envelope cannot be null."); |
|
309 |
} |
|
310 |
if (!(value instanceof org.gvsig.fmap.geom.primitive.Envelope)) { |
|
311 |
throw new IllegalArgumentException("Not an envelope."); |
|
312 |
} |
|
313 |
org.gvsig.fmap.geom.primitive.Envelope env = null; |
|
314 |
if (value instanceof org.gvsig.fmap.geom.primitive.Envelope) { |
|
315 |
env = (org.gvsig.fmap.geom.primitive.Envelope) value; |
|
316 |
} else if (value instanceof Geometry) { |
|
317 |
env = ((Geometry) value).getEnvelope(); |
|
318 |
} |
|
319 |
return new LongList(quadtree.query(toJtsEnvelope(env))); |
|
320 |
} |
|
321 |
|
|
322 |
public List nearest(int count, Object value) throws FeatureIndexException { |
|
323 |
throw new UnsupportedOperationException(); |
|
324 |
} |
|
325 |
|
|
326 |
public boolean isMatchSupported() { |
|
327 |
return true; |
|
328 |
} |
|
329 |
|
|
330 |
public boolean isNearestSupported() { |
|
331 |
return false; |
|
332 |
} |
|
333 |
|
|
334 |
public boolean isNearestToleranceSupported() { |
|
335 |
return false; |
|
336 |
} |
|
337 |
|
|
338 |
public boolean isRangeSupported() { |
|
339 |
return false; |
|
340 |
} |
|
341 |
|
|
342 |
public List nearest(int count, Object value, Object tolerance) |
|
343 |
throws FeatureIndexException { |
|
344 |
throw new UnsupportedOperationException(); |
|
345 |
} |
|
346 |
|
|
347 |
public List range(Object value1, Object value2) throws FeatureIndexException { |
|
348 |
throw new UnsupportedOperationException(); |
|
349 |
} |
|
350 |
|
|
351 |
/** |
|
352 |
* Indicates whether the given OID's type is compatible |
|
353 |
* with this provider |
|
354 |
* |
|
355 |
* @param oid |
|
356 |
* |
|
357 |
* @return |
|
358 |
* true if this index provider supports the given oid type |
|
359 |
*/ |
|
360 |
private boolean isCompatibleOID(Object oid) { |
|
361 |
if (!(oid instanceof Number)) { |
|
362 |
return false; |
|
363 |
} |
|
364 |
|
|
365 |
long num = ((Number) oid).longValue(); |
|
366 |
|
|
367 |
if (num > Integer.MAX_VALUE || num < Integer.MIN_VALUE) { |
|
368 |
return false; |
|
369 |
} |
|
370 |
|
|
371 |
return true; |
|
372 |
} |
|
373 |
|
|
374 |
} |
tags/v2_0_0_Build_2023/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/gt2/Gt2IndexLibrary.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 |
|
|
29 |
package org.gvsig.fmap.dal.index.spatial.gt2; |
|
30 |
|
|
31 |
import org.gvsig.fmap.dal.DALLibrary; |
|
32 |
import org.gvsig.fmap.dal.DALLocator; |
|
33 |
import org.gvsig.fmap.dal.DataTypes; |
|
34 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
35 |
import org.gvsig.tools.library.AbstractLibrary; |
|
36 |
import org.gvsig.tools.library.LibraryException; |
|
37 |
|
|
38 |
public class Gt2IndexLibrary extends AbstractLibrary { |
|
39 |
|
|
40 |
public Gt2IndexLibrary() { |
|
41 |
super(Gt2IndexLibrary.class, TYPE.API); |
|
42 |
require(DALLibrary.class); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
protected void doInitialize() throws LibraryException { |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
protected void doPostInitialize() throws LibraryException { |
|
51 |
DataManagerProviderServices man = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
52 |
|
|
53 |
if (!man.getFeatureIndexProviders().contains(GT2Quadtree.NAME)) { |
|
54 |
man.registerFeatureIndexProvider(GT2Quadtree.NAME, "Quadtree index based on Geotools 2", |
|
55 |
GT2Quadtree.class, DataTypes.GEOMETRY); |
|
56 |
} |
|
57 |
} |
|
58 |
} |
tags/v2_0_0_Build_2023/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/jts/JTSQuadtree.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 28-abr-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: QuadtreeJts.java 11288 2007-04-19 17:32:50Z azabala $ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.2 2007-04-19 17:32:50 azabala |
|
49 |
* new constructor (fmap spatial index from an existing jts spatial index) |
|
50 |
* |
|
51 |
* Revision 1.1 2006/05/01 18:38:41 azabala |
|
52 |
* primera version en cvs del api de indices espaciales |
|
53 |
* |
|
54 |
* |
|
55 |
*/ |
|
56 |
package org.gvsig.fmap.dal.index.spatial.jts; |
|
57 |
|
|
58 |
import java.util.List; |
|
59 |
|
|
60 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
|
61 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
62 |
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider; |
|
63 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
|
64 |
import org.gvsig.fmap.geom.Geometry; |
|
65 |
import org.gvsig.fmap.geom.primitive.NullGeometry; |
|
66 |
import org.gvsig.fmap.geom.primitive.Point; |
|
67 |
|
|
68 |
import com.vividsolutions.jts.geom.Envelope; |
|
69 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
|
70 |
/** |
|
71 |
* Adapter for ISPatialIndex gvSIG's interface to |
|
72 |
* JTS Quadtree. |
|
73 |
* |
|
74 |
* |
|
75 |
* @author azabala |
|
76 |
* |
|
77 |
*/ |
|
78 |
public class JTSQuadtree extends AbstractFeatureIndexProvider implements FeatureIndexProvider { |
|
79 |
|
|
80 |
public static final String NAME = JTSQuadtree.class.getName(); |
|
81 |
|
|
82 |
private Quadtree quadtree; |
|
83 |
|
|
84 |
public JTSQuadtree() { |
|
85 |
} |
|
86 |
|
|
87 |
public void initialize() { |
|
88 |
quadtree = new Quadtree(); |
|
89 |
} |
|
90 |
|
|
91 |
private Envelope fromEnvelope(org.gvsig.fmap.geom.primitive.Envelope env){ |
|
92 |
Point min = env.getLowerCorner(); |
|
93 |
Point max = env.getUpperCorner(); |
|
94 |
Envelope env2 = new Envelope(min.getX(), max.getX(), min.getY(), max.getY()); |
|
95 |
return env2; |
|
96 |
} |
|
97 |
|
|
98 |
public void delete(Object o, FeatureReferenceProviderServices fref) { |
|
99 |
Integer integer=new Integer(((Long)(fref).getOID()).intValue()); |
|
100 |
quadtree.remove( |
|
101 |
fromEnvelope(((Geometry) o).getEnvelope()), integer); |
|
102 |
} |
|
103 |
|
|
104 |
public void insert(Object o, FeatureReferenceProviderServices fref) { |
|
105 |
if (o == null || o instanceof NullGeometry) { |
|
106 |
return; |
|
107 |
} |
|
108 |
Integer integer=new Integer(((Long)(fref).getOID()).intValue()); |
|
109 |
quadtree.insert( |
|
110 |
fromEnvelope(((Geometry) o).getEnvelope()), integer); |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
public List match(Object value) throws FeatureIndexException { |
|
115 |
org.gvsig.fmap.geom.primitive.Envelope env = null; |
|
116 |
if (value instanceof org.gvsig.fmap.geom.primitive.Envelope) { |
|
117 |
env = (org.gvsig.fmap.geom.primitive.Envelope) value; |
|
118 |
} else if (value instanceof Geometry) { |
|
119 |
env = ((Geometry) value).getEnvelope(); |
|
120 |
} |
|
121 |
return new LongList(quadtree.query(fromEnvelope(env))); |
|
122 |
} |
|
123 |
|
|
124 |
public List match(Object min, Object max) { |
|
125 |
throw new UnsupportedOperationException("Can't perform this kind of search."); |
|
126 |
} |
|
127 |
|
|
128 |
public List nearest(int count, Object value) throws FeatureIndexException { |
|
129 |
throw new UnsupportedOperationException("Can't perform this kind of search."); |
|
130 |
} |
|
131 |
|
|
132 |
public boolean isMatchSupported() { |
|
133 |
return true; |
|
134 |
} |
|
135 |
|
|
136 |
public boolean isNearestSupported() { |
|
137 |
return false; |
|
138 |
} |
|
139 |
|
|
140 |
public boolean isNearestToleranceSupported() { |
|
141 |
return false; |
|
142 |
} |
|
143 |
|
|
144 |
public boolean isRangeSupported() { |
|
145 |
return false; |
|
146 |
} |
|
147 |
|
|
148 |
public List nearest(int count, Object value, Object tolerance) |
|
149 |
throws FeatureIndexException { |
|
150 |
throw new UnsupportedOperationException(); |
|
151 |
} |
|
152 |
|
|
153 |
public List range(Object value1, Object value2) |
|
154 |
throws FeatureIndexException { |
|
155 |
throw new UnsupportedOperationException(); |
|
156 |
} |
|
157 |
} |
|
158 |
|
tags/v2_0_0_Build_2023/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/jts/JTSIndexLibrary.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.jts; |
|
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 JTSIndexLibrary extends AbstractLibrary { |
|
38 |
|
|
39 |
public JTSIndexLibrary() { |
|
40 |
super(JTSIndexLibrary.class, TYPE.IMPL); |
|
41 |
require(DALLibrary.class); |
|
42 |
} |
|
43 |
|
|
44 |
protected void doInitialize() throws LibraryException { |
|
45 |
} |
|
46 |
|
|
47 |
protected void doPostInitialize() throws LibraryException { |
|
48 |
DataManagerProviderServices man = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
49 |
|
|
50 |
|
|
51 |
if (!man.getFeatureIndexProviders().contains(JTSQuadtree.NAME)) { |
|
52 |
man.registerFeatureIndexProvider(JTSQuadtree.NAME, "Quadtree index based on JTS", |
|
53 |
JTSQuadtree.class, DataTypes.GEOMETRY); |
|
54 |
man.setDefaultFeatureIndexProviderName(DataTypes.GEOMETRY, JTSQuadtree.NAME); |
|
55 |
} |
|
56 |
} |
|
57 |
} |
|
58 |
|
tags/v2_0_0_Build_2023/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 org.gvsig.fmap.dal.exception.InitializeException; |
|
73 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
|
74 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
75 |
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider; |
|
76 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
|
77 |
import org.gvsig.fmap.geom.Geometry; |
|
78 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
79 |
import org.gvsig.fmap.geom.primitive.Point; |
|
80 |
|
|
81 |
import com.infomatiq.jsi.IntProcedure; |
|
82 |
import com.infomatiq.jsi.Rectangle; |
|
83 |
import com.infomatiq.jsi.rtree.RTree; |
|
84 |
|
|
85 |
/** |
|
86 |
* RTree spatial index implementation based in library |
|
87 |
* JSI (java spatial index). |
|
88 |
* |
|
89 |
* http://jsi.sourceforge.net/ |
|
90 |
* |
|
91 |
* This RTree has better performance that Spatial Index Library |
|
92 |
* RTree, and that JTS'RTree, because |
|
93 |
* it uses the GNU's Trove Collections API. |
|
94 |
* |
|
95 |
* We are doing some probes with it, because it offers |
|
96 |
* a Nearest Neighbour algorithm implementation |
|
97 |
* (useful for Spatial Join geoprocess, for example). |
|
98 |
* |
|
99 |
* It isnt persistent, and We've found some problems |
|
100 |
* with delete operations. |
|
101 |
* |
|
102 |
* |
|
103 |
* |
|
104 |
* |
|
105 |
* @author azabala |
|
106 |
* @author jyarza |
|
107 |
* |
|
108 |
*/ |
|
109 |
public class JSIRTree extends AbstractFeatureIndexProvider implements FeatureIndexProvider { |
|
110 |
|
|
111 |
public static final String NAME = JSIRTree.class.getSimpleName(); |
|
112 |
|
|
113 |
protected RTree rtree; |
|
114 |
|
|
115 |
public JSIRTree() { |
|
116 |
rtree = new RTree(); |
|
117 |
} |
|
118 |
|
|
119 |
|
|
120 |
public void initialize() throws InitializeException { |
|
121 |
Properties props = new Properties(); |
|
122 |
// props.setProperty("MaxNodeEntries", "500"); |
|
123 |
// props.setProperty("MinNodeEntries", "200"); |
|
124 |
rtree.init(props); |
|
125 |
} |
|
126 |
|
|
127 |
class ListIntProcedure implements IntProcedure{ |
|
128 |
ArrayList solution = new ArrayList(); |
|
129 |
|
|
130 |
public boolean execute(int arg0) { |
|
131 |
solution.add(new Integer(arg0)); |
|
132 |
return true; |
|
133 |
} |
|
134 |
|
|
135 |
public List getSolution(){ |
|
136 |
return solution; |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
protected List findNNearest(int numberOfNearest, Point point){ |
|
141 |
com.infomatiq.jsi.Point jsiPoint = |
|
142 |
new com.infomatiq.jsi.Point((float)point.getX(), (float)point.getY()); |
|
143 |
return (List) rtree.nearest(jsiPoint, numberOfNearest); |
|
144 |
} |
|
145 |
|
|
146 |
public Iterator iterator(){ |
|
147 |
return rtree.iterator(); |
|
148 |
} |
|
149 |
|
|
150 |
public int size(){ |
|
151 |
return rtree.size(); |
|
152 |
} |
|
153 |
|
|
154 |
protected Rectangle toJsiRect(Envelope env){ |
|
155 |
Point min = env.getLowerCorner(); |
|
156 |
Point max = env.getUpperCorner(); |
|
157 |
|
|
158 |
Rectangle jsiRect = new Rectangle((float)min.getX(), |
|
159 |
(float)min.getY(), |
|
160 |
(float)max.getX(), |
|
161 |
(float)max.getY()); |
|
162 |
return jsiRect; |
|
163 |
} |
|
164 |
|
|
165 |
public void insert(Object value, FeatureReferenceProviderServices fref) { |
|
166 |
Envelope env = getEnvelope(value); |
|
167 |
|
|
168 |
if (env == null) { |
|
169 |
throw new IllegalArgumentException("value is neither Geometry or Envelope"); |
|
170 |
} |
|
171 |
|
|
172 |
Object oid = fref.getOID(); |
|
173 |
if (!isCompatibleOID(oid)) { |
|
174 |
throw new IllegalArgumentException("OID type not compatible: " + oid.getClass().getName()); |
|
175 |
} |
|
176 |
|
|
177 |
rtree.add(toJsiRect(env), ((Number) oid).intValue()); |
|
178 |
} |
|
179 |
|
|
180 |
public void delete(Object value, FeatureReferenceProviderServices fref) { |
|
181 |
Envelope env = getEnvelope(value); |
|
182 |
|
|
183 |
if (env == null) { |
|
184 |
throw new IllegalArgumentException("value is neither Geometry or Envelope"); |
|
185 |
} |
|
186 |
|
|
187 |
Object oid = fref.getOID(); |
|
188 |
if (!isCompatibleOID(oid)) { |
|
189 |
throw new IllegalArgumentException("OID type not compatible: " + oid.getClass().getName()); |
|
190 |
} |
|
191 |
|
|
192 |
rtree.delete(toJsiRect(env), ((Number) oid).intValue()); |
|
193 |
} |
|
194 |
|
|
195 |
public List match(Object value) throws FeatureIndexException { |
|
196 |
Envelope env = getEnvelope(value); |
|
197 |
|
|
198 |
if (env == null) { |
|
199 |
throw new IllegalArgumentException("value is neither Geometry or Envelope"); |
|
200 |
} |
|
201 |
ListIntProcedure solution = new ListIntProcedure(); |
|
202 |
rtree.intersects(toJsiRect(env), solution); |
|
203 |
return new LongList(solution.getSolution()); |
|
204 |
} |
|
205 |
|
|
206 |
public List nearest(int count, Object value) { |
|
207 |
if (value == null) { |
|
208 |
throw new IllegalArgumentException("value is null"); |
|
209 |
} |
|
210 |
|
|
211 |
if (value instanceof Point) { |
|
212 |
Point p = (Point) value; |
|
213 |
com.infomatiq.jsi.Point jsiPoint = |
|
214 |
new com.infomatiq.jsi.Point((float) p.getDirectPosition().getOrdinate(0), (float) p.getDirectPosition().getOrdinate(1)); |
|
215 |
return (List) rtree.nearest(jsiPoint, count); |
|
216 |
} else { |
|
217 |
Envelope env = getEnvelope(value); |
|
218 |
|
|
219 |
if (env == null) { |
|
220 |
throw new IllegalArgumentException("value is neither Geometry or Envelope"); |
|
221 |
} |
|
222 |
return new LongList((List) rtree.nearest(toJsiRect(env), count)); |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
226 |
|
|
227 |
public boolean isMatchSupported() { |
|
228 |
return true; |
|
229 |
} |
|
230 |
|
|
231 |
public boolean isNearestSupported() { |
|
232 |
return true; |
|
233 |
} |
|
234 |
|
|
235 |
public boolean isNearestToleranceSupported() { |
|
236 |
return false; |
|
237 |
} |
|
238 |
|
|
239 |
public boolean isRangeSupported() { |
|
240 |
return false; |
|
241 |
} |
|
242 |
|
|
243 |
public List nearest(int count, Object value, Object tolerance) |
|
244 |
throws FeatureIndexException { |
|
245 |
throw new UnsupportedOperationException(); |
|
246 |
} |
|
247 |
|
|
248 |
public List range(Object value1, Object value2) throws FeatureIndexException { |
|
249 |
throw new UnsupportedOperationException(); |
|
250 |
} |
|
251 |
|
|
252 |
/** |
|
253 |
* Indicates whether the given OID's type is compatible |
|
254 |
* with this provider |
|
255 |
* |
|
256 |
* @param oid |
|
257 |
* |
|
258 |
* @return |
|
259 |
* true if this index provider supports the given oid type |
|
260 |
*/ |
|
261 |
private boolean isCompatibleOID(Object oid) { |
|
262 |
if (!(oid instanceof Number)) { |
|
263 |
return false; |
|
264 |
} |
|
265 |
|
|
266 |
long num = ((Number) oid).longValue(); |
|
267 |
|
|
268 |
if (num > Integer.MAX_VALUE || num < Integer.MIN_VALUE) { |
|
269 |
return false; |
|
270 |
} |
|
271 |
|
|
272 |
return true; |
|
273 |
} |
|
274 |
|
|
275 |
protected Envelope getEnvelope(Object value) { |
|
276 |
Envelope env = null; |
|
277 |
|
|
278 |
if (value instanceof Envelope) { |
|
279 |
env = (Envelope) value; |
|
280 |
} else if (value instanceof Geometry) { |
|
281 |
env = ((Geometry) value).getEnvelope(); |
|
282 |
} |
|
283 |
return env; |
|
284 |
} |
|
285 |
|
|
286 |
} |
|
287 |
|
tags/v2_0_0_Build_2023/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); |
Also available in: Unified diff