Revision 39312

View differences:

tags/v2_0_0_Build_2059/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
	<artifactId>org.gvsig.fmap.dal.index.spatial
8
	</artifactId>
9
	<packaging>jar</packaging>
10
	<version>2.0-SNAPSHOT</version>
11
	<name>libFMap_dalindex</name>
12
	<parent>
13
		<groupId>org.gvsig</groupId>
14
		<artifactId>gvsig-base-library-pom</artifactId>
15
		<version>2.0-SNAPSHOT</version>
16
	</parent>	
17
	<properties>
18
		<!-- gt2 -->
19
		<gt2-jarIncludes>org/gvsig/fmap/dal/index/spatial/gt2/**
20
		</gt2-jarIncludes>
21
		<gt2-jarExcludes>NONE</gt2-jarExcludes>
22

  
23
		<!-- jts -->
24
		<jts-jarIncludes>org/gvsig/fmap/dal/index/spatial/jts/**
25
		</jts-jarIncludes>
26
		<jts-jarExcludes>NONE</jts-jarExcludes>
27

  
28
		<!-- jsi -->
29
		<jsi-jarIncludes>org/gvsig/fmap/dal/index/spatial/jsi/**
30
		</jsi-jarIncludes>
31
		<jsi-jarExcludes>NONE</jsi-jarExcludes>
32

  
33
		<!-- spatialindex -->
34
		<sptidx-jarIncludes>org/gvsig/fmap/dal/index/spatial/spatialindex/**
35
		</sptidx-jarIncludes>
36
		<sptidx-jarExcludes>NONE</sptidx-jarExcludes>
37

  
38
		<build-dir>${basedir}/../build</build-dir>
39
        <eclipse.project.name>libFMap_dalindex</eclipse.project.name>
40
	</properties>
41

  
42
	<dependencies>
43
        <dependency>
44
            <groupId>org.gvsig</groupId>
45
            <artifactId>org.gvsig.tools.lib</artifactId>
46
            <scope>compile</scope>
47
        </dependency>
48
		<dependency>
49
			<groupId>org.gvsig</groupId>
50
			<artifactId>org.gvsig.fmap.dal</artifactId>
51
            <scope>compile</scope>
52
		</dependency>
53
		<dependency>
54
			<groupId>org.gvsig</groupId>
55
			<artifactId>org.gvsig.fmap.dal</artifactId>
56
			<classifier>spi</classifier>
57
            <scope>compile</scope>
58
		</dependency>
59
        <dependency>
60
            <groupId>org.gvsig</groupId>
61
            <artifactId>org.gvsig.fmap.geometry</artifactId>
62
            <scope>compile</scope>
63
        </dependency>
64
        <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
67
            <scope>compile</scope>
68
        </dependency>        
69
        <dependency>
70
            <groupId>org.gvsig</groupId>
71
            <artifactId>org.gvsig.projection</artifactId>
72
            <scope>compile</scope>
73
        </dependency>
74
		<dependency>
75
			<groupId>com.vividsolutions</groupId>
76
			<artifactId>jts</artifactId>
77
            <scope>compile</scope>
78
		</dependency>
79
		<dependency>
80
			<groupId>net.sf</groupId>
81
			<artifactId>jsi</artifactId>
82
            <scope>compile</scope>
83
		</dependency>
84
		<dependency>
85
			<groupId>sil</groupId>
86
			<artifactId>sil</artifactId>
87
            <scope>compile</scope>
88
		</dependency>
89
		<dependency>
90
			<groupId>gnu.trove</groupId>
91
			<artifactId>trove</artifactId>
92
            <scope>compile</scope>
93
		</dependency>
94
		<dependency>
95
			<groupId>org.geotools</groupId>
96
			<artifactId>gt2-main</artifactId>
97
            <scope>compile</scope>
98
		</dependency>		
99
 		<dependency>
100
		    <groupId>spatialindex</groupId>
101
   			<artifactId>spatialindex</artifactId>
102
            <scope>compile</scope>
103
   		</dependency>
104
   		<dependency>
105
            <groupId>org.gvsig</groupId>
106
            <artifactId>org.gvsig.timesupport.lib.api</artifactId>
107
            <scope>compile</scope>
108
        </dependency>
109
	</dependencies>
110
	<build>
111
		<sourceDirectory>src</sourceDirectory>
112
		<testSourceDirectory>src-test</testSourceDirectory>
113
		<testResources>
114
			<testResource>
115
				<directory>src-test</directory>
116
			</testResource>
117
		</testResources>
118
	</build>
119

  
120
	<profiles>
121
		<profile>
122
			<id>se</id>
123
			<activation>
124
				<activeByDefault>true</activeByDefault>
125
			</activation>
126
			<build>
127
				<plugins>
128
					<plugin>
129
						<groupId>org.apache.maven.plugins
130
						</groupId>
131
						<artifactId>maven-jar-plugin</artifactId>
132
						<configuration>
133
							<excludes>
134
								<exclude>${gt2-jarIncludes}</exclude>
135
								<exclude>${jts-jarIncludes}</exclude>
136
								<exclude>${jsi-jarIncludes}</exclude>
137
								<exclude>${sptidx-jarIncludes}</exclude>
138
							</excludes>
139
						</configuration>
140
						<executions>
141
							<!--
142
								Generates a jar file only with the GT2 based spatial index
143
								classes
144
							-->
145
							<execution>
146
								<id>gt2</id>
147
								<phase>package</phase>
148
								<goals>
149
									<goal>jar</goal>
150
								</goals>
151
								<configuration>
152
									<classifier>gt2</classifier>
153
									<includes>
154
										<include>${gt2-jarIncludes}</include>
155
									</includes>
156
									<excludes>
157
										<exclude>${gt2-jarExcludes}</exclude>
158
									</excludes>
159
								</configuration>
160
							</execution>
161
							<!--
162
								Generates a jar file only with the JTS based spatial index
163
								classes
164
							-->
165
							<execution>
166
								<id>jts</id>
167
								<phase>package</phase>
168
								<goals>
169
									<goal>jar</goal>
170
								</goals>
171
								<configuration>
172
									<classifier>jts</classifier>
173
									<includes>
174
										<include>${jts-jarIncludes}</include>
175
									</includes>
176
									<excludes>
177
										<exclude>${jts-jarExcludes}</exclude>
178
									</excludes>
179
								</configuration>
180
							</execution>
181
							<!--
182
								Generates a jar file only with the JSI based spatial index
183
								classes
184
							-->
185
							<execution>
186
								<id>jsi</id>
187
								<phase>package</phase>
188
								<goals>
189
									<goal>jar</goal>
190
								</goals>
191
								<configuration>
192
									<classifier>jsi</classifier>
193
									<includes>
194
										<include>${jsi-jarIncludes}</include>
195
									</includes>
196
									<excludes>
197
										<exclude>${jsi-jarExcludes}</exclude>
198
									</excludes>
199
								</configuration>
200
							</execution>
201
							<!--
202
								Generates a jar file only with the spatialindex based spatial
203
								index classes
204
							-->
205
							<execution>
206
								<id>spatialindex</id>
207
								<phase>package</phase>
208
								<goals>
209
									<goal>jar</goal>
210
								</goals>
211
								<configuration>
212
									<classifier>spatialindex</classifier>
213
									<includes>
214
										<include>${sptidx-jarIncludes}</include>
215
									</includes>
216
									<excludes>
217
										<exclude>${sptidx-jarExcludes}</exclude>
218
									</excludes>
219
								</configuration>
220
							</execution>
221
						</executions>
222
					</plugin>
223
					<plugin>
224
						<artifactId>maven-antrun-plugin</artifactId>
225
						<executions>
226
							<execution>
227
								<id>services</id>
228
								<phase>package</phase>
229
								<goals>
230
									<goal>run</goal>
231
								</goals>
232
								<configuration>
233
									<tasks>
234
										<jar
235
											destfile="${project.build.directory}/${project.build.finalName}-gt2.jar"
236
											update="true">
237
											<fileset dir="${basedir}/resources/gt2" />
238
										</jar>
239
										<jar
240
											destfile="${project.build.directory}/${project.build.finalName}-jsi.jar"
241
											update="true">
242
											<fileset dir="${basedir}/resources/jsi" />
243
										</jar>
244
										<jar
245
											destfile="${project.build.directory}/${project.build.finalName}-jts.jar"
246
											update="true">
247
											<fileset dir="${basedir}/resources/jts" />
248
										</jar>
249
										<jar
250
											destfile="${project.build.directory}/${project.build.finalName}-spatialindex.jar"
251
											update="true">
252
											<fileset dir="${basedir}/resources/spatialindex" />
253
										</jar>
254
									</tasks>
255
								</configuration>
256
							</execution>
257
						</executions>
258
					</plugin>
259
					<plugin>
260
						<groupId>org.apache.maven.plugins
261
						</groupId>
262
						<artifactId>maven-surefire-plugin
263
						</artifactId>
264
						<configuration>
265
							<additionalClasspathElements>
266
								<additionalClasspathElement>${basedir}/resources/gt2
267
								</additionalClasspathElement>
268
								<additionalClasspathElement>${basedir}/resources/jsi
269
								</additionalClasspathElement>
270
								<additionalClasspathElement>${basedir}/resources/jts
271
								</additionalClasspathElement>
272
								<additionalClasspathElement>${basedir}/resources/spatialindex
273
								</additionalClasspathElement>
274
							</additionalClasspathElements>
275
						</configuration>
276
					</plugin>
277

  
278
				</plugins>
279
			</build>
280
		</profile>
281
		<profile>
282
			<id>cdc</id>
283
			<activation>
284
				<activeByDefault>false</activeByDefault>
285
			</activation>
286
			<build>
287

  
288
				<plugins>
289
					<plugin>
290
						<groupId>org.apache.maven.plugins
291
						</groupId>
292
						<artifactId>maven-compiler-plugin
293
						</artifactId>
294
						<configuration>
295
							<source>1.4</source>
296
							<target>1.4</target>
297
							<!-- put your configurations here -->
298
							<encoding>ISO-8859-1</encoding>
299
							<excludes>
300
								<exclude>${jts-jarExcludes}</exclude>
301
								<exclude>**/gt2/**</exclude>
302
								<exclude>**/jsi/**</exclude>
303
								<exclude>**/spatialindex/**</exclude>
304
							</excludes>
305
						</configuration>
306
					</plugin>
307
					<plugin>
308
						<groupId>org.apache.maven.plugins
309
						</groupId>
310
						<artifactId>maven-jar-plugin</artifactId>
311
						<configuration>
312
							<excludes>
313
								<exclude>${jts-jarIncludes}</exclude>
314
							</excludes>
315
						</configuration>
316
						<executions>
317

  
318
							<!--
319
								Generates a jar file only with the JTS based spatial index
320
								classes
321
							-->
322
							<execution>
323
								<id>jts</id>
324
								<phase>package</phase>
325
								<goals>
326
									<goal>jar</goal>
327
								</goals>
328
								<configuration>
329
									<classifier>jts</classifier>
330
									<includes>
331
										<include>${jts-jarIncludes}</include>
332
									</includes>
333
									<excludes>
334
										<exclude>${jts-jarExcludes}</exclude>
335
										<exclude>**/gt2/**</exclude>
336
										<exclude>**/jsi/**</exclude>
337
										<exclude>**/spatialindex/**</exclude>
338
									</excludes>
339
								</configuration>
340
							</execution>
341
						</executions>
342
					</plugin>
343
				</plugins>
344
			</build>
345
		</profile>
346
		<profile>
347
			<id>eclipse-project</id>
348
			<build>
349
				<defaultGoal>antrun:run</defaultGoal>
350
				<plugins>
351
					<plugin>
352
						<artifactId>maven-antrun-plugin</artifactId>
353
						<configuration>
354
							<tasks>
355
								<ant antfile="${build-dir}/ant-tasks/eclipse-tasks.xml"
356
									target="eclipse.all"/>
357
							</tasks>
358
						</configuration>
359
					</plugin>
360
				</plugins>
361
			</build>				
362
		</profile>		
363
	</profiles>
364

  
365

  
366
</project>
tags/v2_0_0_Build_2059/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_2059/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_2059/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_2059/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_2059/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
    /**
123
     * Bounds of the layer to index
124
     */
