Revision 23288

View differences:

branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/AbstractIntBasedSpatialIndex.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.data.index;
30

  
31
import java.util.ArrayList;
32
import java.util.List;
33

  
34
import org.gvsig.fmap.data.feature.FeatureID;
35
import org.gvsig.fmap.geom.primitive.Envelope;
36

  
37
/**
38
 * This class is a wrapper that can be extended by index implementations
39
 * that use integer as index data, so that they can use FeatureID instead.
40
 *
41
 * @author jyarza
42
 *
43
 */
44
public abstract class AbstractIntBasedSpatialIndex implements SpatialIndex {
45

  
46
	/** Keeps the correspondence between the int index used internally and FeatureID*/
47
	private ArrayList ids = new ArrayList();
48
	
49
	public void delete(org.gvsig.fmap.geom.primitive.Envelope env, FeatureID fid) {		
50
		int idx = ids.indexOf(fid);
51
		if (idx >= 0) {
52
			this.delete(env, idx);
53
		}
54
	}
55

  
56
	public void insert(Envelope env, FeatureID fid) {
57
		ids.add(fid);
58
		this.insert(env, ids.size()-1);
59
	}
60

  
61
	public List query(QueryParameters params) throws IndexException {
62
		try {
63
			SpatialQueryParameters sqp = (SpatialQueryParameters) params;
64
			return query(sqp.getEnvelope());
65
		} catch (ClassCastException e) {
66
			throw new IndexException(e);
67
		}
68
	}
69
	
70
	public abstract void insert(Envelope env, int index);
71
	public abstract void delete(Envelope env, int index);
72
	public abstract List query(Envelope env) throws IndexException;
73
}
74

  
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/SpatialIndex.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: ISpatialIndex.java 5098 2006-05-08 15:44:03Z azabala $
47
* $Log$
48
* Revision 1.2  2006-05-08 15:44:03  azabala
49
* *** empty log message ***
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.data.index;
57

  
58
import java.util.List;
59

  
60
import org.gvsig.fmap.data.feature.FeatureID;
61
import org.gvsig.fmap.geom.primitive.Envelope;
62

  
63
/**
64
 * gvSIG spatial index
65
 * 
66
 * 
67
 * 
68
 * @author azabala
69
 * @author jyarza
70
 */
71
public interface SpatialIndex extends Index {
72
	/**
73
	 * @param rect
74
	 * @param fid
75
	 */
76
	public void insert(Envelope env, FeatureID fid);
77
	/**
78
	 * 
79
	 * @param rect
80
	 * @param fid
81
	 */
82
	public void delete(Envelope env, FeatureID fid);
83
	
84
}
85

  
86

  
87

  
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/PersistentSpatialIndex.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: IPersistentSpatialIndex.java 5416 2006-05-24 21:57:42Z azabala $
47
* $Log$
48
* Revision 1.2  2006-05-24 21:57:42  azabala
49
* a?adidos comentarios
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.data.index;
57

  
58

  
59
/**
60
 * An spatial index based in persistent data stores.
61
 * 
62
 * @author azabala
63
 * @author jyarza
64
 *
65
 */
66
public interface PersistentSpatialIndex extends PersistentIndex, SpatialIndex {
67

  
68

  
69
}
70

  
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/SpatialQueryParameters.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.data.index;
30

  
31
import org.gvsig.fmap.geom.primitive.Envelope;
32

  
33

  
34
public class SpatialQueryParameters implements QueryParameters {
35
	
36
	private Envelope envelope = null;
37
		
38
	public Envelope getEnvelope() {
39
		return envelope;
40
	}
41
	
42
	public void setEnvelope(Envelope envelope) {
43
		this.envelope = envelope;
44
	}
45

  
46
}
47

  
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/SpatialIndexParameters.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.data.index;
29

  
30
import java.util.HashMap;
31
import java.util.Map;
32

  
33
import org.gvsig.fmap.geom.primitive.Envelope;
34

  
35

  
36
/**
37
 * 
38
 * @author jyarza
39
 *
40
 */
41
public class SpatialIndexParameters {
42
	
43
	private boolean overwrite = true;
44
	private String filename = null;
45
	private Envelope envelope = null;
46
	private int featureCount = 0;
47
	
48
	private Map params = new HashMap();
49
	
50
	public void setParam(String key, Object value) {
51
		params.put(key, value);
52
	}
53
	
54
	public Object getParam(String key) {
55
		return params.get(key);
56
	}
57
	
58
	public boolean isOverwrite() {
59
		return overwrite;
60
	}
61
	
62
	public void setOverwrite(boolean b) {
63
		overwrite = b;
64
	}
65
	
66
	public String getFilename() {
67
		return filename;
68
	}
69
	
70
	public void setFilename(String s) {
71
		filename = s;
72
	}
73
	
74
	public Envelope getEnvelope() {
75
		return envelope;
76
	}
77
	
78
	public void setEnvelope(Envelope env) {
79
		envelope = env;
80
	}
81
	
82
	public int getFeatureCount() {
83
		return featureCount;
84
	}
85
	
86
	public void setFeatureCount(int n) {
87
		featureCount = n;
88
	}
89
}
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/NearestNeighbourFinder.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: INearestNeighbourFinder.java 12380 2007-06-27 20:17:30Z azabala $
47
* $Log$
48
* Revision 1.2  2007-06-27 20:17:30  azabala
49
* new spatial index (rix)
50
*
51
* Revision 1.1  2006/05/02 18:21:17  azabala
52
* refactorizaci?n del nombre para seguir estandares de interfaces
53
*
54
* Revision 1.1  2006/05/01 18:38:41  azabala
55
* primera version en cvs del api de indices espaciales
56
*
57
*
58
*/
59
package org.gvsig.fmap.data.index;
60

  
61
import java.util.List;
62

  
63
import org.gvsig.fmap.geom.primitive.Envelope;
64
import org.gvsig.fmap.geom.primitive.Point2D;
65

  
66
/**
67
 * Find an specified number of items nearest to a given
68
 * geometry (Point or Rectangle2D as usual)
69
 *
70
 * @author azabala
71
 * @author jyarza
72
 */
73
public interface NearestNeighbourFinder {
74
	
75
	public List findNNearest(int numberOfNearest, Point2D point);
76
	
77
	public List findNNearest(int numberOfNearest, Envelope env);
78
}
79

  
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/SpatialIndexFactory.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.data.index;
29

  
30
import org.apache.log4j.Logger;
31

  
32
import com.iver.utiles.extensionPoints.ExtensionPoint;
33
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
34

  
35

  
36
/**
37
 * 
38
 * @author jyarza
39
 *
40
 */
41
public abstract class SpatialIndexFactory {
42

  
43
	private static Logger logger = Logger.getLogger(SpatialIndexFactory.class);
44
	
45
	
46
	public interface Factories {
47
		public static final String GT2_QUADTREE = "QuadTreeGt2Factory";
48
		public static final String JSI_RTREE = "RTreeJsiFactory";
49
		public static final String JTS_QUADTREE = "QuadTreeJtsFactory";
50
		public static final String SPATIALINDEX_RTREE = "RTreeSptLibFactory";
51
		public static final String DEFAULT = GT2_QUADTREE;
52
	}
53
	
54
	
55
	public static final String EXTENSION_POINT_NAME =  "SpatialIndexFactory";
56
	private static ExtensionPoint ep = new ExtensionPoint(EXTENSION_POINT_NAME, "Spatial Index Factory");
57
	
58
	static {		
59
		ExtensionPointsSingleton.getInstance().put(ep);
60
		logger.debug("factory static code executed");
61
	}
62

  
63
	public static SpatialIndexFactory getFactory(String type) throws InstantiationException, IllegalAccessException {
64
		if (type == null) type = Factories.DEFAULT;
65
		return (SpatialIndexFactory) ep.create(type);
66
	}
67
	
68
	protected static void registerFactory(String key, String description, Class value) {
69
		ep.put(key, description, value);
70
		logger.debug(key + " registered.");
71
	}
72
	
73
	
74
	public SpatialIndex createSpatialIndex() throws IndexException {
75
		return createSpatialIndex(null);
76
	}	
77

  
78
	public abstract SpatialIndex createSpatialIndex(SpatialIndexParameters params) throws IndexException;
79
}

Also available in: Unified diff