Revision 24636

View differences:

branches/v2_0_0_prep/libraries/libFMap_dalindex/build.xml
19 19
	<property name="build" location="${proyectDir}/bin"/>
20 20
	<property name="build-test" location="${proyectDir}/bin-test"/>
21 21
	<property name="dist" location="${proyectDir}/dist"/>
22
	<property name="jarName" value="org.gvsig.fmap.data.index.spatial.jar"/>
22
	<property name="jarName" value="org.gvsig.fmap.dal.index.spatial.jar"/>
23 23

  
24 24

  
25 25
	<!-- =================================
......
32 32

  
33 33

  
34 34

  
35
	<!-- ================================= 
36
          target: compile              
35
	<!-- =================================
36
          target: compile
37 37
         ================================= -->
38 38
	<target name="compile" depends="" description="--> Compile sources">
39 39
		<mkdir dir="${build}"/>
......
49 49

  
50 50
	</target>
51 51

  
52
	<!-- ================================= 
53
          target: batch-build              
52
	<!-- =================================
53
          target: batch-build
54 54
         ================================= -->
55 55
	<target name="batch-build" depends="compile" description="--> Prepare library">
56 56
		<mkdir dir="${dist}"/>
57 57
		<jar destfile="${dist}/${jarName}" basedir="${build}"/>
58 58
	</target>
59 59

  
60
	<!-- ================================= 
61
          target: clean              
60
	<!-- =================================
61
          target: clean
62 62
         ================================= -->
63 63
	<target name="clean" depends="" description="--> Clean proyect">
64 64
		<delete>
branches/v2_0_0_prep/libraries/libFMap_dalindex/src-test/org/gvsig/fmap/dal/index/IndexTest.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;
29

  
30
import junit.framework.TestCase;
31

  
32
/**
33
 * TODO Update these tests according to new design
34
 */