125
    // Envelope bounds;
126
    /**
127
     * Number of records of the layer to index
128
     */
129
    // int numRecs = 0;
130

  
131
    boolean inMemory = false;
132

  
133
    public GT2Quadtree() {
134

  
135
    }
136

  
137
    @Override
138
    public void initialize() throws InitializeException {
139
        try {
140
            File file =
141
                File.createTempFile(getFeatureStore().getName(), ".qix");
142
            this.fileName = file.getAbsolutePath();
143
            this.byteOrder = "NM";
144
            this.quadtree = createQuadTree();
145
            if (exists()) {
146
                load();
147
            }
148
        } catch (IOException e) {
149
            throw new InitializeException(e);
150
        } catch (BaseException e) {
151
            throw new InitializeException(e);
152
        }
153
    }
154

  
155
    /**
156
     * @return
157
     * @throws DataException
158
     */
159
    private QuadTree createQuadTree() throws DataException {
160
        org.gvsig.fmap.geom.primitive.Envelope env =
161
            getFeatureStore().getEnvelope();
162
        int featureCount = (int) getFeatureStore().getFeatureCount();
163
        return new QuadTree(featureCount, toJtsEnvelope(env));
164
    }
165

  
166
    /**
167
     * If the spatial index file exists and has content
168
     */
169
    public boolean exists() {
170
        return (new File(fileName).length() != 0);
171
    }
172

  
173
    public void load() throws FeatureIndexException {
174
        if (quadtree == null) {
175
            load(new File(fileName));
176
        }
177
    }
178

  
179
    public void load(File f) throws FeatureIndexException {
180
        try {
181
            FileSystemIndexStore store = new FileSystemIndexStore(f);
182
            quadtree = store.load();
183
            this.fileName = f.getAbsolutePath();
184
        } catch (StoreException e) {
185
            throw new FeatureIndexException(e);
186
        }
187
    }
188

  
189
    /**
190
     * Inserts an object in the index
191
     */
192
    public void insert(org.gvsig.fmap.geom.primitive.Envelope env, int index) {
193
        if (env == null) {
194
            throw new IllegalArgumentException("Envelope cannot be null");
195
        }
196
        Envelope e = toJtsEnvelope(env);
197
        if (e == null) {
198
            throw new IllegalStateException(
199
                "JTS Envelope conversion returns null");
200
        }
201
        System.out.println("recno=" + index);
202
        if (quadtree == null) {
203
            throw new IllegalStateException("quadtree is null");
204
        }
205
        try {
206
            quadtree.insert(index, toJtsEnvelope(env));
207
        } catch (StoreException se) {
208
            // TODO Auto-generated catch block
209
            se.printStackTrace();
210
        }
211
    }
212

  
213
    public void delete(org.gvsig.fmap.geom.primitive.Envelope env, int index) {
214
        if (inMemory) {
215
            quadtree.delete(toJtsEnvelope(env), index);
216
        }
217
    }
218

  
219
    public Envelope toJtsEnvelope(org.gvsig.fmap.geom.primitive.Envelope env) {
220
        if (env == null) {
221
            return null;
222
        }
223
        Point min = env.getLowerCorner();
224
        Point max = env.getUpperCorner();
225

  
226
        return new Envelope(min.getX(), max.getX(), min.getY(), max.getY());
227
    }
228

  
229
    /**
230
     * 
231
     * @throws StoreException
232
     * @deprecated
233
     */
234
    @Deprecated
235
    void openQuadTree() throws StoreException {
236
        if (quadtree == null) {
237
            File file = new File(this.fileName);
238
            // Intento de cargar todo el quadtree en memoria
239
            FileSystemIndexStore store = new FileSystemIndexStore(file);
240
            quadtree = store.load();
241
        }
242
    }
243

  
244
    void openQuadTreeInMemory() throws StoreException {
245
        if (quadtree == null) {
246
            File file = new File(fileName);
247
            // Intento de cargar todo el quadtree en memoria
248
            FileSystemIndexStore store = new FileSystemIndexStore(file);
249
            QuadTree filequadtree = store.load();
250
            quadtree =
251
                new QuadTree(filequadtree.getNumShapes(),
252
                    filequadtree.getMaxDepth(), filequadtree.getRoot()
253
                        .getBounds());
254
            Stack nodes = new Stack();
255
            nodes.push(filequadtree.getRoot());
256
            while (nodes.size() != 0) {
257
                Node node = (Node) nodes.pop();
258
                Envelope nodeEnv = node.getBounds();
259
                int[] shapeIds = node.getShapesId();
260
                for (int i = 0; i < shapeIds.length; i++) {
261
                    quadtree.insert(shapeIds[i], nodeEnv);
262
                }
263
                int numSubnodes = node.getNumSubNodes();
264
                for (int i = 0; i < numSubnodes; i++) {
265
                    nodes.push(node.getSubNode(i));
266
                }
267
            }// while
268
            filequadtree.close();
269
        }
270
    }
271

  
272
    public void flush() throws FeatureIndexException {
273
        flush(new File(fileName));
274
    }
275

  
276
    public void flush(File f) throws FeatureIndexException {
277
        byte order = 0;
278
        if ((byteOrder == null) || byteOrder.equalsIgnoreCase("NM")) {
279
            order = IndexHeader.NEW_MSB_ORDER;
280
        } else
281
            if (byteOrder.equalsIgnoreCase("NL")) {
282
                order = IndexHeader.NEW_LSB_ORDER;
283
            }
284
        FileSystemIndexStore store = new FileSystemIndexStore(f, order);
285
        try {
286
            store.store(quadtree);
287
            this.fileName = f.getAbsolutePath();
288
        } catch (StoreException e) {
289
            throw new FeatureIndexException(e);
290
        }
291
    }
292

  
293
    public File getFile() {
294
        return new File(this.fileName);
295
    }
296

  
297
    private FeatureStore getFeatureStore() {
298
        return getFeatureIndexProviderServices()
299
            .getFeatureStoreProviderServices().getFeatureStore();
300
    }
301

  
302
    public void delete(Object value, FeatureReferenceProviderServices fref) {
303

  
304
        if (!isCompatibleOID(fref.getOID())) {
305
            throw new IllegalArgumentException(
306
                "OID not compatible. Must be an instance of Number within the Integer range.");
307
        }
308

  
309
        delete(((org.gvsig.fmap.geom.Geometry) value).getEnvelope(),
310
            ((Number) fref.getOID()).intValue());
311
    }
312

  
313
    public void insert(Object value, FeatureReferenceProviderServices fref) {
314

  
315
        if (!isCompatibleOID(fref.getOID())) {
316
            throw new IllegalArgumentException(
317
                "OID not compatible. Must be an instance of Number within the Integer range.");
318
        }
319

  
320
        insert(((org.gvsig.fmap.geom.Geometry) value).getEnvelope(),
321
            ((Number) fref.getOID()).intValue());
322
    }
323

  
324
    public List match(Object value) throws FeatureIndexException {
325
        if (quadtree == null) {
326
            throw new IllegalStateException("This quadtree is null.");
327
        }
328
        if (value == null) {
329
            throw new IllegalArgumentException("Envelope cannot be null.");
330
        }
331
        if (!(value instanceof org.gvsig.fmap.geom.primitive.Envelope)) {
332
            throw new IllegalArgumentException("Not an envelope.");
333
        }
334
        org.gvsig.fmap.geom.primitive.Envelope env = null;
335
        if (value instanceof org.gvsig.fmap.geom.primitive.Envelope) {
336
            env = (org.gvsig.fmap.geom.primitive.Envelope) value;
337
        } else
338
            if (value instanceof Geometry) {
339
                env = ((Geometry) value).getEnvelope();
340
            }
341
        return new LongList(quadtree.query(toJtsEnvelope(env)));
342
    }
343

  
344
    public List nearest(int count, Object value) throws FeatureIndexException {
345
        throw new UnsupportedOperationException();
346
    }
347

  
348
    public boolean isMatchSupported() {
349
        return true;
350
    }
351

  
352
    public boolean isNearestSupported() {
353
        return false;
354
    }
355

  
356
    public boolean isNearestToleranceSupported() {
357
        return false;
358
    }
359

  
360
    public boolean isRangeSupported() {
361
        return false;
362
    }
363

  
364
    public List nearest(int count, Object value, Object tolerance)
365
        throws FeatureIndexException {
366
        throw new UnsupportedOperationException();
367
    }
368

  
369
    public List range(Object value1, Object value2)
370
        throws FeatureIndexException {
371
        throw new UnsupportedOperationException();
372
    }
373

  
374
    /**
375
     * Indicates whether the given OID's type is compatible
376
     * with this provider
377
     * 
378
     * @param oid
379
     * 
380
     * @return
381
     *         true if this index provider supports the given oid type
382
     */
383
    private boolean isCompatibleOID(Object oid) {
384
        if (!(oid instanceof Number)) {
385
            return false;
386
        }
387

  
388
        long num = ((Number) oid).longValue();
389

  
390
        if ((num > Integer.MAX_VALUE) || (num < Integer.MIN_VALUE)) {
391
            return false;
392
        }
393

  
394
        return true;
395
    }
396

  
397
    public void clear() throws DataException {
398
        this.quadtree = createQuadTree();
399
    }
400

  
401
}
tags/v2_0_0_Build_2059/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
    @Override
41
    public void doRegistration() {
42
        registerAsServiceOf(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_2059/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 com.vividsolutions.jts.geom.Envelope;
61
import com.vividsolutions.jts.index.quadtree.Quadtree;
62

  
63
import org.gvsig.fmap.dal.exception.DataException;
64
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
65
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
66
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider;
67
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider;
68
import org.gvsig.fmap.geom.Geometry;
69
import org.gvsig.fmap.geom.primitive.NullGeometry;
70
import org.gvsig.fmap.geom.primitive.Point;
71

  
72
/**
73
 * Adapter for ISPatialIndex gvSIG's interface to
74
 * JTS Quadtree.
75
 * 
76
 * 
77
 * @author azabala
78
 * 
79
 */
80
public class JTSQuadtree extends AbstractFeatureIndexProvider implements
81
    FeatureIndexProvider {
82

  
83
    public static final String NAME = JTSQuadtree.class.getName();
84

  
85
    private Quadtree quadtree;
86

  
87
    public JTSQuadtree() {
88
    }
89

  
90
    public void initialize() {
91
        quadtree = createQuadtree();
92
    }
93

  
94
    private Quadtree createQuadtree() {
95
        return new Quadtree();
96
    }
97

  
98
    private Envelope fromEnvelope(org.gvsig.fmap.geom.primitive.Envelope env) {
99
        Point min = env.getLowerCorner();
100
        Point max = env.getUpperCorner();
101
        Envelope env2 =
102
            new Envelope(min.getX(), max.getX(), min.getY(), max.getY());
103
        return env2;
104
    }
105

  
106
    public void delete(Object o, FeatureReferenceProviderServices fref) {
107
        Integer integer = new Integer(((Long) (fref).getOID()).intValue());
108
        quadtree.remove(fromEnvelope(((Geometry) o).getEnvelope()), integer);
109
    }
110

  
111
    public void insert(Object o, FeatureReferenceProviderServices fref) {
112
        if (o == null || o instanceof NullGeometry) {
113
            return;
114
        }
115
        Integer integer = new Integer(((Long) (fref).getOID()).intValue());
116
        quadtree.insert(fromEnvelope(((Geometry) o).getEnvelope()), integer);
117

  
118
    }
119

  
120
    public List match(Object value) throws FeatureIndexException {
121
        org.gvsig.fmap.geom.primitive.Envelope env = null;
122
        if (value instanceof org.gvsig.fmap.geom.primitive.Envelope) {
123
            env = (org.gvsig.fmap.geom.primitive.Envelope) value;
124
        } else
125
            if (value instanceof Geometry) {
126
                env = ((Geometry) value).getEnvelope();
127
            }
128
        return new LongList(quadtree.query(fromEnvelope(env)));
129
    }
130

  
131
    public List match(Object min, Object max) {
132
        throw new UnsupportedOperationException(
133
            "Can't perform this kind of search.");
134
    }
135

  
136
    public List nearest(int count, Object value) throws FeatureIndexException {
137
        throw new UnsupportedOperationException(
138
            "Can't perform this kind of search.");
139
    }
140

  
141
    public boolean isMatchSupported() {
142
        return true;
143
    }
144

  
145
    public boolean isNearestSupported() {
146
        return false;
147
    }
148

  
149
    public boolean isNearestToleranceSupported() {
150
        return false;
151
    }
152

  
153
    public boolean isRangeSupported() {
154
        return false;
155
    }
156

  
157
    public List nearest(int count, Object value, Object tolerance)
158
        throws FeatureIndexException {
159
        throw new UnsupportedOperationException();
160
    }
161

  
162
    public List range(Object value1, Object value2)
163
        throws FeatureIndexException {
164
        throw new UnsupportedOperationException();
165
    }
166

  
167
    public void clear() throws DataException {
168
        quadtree = createQuadtree();
169
    }
170
}
tags/v2_0_0_Build_2059/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
    @Override
40
    public void doRegistration() {
41
        registerAsServiceOf(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_2059/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_2059/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_2059/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.
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff