Revision 59

View differences:

org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/core/GeometryOperation.java
67 67
	 * @param out
68 68
	 * @throws DataException 
69 69
	 */
70
	public abstract void setFeatureStore(FeatureStore out, String[] attrNames) throws DataException;
70
	public void setFeatureStore(FeatureStore out, String[] attrNames) throws DataException {
71
		persister = new DALFeaturePersister(out, attrNames);
72
	}
71 73
	
72 74
	/**
73 75
	 * Gets the last result of this operation
org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/visitor/exception/StartVisitorException.java
47 47
 * @author Vicente Caballero Navarro
48 48
 */
49 49
public class StartVisitorException extends VisitorException {
50
	private static final long serialVersionUID = 1L;
51

  
50 52
	public StartVisitorException(String layer,Throwable exception) {
51 53
		super(layer,exception);
52 54
		init();
org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/visitor/exception/ProcessVisitorException.java
25 25
 * @author Vicente Caballero Navarro
26 26
 */
27 27
public class ProcessVisitorException extends VisitorException {
28
	private static final long serialVersionUID = 1L;
28 29
	private String description="";
29 30
	public ProcessVisitorException(String layer,Throwable exception,String description) {
30 31
		super(layer,exception);
org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/visitor/exception/VisitorException.java
52 52
 * @author Vicente Caballero Navarro
53 53
 */
54 54
public class VisitorException extends BaseException {
55
	private static final long serialVersionUID = 1L;
55 56
	private String layer = null;
56 57
	/**
57 58
 	 * <p>Constructs an visitor exception with the specified cause, and the layer where this exception was produced.</p>
......
59 60
 	 * @param layer the layer affected
60 61
	 * @param exception an exception with the cause
61 62
	 */
63
	@SuppressWarnings("deprecation")
62 64
	public VisitorException(String layer,Throwable exception) {
63 65
		this.layer = layer;
64 66
		init();
......
77 79
	 * (non-Javadoc)
78 80
	 * @see org.gvsig.exceptions.BaseException#values()
79 81
	 */
82
	@SuppressWarnings("unchecked")
80 83
	protected Map values() {
81 84
		Hashtable params = new Hashtable();
82 85
		params.put("layer",layer);
org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/visitor/exception/StopWriterVisitorException.java
5 5
 * @author Vicente Caballero Navarro
6 6
 */
7 7
public class StopWriterVisitorException extends StopVisitorException {
8
	private static final long serialVersionUID = 1L;
9

  
8 10
	public StopWriterVisitorException(String layer,Throwable exception) {
9 11
		super(layer,exception);
10 12
		init();
org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/visitor/exception/StopVisitorException.java
47 47
 * @author Vicente Caballero Navarro
48 48
 */
49 49
public class StopVisitorException extends VisitorException {
50
	private static final long serialVersionUID = 1L;
51

  
50 52
	public StopVisitorException(String layer,Throwable exception) {
51 53
		super(layer,exception);
52 54
		init();
org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/visitor/exception/StartWriterVisitorException.java
5 5
 * @author Vicente Caballero Navarro
6 6
 */
7 7
public class StartWriterVisitorException extends StartVisitorException {
8
	private static final long serialVersionUID = 1L;
9

  
8 10
	public StartWriterVisitorException(String layer,Throwable exception) {
9 11
		super(layer,exception);
10 12
		init();
org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/spatialindex/INearestNeighbourFinder.java
1
/*
2
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 */
20
package org.gvsig.sextante.app.algorithm.base.spatialindex;
21

  
22
import java.awt.geom.Point2D;
23
import java.awt.geom.Rectangle2D;
24
import java.util.List;
25
/**
26
 * Find an specified number of items nearest to a given
27
 * geometry (Point or Rectangle2D as usual)
28
 * @author azabala
29
 *
30
 */
31
public interface INearestNeighbourFinder {
32
	@SuppressWarnings("unchecked")
33
	public List findNNearest(int numberOfNearest, Point2D point);
34
	@SuppressWarnings("unchecked")
35
	public List findNNearest(int numberOfNearest, Rectangle2D rect);
36
}
37

  
0 38

  
org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/spatialindex/RTreeJsi.java
1
/*
2
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 */
20

  
21
package org.gvsig.sextante.app.algorithm.base.spatialindex;
22

  
23
import java.awt.geom.Point2D;
24
import java.awt.geom.Rectangle2D;
25
import java.util.ArrayList;
26
import java.util.Iterator;
27
import java.util.List;
28
import java.util.Properties;
29

  
30
import com.infomatiq.jsi.IntProcedure;
31
import com.infomatiq.jsi.Rectangle;
32
import com.infomatiq.jsi.rtree.RTree;
33

  
34
/**
35
 * RTree spatial index implementation based in library
36
 * JSI (java spatial index).
37
 *
38
 * http://jsi.sourceforge.net/
39
 *
40
 * This RTree has better performance that Spatial Index Library
41
 * RTree, and that JTS'RTree, because
42
 * it uses the GNU's Trove Collections API.
43
 *
44
 * We are doing some probes with it, because it offers
45
 * a Nearest Neighbour algorithm implementation
46
 * (useful for Spatial Join geoprocess, for example).
47
 *
48
 * It isnt persistent, and We've found some problems
49
 * with delete operations.
50
 *
51
 * @author azabala
52
 *
53
 */
54
public class RTreeJsi implements ISpatialIndex, INearestNeighbourFinder {
55
	private RTree rtree;
56

  
57
	public RTreeJsi(){
58
		rtree = new RTree();
59
	}
60

  
61
	public void create(){
62
		Properties props = new Properties();
63
		rtree.init(props);
64
	}
65

  
66
	class ListIntProcedure implements IntProcedure {
67
		ArrayList<Integer> solution = new ArrayList<Integer>();
68

  
69
		public boolean execute(int arg0) {
70
			solution.add(new Integer(arg0));
71
			return true;
72
		}
73

  
74
		@SuppressWarnings("unchecked")
75
		public List getSolution(){
76
			return solution;
77
		}
78
	}
79

  
80

  
81
	@SuppressWarnings("unchecked")
82
	public List query(Rectangle2D rect) {
83
		ListIntProcedure solution = new ListIntProcedure();
84
		rtree.intersects(toJsiRect(rect), solution);
85
		return solution.getSolution();
86
	}
87

  
88
	private Rectangle toJsiRect(Rectangle2D rect){
89
		Rectangle jsiRect = new Rectangle((float)rect.getMinX(),
90
				(float)rect.getMinY(),
91
				(float)rect.getMaxX(),
92
				(float)rect.getMaxY());
93
		return jsiRect;
94
	}
95

  
96
	public void insert(Rectangle2D rect, int index) {
97
		rtree.add(toJsiRect(rect), index);
98
	}
99

  
100
	public void delete(Rectangle2D rect, int index) {
101
		rtree.delete(toJsiRect(rect), index);
102
	}
103

  
104
	@SuppressWarnings("unchecked")
105
	public List findNNearest(int numberOfNearest, Point2D point) {
106
		ListIntProcedure solution = new ListIntProcedure();
107
		com.infomatiq.jsi.Point jsiPoint =
108
			new com.infomatiq.jsi.Point((float)point.getX(), (float)point.getY());
109
		rtree.nearest(jsiPoint, solution, Float.POSITIVE_INFINITY);
110
		return solution.getSolution();
111
	}
112

  
113
	@SuppressWarnings("unchecked")
114
	public List findNNearest(int numberOfNearest, Rectangle2D rect) {
115
		ListIntProcedure solution = new ListIntProcedure();
116
		com.infomatiq.jsi.Rectangle jsiRect = toJsiRect(rect);
117
		rtree.nearest(jsiRect, solution, Float.POSITIVE_INFINITY);
118
		return solution.getSolution();
119
	}
120

  
121
	@SuppressWarnings("unchecked")
122
	public Iterator iterator(){
123
		return rtree.iterator();
124
	}
125

  
126
	public static void main(String[] args){
127
		RTreeJsi q = new RTreeJsi();
128
		q.create();
129

  
130
			for(int i = 1; i <= 99; i++){
131
				q.insert(new Rectangle2D.Double(100+i, 200+i, 200+i, 500+i),i);
132
			}
133

  
134
			for(int i = 1; i <= 99; i++){
135
				q.delete(new Rectangle2D.Double(100+i, 200+i, 200+i, 500+i),i);
136
				System.out.println("Rect="+i);
137
			}
138
	}
139

  
140
}
141

  
0 142

  
org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.base/src/main/java/org/gvsig/sextante/app/algorithm/base/spatialindex/ISpatialIndex.java
1
/*
2
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2010 Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 */
20
package org.gvsig.sextante.app.algorithm.base.spatialindex;
21

  
22
import java.awt.geom.Rectangle2D;
23
import java.util.List;
24

  
25
/**
26
 * gvSIG spatial index
27
 * @author azabala
28
 *
29
 */
30
public interface ISpatialIndex {
31
	/**
32
	 * Returns a list of objects spatially indexed
33
	 * covered by specified rect.
34
	 * Usually this list will have Integer objects
35
	 * (pointers to a place where the object information
36
	 * 	is saved)
37
	 * @param rect
38
	 * @return
39
	 */
40
	@SuppressWarnings("unchecked")
41
	public List query(Rectangle2D rect);
42
	
43
	/**
44
	 * @param rect
45
	 * @param index
46
	 */
47
	public void insert(Rectangle2D rect, int index);
48
	/**
49
	 * 
50
	 * @param rect
51
	 * @param index
52
	 */
53
	public void delete(Rectangle2D rect, int index);
54
	
55
	//TODO Hacer un overwrite and update
56
}
57

  
58

  
59

  
0 60

  

Also available in: Unified diff