35
public class IndexTest extends TestCase {
36
		
37
	protected void setUp() throws Exception {
38
		super.setUp();
39
	}
40
}
branches/v2_0_0_prep/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

  
29
package org.gvsig.fmap.dal.index.spatial.jsi;
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.locator.BaseLibrary;
36
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
37

  
38

  
39
public class JsiIndexLibrary extends BaseLibrary {
40

  
41
    public void initialize() throws ReferenceNotRegisteredException {
42
    	super.initialize();
43
    	
44
    	DALLibrary dal = new DALLibrary();
45
    	dal.initialize();    
46
    	DataManagerProviderServices man = (DataManagerProviderServices) DALLocator.getDataManager();
47
    	
48
    	if (!man.getFeatureIndexProviders().contains(PersistentRTreeJsi.NAME)) {
49
			man.registerFeatureIndexProvider(PersistentRTreeJsi.NAME, "Persistent RTree index based on JSI", 
50
					PersistentRTreeJsi.class, DataTypes.INT);
51
    	}
52
    	
53
    	if (!man.getFeatureIndexProviders().contains(RTreeJsi.NAME)) {
54
			man.registerFeatureIndexProvider(RTreeJsi.NAME, "RTree index based on JSI", 
55
					RTreeJsi.class, DataTypes.INT);
56
    	}    	
57
    }
58

  
59
    public void postInitialize() throws ReferenceNotRegisteredException {
60
        // TODO: log library postInitialization
61
        // Nothing to check
62
    }	
63
}
64

  
branches/v2_0_0_prep/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/jsi/RTreeJsi.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.primitive.Envelope;
78
import org.gvsig.fmap.geom.primitive.Point;
79
import org.gvsig.fmap.geom.primitive.Point2D;
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 RTreeJsi extends AbstractFeatureIndexProvider implements FeatureIndexProvider {
110

  
111
	public static final String NAME = "RTreeJsi";
112

  
113
	private RTree rtree;
114

  
115
	public RTreeJsi() {
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
	public List findNNearest(int numberOfNearest, Point2D 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
		double[] min = env.getLowerCorner();
156
		double[] max = env.getUpperCorner();
157

  
158
		Rectangle jsiRect = new Rectangle((float)min[0],
159
				(float)min[1],
160
				(float)max[0],
161
				(float)max[1]);
162
		return jsiRect;
163
	}
164

  
165
	public void insert(Object value, FeatureReferenceProviderServices fref) {
166
		if (value == null) {
167
			throw new IllegalArgumentException("value is null");
168
		}
169
		if (!(value instanceof Envelope)) {
170
			throw new IllegalArgumentException("Received " + value.getClass().getName() + " but expected org.gvsig.fmap.geom.primitive.Envelope.");
171
		}
172
		if (!(fref.getOID() instanceof Integer)) {
173
			throw new IllegalArgumentException("Reference Id is of type "
174
					+ fref.getOID().getClass().getName()
175
					+ " but expected an Integer.");
176
		}
177
		rtree.add(toJsiRect((Envelope) value), ((Integer) fref.getOID())
178
				.intValue());
179
	}
180

  
181
	public void delete(Object value, FeatureReferenceProviderServices fref) {
182
		if (value == null) {
183
			throw new IllegalArgumentException("value is null");
184
		}
185
		if (!(value instanceof Envelope)) {
186
			throw new IllegalArgumentException("Received " + value.getClass().getName() + " but expected org.gvsig.fmap.geom.primitive.Envelope.");
187
		}
188
		rtree.delete(toJsiRect((Envelope) value), ((Integer) fref.getOID())
189
				.intValue());
190
	}
191

  
192
	public List match(Object value) throws FeatureIndexException {
193
		if (value == null) {
194
			throw new IllegalArgumentException("value is null");
195
		}
196
		if (!(value instanceof Envelope)) {
197
			throw new IllegalArgumentException("Received " + value.getClass().getName() + " but expected org.gvsig.fmap.geom.primitive.Envelope.");
198
		}
199
		ListIntProcedure solution = new ListIntProcedure();
200
		rtree.intersects(toJsiRect((Envelope) value), solution);
201
		return solution.getSolution();
202
	}
203

  
204
	public List match(Object min, Object max) {
205
		throw new UnsupportedOperationException();
206
	}
207

  
208
	public List nearest(int count, Object value) {
209
		if (value == null) {
210
			throw new IllegalArgumentException("value is null");
211
		}
212
		if (value instanceof Envelope) {
213
			return (List) rtree.nearest(toJsiRect((Envelope) value), count);
214

  
215
		} else if (value instanceof Point) {
216
			Point p = (Point) value;
217
			com.infomatiq.jsi.Point jsiPoint =
218
				new com.infomatiq.jsi.Point((float) p.getDirectPosition().getOrdinate(0), (float) p.getDirectPosition().getOrdinate(1));
219
			return (List) rtree.nearest(jsiPoint, count);
220
		}
221
		throw new IllegalArgumentException("Received " + value.getClass().getName() + " but expected org.gvsig.fmap.geom.primitive.Envelope.");
222
	}
223

  
224

  
225
	public boolean isMatchSupported() {
226
		return true;
227
	}
228

  
229
	public boolean isNearestSupported() {
230
		return true;
231
	}
232

  
233
	public boolean isNearestToleranceSupported() {
234
		return false;
235
	}
236

  
237
	public boolean isRangeSupported() {
238
		return false;
239
	}
240

  
241
	public List nearest(int count, Object value, double tolerance)
242
			throws FeatureIndexException {
243
		throw new UnsupportedOperationException();
244
	}
245

  
246
	public List range(Object value1, Object value2) throws FeatureIndexException {
247
		throw new UnsupportedOperationException();
248
	}
249

  
250
}
251

  
branches/v2_0_0_prep/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/jsi/PersistentRTreeJsi.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.primitive.Envelope;
74

  
75
import com.infomatiq.jsi.Rectangle;
76
import com.infomatiq.jsi.rtree.RTree;
77

  
78
/**
79
 * Persistent spatial index which can resolve nearest neighbour queries.
80
 * <br>
81
 *
82
 * To use:
83
 *
84
 * PersistentRTreeJsi sptidx = new PersistentRtreeJsi("/home/kk");
85
 * if(sptidx.exists())
86
 *  sptidx.load();
87
 *
88
 *
89
 *  sptidx.add(rect, int);
90
 *  ...
91
 *  sptidx.add(rect2,int2);
92
 *  sptidx.flush();
93
 *
94
 * @author azabala
95
 *
96
 */
97
public class PersistentRTreeJsi extends RTreeJsi {
98

  
99
	public static final String NAME = "PersistentRTreeJsi";
100

  
101
	/**
102
	 * Spatial index in memory
103
	 */
104
	private RTree rtree;
105
	/**
106
	 * Spatial index file
107
	 */
108
	private File file;
109

  
110
	private boolean hasChanged = false;
111
	/**
112
	 * Spatial index file extension
113
	 */
114
	final String rExt = ".rix";
115

  
116
	private LinkedHashMap  rectangles;
117

  
118
	/**
119
	 * Constructor
120
	 * @param fileName path of the spatial index file
121
	 * @throws FeatureIndexException
122
	 */
123
	public PersistentRTreeJsi() {
124
		rtree = new RTree();
125
	}
126

  
127
	public void initialize() throws InitializeException {
128
		Properties props = new Properties();
129
		rtree.init(props);
130
		try {
131
			file = File.createTempFile("RTreeJsi" + getFeatureIndexProviderServices().getTemporaryFileName(), rExt);
132
			rectangles = new LinkedHashMap();
133
			load();
134
		} catch (IOException e) {
135
			throw new InitializeException(e);
136
		} catch (FeatureIndexException e) {
137
			throw new InitializeException(e);
138
		}
139
	}
140

  
141
	public void flush(File f) throws FeatureIndexException {
142
		try {
143
			if(! hasChanged) {
144
				return;
145
			}
146
			RandomAccessFile file = new RandomAccessFile(f,
147
															"rw");
148
			FileImageOutputStream output = new FileImageOutputStream(file);
149
			output.setByteOrder(ByteOrder.LITTLE_ENDIAN);
150
			int numShapes = rtree.size();
151
			output.writeInt(numShapes);
152

  
153
			Iterator iterator = rtree.iterator();
154
			int count = 0;
155
			while(iterator.hasNext()){
156
				Integer  idx = (Integer) iterator.next();
157
				Rectangle nr = (Rectangle) rectangles.get(idx);
158
				float xmin = nr.min[0];
159
				float ymin = nr.min[1];
160

  
161
				float xmax = nr.max[0];
162
				float ymax = nr.max[1];
163

  
164
				output.writeFloat(xmin);
165
				output.writeFloat(ymin);
166
				output.writeFloat(xmax);
167
				output.writeFloat(ymax);
168

  
169
				output.writeInt(idx.intValue());
170
				count++;
171
			}
172
			output.flush();
173
			output.close();
174
			file.close();
175
			hasChanged = false;
176
		} catch (FileNotFoundException e) {
177
			throw new FeatureIndexException(e);
178
		} catch (IOException e) {
179
			throw new FeatureIndexException(e);
180
		}
181

  
182
	}
183

  
184
	public void flush() throws FeatureIndexException {
185
		flush(file);
186
	}
187

  
188
	public boolean exists() {
189
		return file.exists();
190
	}
191

  
192
	public void load(File f) throws FeatureIndexException {
193
		if (f == null) {
194
			throw new IllegalArgumentException("File f cannot be null");
195
		}
196

  
197
		try {
198
			if(! f.exists()){
199
				return;
200
			}
201
			RandomAccessFile file = new RandomAccessFile(f, "r");
202
			FileChannel channel = file.getChannel();
203
			MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
204
			buf.order(ByteOrder.LITTLE_ENDIAN);
205
			int numShapes = buf.getInt();
206
			for(int i = 0; i < numShapes; i++){
207
				float xmin, ymin, xmax, ymax;
208
				int shapeIndex;
209
				xmin = buf.getFloat();
210
				ymin = buf.getFloat();
211
				xmax = buf.getFloat();
212
				ymax = buf.getFloat();
213
				shapeIndex = buf.getInt();
214

  
215
				Rectangle jsiRect = new Rectangle(xmin, ymin, xmax, ymax);
216
				rtree.add(jsiRect, shapeIndex);
217
			}
218
		}catch(Exception e){
219
			throw new FeatureIndexException(e);
220
		}
221
	}
222

  
223
	public void load() throws FeatureIndexException {
224
		load(file);
225
	}
226

  
227
	public void close() {
228
		rectangles.clear();
229
		rectangles = null;
230
	}
231

  
232
	public void insert(Object value, FeatureReferenceProviderServices fref) {
233
		super.insert(value, fref);
234
		rectangles.put(fref.getOID(), toJsiRect((Envelope) value));
235
		hasChanged = true;
236
	}
237

  
238

  
239
	public void delete(Object value, FeatureReferenceProviderServices fref) {
240
		super.delete(value, fref);
241
		rectangles.remove(fref.getOID());
242
		hasChanged = true;
243
	}
244

  
245
	public List findNNearest(int numberOfNearest, Point2D point){
246
		com.infomatiq.jsi.Point jsiPoint =
247
			new com.infomatiq.jsi.Point((float)point.getX(),(float)point.getY());
248
		return (List) rtree.nearest(jsiPoint, numberOfNearest);
249
	}
250

  
251
	public File getFile() {
252
		return this.file;
253
	}
254
}
255

  
branches/v2_0_0_prep/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/spatialindex/RTreeSptLib.java
1
package org.gvsig.fmap.dal.index.spatial.spatialindex;
2

  
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.IOException;
6
import java.util.ArrayList;
7
import java.util.List;
8

  
9
import org.gvsig.fmap.dal.exception.InitializeException;
10
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
11
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
12
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider;
13
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider;
14
import org.gvsig.fmap.geom.primitive.Envelope;
15
import org.gvsig.fmap.geom.primitive.Point2D;
16

  
17
import spatialindex.rtree.RTree;
18
import spatialindex.spatialindex.IData;
19
import spatialindex.spatialindex.INode;
20
import spatialindex.spatialindex.IVisitor;
21
import spatialindex.spatialindex.Region;
22
import spatialindex.storagemanager.DiskStorageManager;
23
import spatialindex.storagemanager.IBuffer;
24
import spatialindex.storagemanager.IStorageManager;
25
import spatialindex.storagemanager.PropertySet;
26
import spatialindex.storagemanager.RandomEvictionsBuffer;
27

  
28
/**
29
 * <p>
30
 * RTree spatial index based in spatial index library: <br>
31
 * http://u-foria.org/marioh/spatialindex/index.html <br>
32
 * marioh@cs.ucr.edu
33
 * </p>
34
 * It has the problem that spatial index file creation is a bit slowly (in
35
 * comparation with other indexes).
36
 */
37
public class RTreeSptLib extends AbstractFeatureIndexProvider implements
38
		FeatureIndexProvider {
39

  
40
	public static final String NAME = "RTreeSptLib";
41
	/**
42
	 * Page size of associated file
43
	 */
44
	private static final int defaultPageSize = 32 * 1024;
45
	private static final double defaultFillFactor = 0.85d;
46

  
47
	/**
48
	 * Size of memory buffer of the index
49
	 */
50
	private static final int BUFFER_SIZE = 25000;
51
	RTree rtree;
52
	String fileName;
53
	IStorageManager diskfile;
54

  
55
	public RTreeSptLib() {
56

  
57
	}
58

  
59
	public void initialize() throws InitializeException {
60
		try {
61
			PropertySet ps = new PropertySet();
62
			ps.setProperty("Overwrite", new Boolean(false));
63
			// .idx and .dat extensions will be added.
64
			fileName = getFeatureIndexProviderServices().getNewFileName(null, null);
65
			ps.setProperty("FileName", fileName);
66
			ps.setProperty("PageSize", new Integer(defaultPageSize));
67
			diskfile = new DiskStorageManager(ps);
68
			load();
69
		} catch (SecurityException e) {
70
			throw new InitializeException(e);
71
		} catch (FileNotFoundException e) {
72
			throw new InitializeException(e);
73
		} catch (IOException e) {
74
			throw new InitializeException(e);
75
		}
76
	}
77

  
78
	/**
79
	 * If the spatial index file exists and has content
80
	 */
81
	public boolean exists() {
82
		return (new File(fileName + ".dat").length() != 0);
83
	}
84

  
85
	class RTreeVisitor implements IVisitor {
86
		ArrayList solution = new ArrayList();
87

  
88
		public void visitNode(INode n) {
89
		}
90

  
91
		public void visitData(IData d) {
92
			solution.add(new Integer(d.getIdentifier()));
93
		}
94

  
95
		public List getSolution() {
96
			return solution;
97
		}
98
	}
99

  
100
	public List containtmentQuery(Envelope env) {
101
		List solution = null;
102
		Region region = createRegion(env);
103
		RTreeVisitor visitor = new RTreeVisitor();
104
		rtree.containmentQuery(region, visitor);
105
		solution = visitor.getSolution();
106
		return solution;
107
	}
108

  
109
	/**
110
	 * Warn! This RTree implemention doesnt care if 'index' entry has been
111
	 * indexed yet
112
	 */
113
	public void insert(Envelope env, int index) {
114
		rtree.insertData(null, createRegion(env), index);
115
	}
116

  
117
	private Region createRegion(Envelope env) {
118
		return new Region(env.getLowerCorner(), env.getUpperCorner());
119
	}
120

  
121
	/**
122
	 * Looks for N indexes nearest to the specified rect.
123
	 *
124
	 * @param numberOfNearest
125
	 * @param rect
126
	 * @return
127
	 */
128
	public List findNNearest(int numberOfNearest, Envelope env) {
129
		List solution = null;
130
		Region region = createRegion(env);
131
		RTreeVisitor visitor = new RTreeVisitor();
132
		rtree.nearestNeighborQuery(numberOfNearest, region, visitor);
133
		solution = visitor.getSolution();
134
		return solution;
135
	}
136

  
137
	/**
138
	 * Looks for the N indexes nearest to the specified point
139
	 *
140
	 * @param numberOfNearest
141
	 * @param point
142
	 * @return
143
	 */
144
	public List findNNearest(int numberOfNearest, Point2D point) {
145
		List solution = null;
146
		spatialindex.spatialindex.Point sptPoint = new spatialindex.spatialindex.Point(
147
				new double[] { point.getX(), point.getY() });
148
		RTreeVisitor visitor = new RTreeVisitor();
149
		rtree.nearestNeighborQuery(numberOfNearest, sptPoint, visitor);
150
		solution = visitor.getSolution();
151
		return solution;
152
	}
153

  
154
	public void flush() {
155
		rtree.flush();
156
	}
157

  
158
	public void load() {
159
		// applies a main memory random buffer on top of the persistent
160
		// storage manager
161
		IBuffer buffer = new RandomEvictionsBuffer(diskfile, BUFFER_SIZE, false);
162

  
163
		// Create a new, empty, RTree with dimensionality 2, minimum load
164
		// 70%, using "file" as
165
		// the StorageManager and the RSTAR splitting policy.
166
		PropertySet ps2 = new PropertySet();
167

  
168
		Double f = new Double(defaultFillFactor);
169
		ps2.setProperty("FillFactor", f);
170

  
171
		Integer i = new Integer(2);
172
		ps2.setProperty("Dimension", i);
173

  
174
		File file = new File(fileName + ".dat");
175
		if (file.length() != 0) {
176
			ps2.setProperty("IndexIdentifier", new Integer(1));
177
		}
178
		rtree = new RTree(ps2, buffer);
179
	}
180

  
181
	public void load(File f) throws FeatureIndexException {
182
		load();
183
	}
184

  
185
	public void flush(File f) throws FeatureIndexException {
186
		flush();
187
	}
188

  
189
	public void close() {
190
	}
191

  
192
	public File getFile() {
193
		return new File(fileName + ".dat");
194
	}
195

  
196
	public void delete(Object value, FeatureReferenceProviderServices fref) {
197
		rtree.deleteData(createRegion((Envelope) value), ((Integer) fref
198
				.getOID()).intValue());
199
	}
200

  
201
	public void insert(Object value, FeatureReferenceProviderServices fref) {
202
		rtree.insertData(null, createRegion((Envelope) value), ((Integer) fref
203
				.getOID()).intValue());
204
	}
205

  
206
	public List match(Object value) throws FeatureIndexException {
207
		List solution = null;
208
		Region region = createRegion((Envelope) value);
209
		RTreeVisitor visitor = new RTreeVisitor();
210
		rtree.intersectionQuery(region, visitor);
211
		solution = visitor.getSolution();
212
		return solution;
213
	}
214

  
215
	public List match(Object min, Object max) {
216
		throw new UnsupportedOperationException();
217
	}
218

  
219
	public List nearest(int count, Object value) throws FeatureIndexException {
220
		if (value instanceof Envelope) {
221
			return this.findNNearest(count, (Envelope) value);
222
		} else if (value instanceof Point2D) {
223
			return this.findNNearest(count, (Point2D) value);
224
		} else {
225
			throw new IllegalArgumentException ("value must be either an Envelope or either a Point2D");
226
		}
227
	}
228

  
229
	public boolean isMatchSupported() {
230
		return true;
231
	}
232

  
233
	public boolean isNearestSupported() {
234
		return true;
235
	}
236

  
237
	public boolean isNearestToleranceSupported() {
238
		return false;
239
	}
240

  
241
	public boolean isRangeSupported() {
242
		// TODO Auto-generated method stub
243
		return false;
244
	}
245

  
246
	public List nearest(int count, Object value, double tolerance)
247
			throws FeatureIndexException {
248
		throw new UnsupportedOperationException();
249
	}
250

  
251
	public List range(Object value1, Object value2)
252
			throws FeatureIndexException {
253
		throw new UnsupportedOperationException();
254
	}
255
}
branches/v2_0_0_prep/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/spatialindex/RTreeSptLibLibrary.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.spatialindex;
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.locator.BaseLibrary;
36
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
37

  
38

  
39
public class RTreeSptLibLibrary extends BaseLibrary {
40

  
41
    public void initialize() throws ReferenceNotRegisteredException {
42
    	super.initialize();
43
    	
44
    	DALLibrary dal = new DALLibrary();
45
    	dal.initialize();    
46
    	DataManagerProviderServices man = (DataManagerProviderServices) DALLocator.getDataManager();
47
    	
48
   	
49
    	if (!man.getFeatureIndexProviders().contains(RTreeSptLib.NAME)) {
50
			man.registerFeatureIndexProvider(RTreeSptLib.NAME, "RTree index based on spatialindex", 
51
					RTreeSptLib.class, DataTypes.INT);
52
    	}    	
53
    }
54

  
55
    public void postInitialize() throws ReferenceNotRegisteredException {
56
        // TODO: log library postInitialization
57
        // Nothing to check
58
    }	
59
}
60

  
branches/v2_0_0_prep/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/gt2/QuadtreeGt2.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.tools.exception.BaseException;
78

  
79
import com.vividsolutions.jts.geom.Envelope;
80

  
81
/**
82
 * This Quadtree spatial index implementation is based in a fork of
83
 * org.geotools.index.quadtree.Quadtree implementation. <br>
84
 * This implementation offers us:
85
 * <ol>
86
 * <li>Persistence of spatial index</li>
87
 * </ol>
88
 * We had to fork geotools quadtree for many reasons:
89
 * <ol>
90
 * <li>It was strongly dependent of SHP format, so it returned not only a num
91
 * of rectangle, it also returned byte offset of this rectangle in shp file</li>
92
 * <li> Query artifact wasnt run well at all </li>
93
 * </ol>
94
 *
95
 * @author azabala
96
 *
97
 */
98
public class QuadtreeGt2 extends AbstractFeatureIndexProvider implements FeatureIndexProvider {
99

  
100
	public static final String NAME = "QuadtreeGt2";
101
	/**
102
	 * Geotools quadtree implementation
103
	 */
104
	QuadTree quadtree;
105
	/**
106
	 * Persistent storage
107
	 */
108
	String fileName;
109
	/**
110
	 * Spatial index file extension
111
	 */
112
	final String qExt = ".qix";
113
	/**
114
	 * qix format has many versions, and allows different byte orders.
115
	 */
116
	String byteOrder;
117
	/**
118
	 * Bounds of the layer to index
119
	 */
120
	//Envelope bounds;
121
	/**
122
	 * Number of records of the layer to index
123
	 */
124
	//int numRecs = 0;
125

  
126
	boolean inMemory = false;
127

  
128
	public QuadtreeGt2() {
129

  
130
	}
131

  
132
	public void initialize() throws InitializeException {
133
		try {
134
			File file = File.createTempFile(getFeatureStore().getName(), ".qix");
135
			this.fileName = file.getAbsolutePath();
136
			org.gvsig.fmap.geom.primitive.Envelope env = getFeatureStore()
137
					.getEnvelope();
138
			int featureCount = (int) getFeatureStore().getFeatureSet().getSize();
139
			this.byteOrder = "NM";
140
			quadtree = new QuadTree(featureCount, toJtsEnvelope(env));
141
			if (exists()) {
142
				load();
143
			}
144
		} catch (IOException e) {
145
			throw new InitializeException(e);
146
		} catch (BaseException e) {
147
			throw new InitializeException(e);
148
		}
149
	}
150

  
151
	/**
152
	 * If the spatial index file exists and has content
153
	 */
154
	public boolean exists() {
155
		return (new File(fileName).length() != 0);
156
	}
157

  
158
	public void load() throws FeatureIndexException {
159
		if (quadtree == null) {
160
			load(new File(fileName));
161
		}
162
	}
163

  
164
	public void load(File f) throws FeatureIndexException {
165
		try {
166
			FileSystemIndexStore store = new FileSystemIndexStore(f);
167
			quadtree = store.load();
168
			this.fileName = f.getAbsolutePath();
169
		} catch (StoreException e) {
170
			throw new FeatureIndexException(e);
171
		}
172
	}
173

  
174
	/**
175
	 * Inserts an object in the index
176
	 */
177
	public void insert(org.gvsig.fmap.geom.primitive.Envelope env, int index) {
178
		if (env == null) {
179
			throw new IllegalArgumentException("Envelope cannot be null");
180
		}
181
		Envelope e = toJtsEnvelope(env);
182
		if (e == null) {
183
			throw new IllegalStateException(
184
					"JTS Envelope conversion returns null");
185
		}
186
		System.out.println("recno=" + index);
187
		if (quadtree == null) {
188
			throw new IllegalStateException("quadtree is null");
189
		}
190
		try {
191
			quadtree.insert(index, toJtsEnvelope(env));
192
		} catch (StoreException se) {
193
			// TODO Auto-generated catch block
194
			se.printStackTrace();
195
		}
196
	}
197

  
198
	public void delete(org.gvsig.fmap.geom.primitive.Envelope env, int index) {
199
		if (inMemory) {
200
			quadtree.delete(toJtsEnvelope(env), index);
201
		}
202
	}
203

  
204
	public Envelope toJtsEnvelope(org.gvsig.fmap.geom.primitive.Envelope env) {
205
		if (env == null) {
206
			return null;
207
		}
208
		double[] min = env.getLowerCorner();
209
		double[] max = env.getUpperCorner();
210
		return new Envelope(min[0], max[0], min[1], max[1]);
211
	}
212

  
213
	/**
214
	 *
215
	 * @throws StoreException
216
	 * @deprecated
217
	 */
218
	void openQuadTree() throws StoreException {
219
		if (quadtree == null) {
220
			File file = new File(this.fileName);
221
			// Intento de cargar todo el quadtree en memoria
222
			FileSystemIndexStore store = new FileSystemIndexStore(file);
223
			quadtree = store.load();
224
		}
225
	}
226

  
227
	void openQuadTreeInMemory() throws StoreException {
228
		if (quadtree == null) {
229
			File file = new File(fileName);
230
			// Intento de cargar todo el quadtree en memoria
231
			FileSystemIndexStore store = new FileSystemIndexStore(file);
232
			QuadTree filequadtree = store.load();
233
			quadtree = new QuadTree(filequadtree.getNumShapes(), filequadtree
234
					.getMaxDepth(), filequadtree.getRoot().getBounds());
235
			Stack nodes = new Stack();
236
			nodes.push(filequadtree.getRoot());
237
			while (nodes.size() != 0) {
238
				Node node = (Node) nodes.pop();
239
				Envelope nodeEnv = node.getBounds();
240
				int[] shapeIds = node.getShapesId();
241
				for (int i = 0; i < shapeIds.length; i++) {
242
					quadtree.insert(shapeIds[i], nodeEnv);
243
				}
244
				int numSubnodes = node.getNumSubNodes();
245
				for (int i = 0; i < numSubnodes; i++) {
246
					nodes.push(node.getSubNode(i));
247
				}
248
			}// while
249
			filequadtree.close();
250
		}
251
	}
252

  
253
	public void flush() throws FeatureIndexException {
254
		flush(new File(fileName));
255
	}
256

  
257
	public void flush(File f) throws FeatureIndexException {
258
		byte order = 0;
259
		if ((byteOrder == null) || byteOrder.equalsIgnoreCase("NM")) {
260
			order = IndexHeader.NEW_MSB_ORDER;
261
		} else if (byteOrder.equalsIgnoreCase("NL")) {
262
			order = IndexHeader.NEW_LSB_ORDER;
263
		}
264
		FileSystemIndexStore store = new FileSystemIndexStore(f, order);
265
		try {
266
			store.store(quadtree);
267
			this.fileName = f.getAbsolutePath();
268
		} catch (StoreException e) {
269
			throw new FeatureIndexException(e);
270
		}
271
	}
272

  
273
	private void close() throws FeatureIndexException {
274
		try {
275
			quadtree.close();
276
		} catch (StoreException e) {
277
			throw new FeatureIndexException(e);
278
		}
279
	}
280

  
281
	public File getFile() {
282
		return new File(this.fileName);
283
	}
284

  
285
	private FeatureStore getFeatureStore() {
286
		return getFeatureIndexProviderServices().getFeatureStore();
287
	}
288

  
289
	public void delete(Object value, FeatureReferenceProviderServices fref) {
290
		delete((org.gvsig.fmap.geom.primitive.Envelope) value, ((Integer) fref
291
				.getOID()).intValue());
292
	}
293

  
294
	public void insert(Object value, FeatureReferenceProviderServices fref) {
295
		insert((org.gvsig.fmap.geom.primitive.Envelope) value, ((Integer) fref
296
				.getOID()).intValue());
297
	}
298

  
299
	public List match(Object value) throws FeatureIndexException {
300
		if (quadtree == null) {
301
			throw new IllegalStateException("This quadtree is null.");
302
		}
303
		if (value == null) {
304
			throw new IllegalArgumentException("Envelope cannot be null.");
305
		}
306
		if (!(value instanceof org.gvsig.fmap.geom.primitive.Envelope)) {
307
			throw new IllegalArgumentException("Not an envelope.");
308
		}
309
		return quadtree.query(toJtsEnvelope((org.gvsig.fmap.geom.primitive.Envelope) value));
310
	}
311

  
312
	public List nearest(int count, Object value) throws FeatureIndexException {
313
		throw new UnsupportedOperationException();
314
	}
315

  
316
	public boolean isMatchSupported() {
317
		return true;
318
	}
319

  
320
	public boolean isNearestSupported() {
321
		return false;
322
	}
323

  
324
	public boolean isNearestToleranceSupported() {
325
		return false;
326
	}
327

  
328
	public boolean isRangeSupported() {
329
		return false;
330
	}
331

  
332
	public List nearest(int count, Object value, double tolerance)
333
			throws FeatureIndexException {
334
		throw new UnsupportedOperationException();
335
	}
336

  
337
	public List range(Object value1, Object value2) throws FeatureIndexException {
338
		throw new UnsupportedOperationException();
339
	}
340

  
341
}
branches/v2_0_0_prep/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.locator.BaseLibrary;
36
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
37

  
38

  
39
public class Gt2IndexLibrary extends BaseLibrary {
40

  
41
    public void initialize() throws ReferenceNotRegisteredException {
42
    	super.initialize();
43
    	
44
    	DALLibrary dal = new DALLibrary();
45
    	dal.initialize();    
46
    	DataManagerProviderServices man = (DataManagerProviderServices) DALLocator.getDataManager();
47
    	
48
    	if (!man.getFeatureIndexProviders().contains(QuadtreeGt2.NAME)) {
49
			man.registerFeatureIndexProvider(QuadtreeGt2.NAME, "Quadtree index based on Geotools 2", 
50
					QuadtreeGt2.class, DataTypes.INT);
51
    	}
52
    }
53

  
54
    public void postInitialize() throws ReferenceNotRegisteredException {
55
        // TODO: log library postInitialization
56
        // Nothing to check
57
    }	
58
}
59

  
branches/v2_0_0_prep/libraries/libFMap_dalindex/src/org/gvsig/fmap/dal/index/spatial/jts/QuadtreeJts.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

  
65
import com.vividsolutions.jts.geom.Envelope;
66
import com.vividsolutions.jts.index.quadtree.Quadtree;
67
/**
68
 * Adapter for ISPatialIndex gvSIG's interface to
69
 * JTS Quadtree.
70
 *
71
 *
72
 * @author azabala
73
 *
74
 */
75
public class QuadtreeJts extends AbstractFeatureIndexProvider implements FeatureIndexProvider {
76

  
77
	public static final String NAME = "QuadtreeJts";
78

  
79
	private Quadtree quadtree;
80

  
81
	public QuadtreeJts() {
82
	}
83

  
84
	public void initialize() {
85
		quadtree = new Quadtree();
86
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff