Revision 23758
branches/v2_0_0_prep/libraries/libFMap_spatialindex/src/org/gvsig/fmap/data/index/spatial/SpatialIndex.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.spatial; |
|
29 |
|
|
30 |
import org.gvsig.fmap.data.feature.FeatureID; |
|
31 |
import org.gvsig.fmap.data.index.Index; |
|
32 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
33 |
|
|
34 |
/** |
|
35 |
* An index whose data is of type Geometry, ie: A spatial index |
|
36 |
* |
|
37 |
* @author jyarza |
|
38 |
*/ |
|
39 |
public interface SpatialIndex extends Index { |
|
40 |
/** |
|
41 |
* Inserts an element into this index |
|
42 |
* @param env Geometry's Envelope |
|
43 |
* @param fid Feature unique identifier |
|
44 |
*/ |
|
45 |
public void insert(Envelope env, FeatureID fid); |
|
46 |
/** |
|
47 |
* Deletes an element from this index |
|
48 |
* @param env Geometry's Envelope |
|
49 |
* @param fid Feature unique identifier |
|
50 |
*/ |
|
51 |
public void delete(Envelope env, FeatureID fid); |
|
52 |
|
|
53 |
} |
|
54 |
|
|
55 |
|
|
56 |
|
branches/v2_0_0_prep/libraries/libFMap_spatialindex/src/org/gvsig/fmap/data/index/spatial/PersistentSpatialIndex.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.spatial; |
|
29 |
|
|
30 |
import org.gvsig.fmap.data.index.PersistentIndex; |
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* An spatial index based in persistent data stores. |
|
35 |
* |
|
36 |
* @author azabala |
|
37 |
* @author jyarza |
|
38 |
* @deprecated |
|
39 |
*/ |
|
40 |
public interface PersistentSpatialIndex extends PersistentIndex, SpatialIndex { |
|
41 |
|
|
42 |
|
|
43 |
} |
|
44 |
|
branches/v2_0_0_prep/libraries/libFMap_spatialindex/src/org/gvsig/fmap/data/index/spatial/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.spatial; |
|
30 |
|
|
31 |
import org.gvsig.fmap.data.index.QueryParameters; |
|
32 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
33 |
|
|
34 |
/** |
|
35 |
* |
|
36 |
* @author jyarza |
|
37 |
*/ |
|
38 |
public class SpatialQueryParameters extends QueryParameters { |
|
39 |
|
|
40 |
public void setDefaultValues() { |
|
41 |
setEnvelope(null); |
|
42 |
} |
|
43 |
|
|
44 |
public Envelope getEnvelope() { |
|
45 |
return (Envelope) get("envelope"); |
|
46 |
} |
|
47 |
|
|
48 |
public void setEnvelope(Envelope env) { |
|
49 |
set("envelope", env); |
|
50 |
} |
|
51 |
|
|
52 |
} |
|
53 |
|
branches/v2_0_0_prep/libraries/libFMap_spatialindex/src/org/gvsig/fmap/data/index/spatial/NearestNeighbourFinder.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.spatial; |
|
29 |
|
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
33 |
import org.gvsig.fmap.geom.primitive.Point2D; |
|
34 |
|
|
35 |
/** |
|
36 |
* Find an specified number of items nearest to a given |
|
37 |
* geometry (Point or Rectangle2D as usual) |
|
38 |
* |
|
39 |
* @author azabala |
|
40 |
* @author jyarza |
|
41 |
*/ |
|
42 |
public interface NearestNeighbourFinder { |
|
43 |
|
|
44 |
public List findNNearest(int numberOfNearest, Point2D point); |
|
45 |
|
|
46 |
public List findNNearest(int numberOfNearest, Envelope env); |
|
47 |
} |
|
48 |
|
branches/v2_0_0_prep/libraries/libFMap_spatialindex/src/org/gvsig/fmap/data/index/spatial/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.spatial; |
|
30 |
|
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.List; |
|
33 |
|
|
34 |
import org.apache.log4j.Logger; |
|
35 |
import org.gvsig.fmap.data.feature.Feature; |
|
36 |
import org.gvsig.fmap.data.feature.FeatureID; |
|
37 |
import org.gvsig.fmap.data.index.AbstractIndex; |
|
38 |
import org.gvsig.fmap.data.index.IndexException; |
|
39 |
import org.gvsig.fmap.data.index.IndexParameters; |
|
40 |
import org.gvsig.fmap.data.index.QueryParameters; |
|
41 |
import org.gvsig.fmap.geom.Geometry; |
|
42 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
43 |
|
|
44 |
/** |
|
45 |
* This class is a wrapper for spatial indexes based on int values so that they can use |
|
46 |
* FeatureID instead. |
|
47 |
* |
|
48 |
* @author jyarza |
|
49 |
* |
|
50 |
*/ |
|
51 |
public abstract class AbstractIntBasedSpatialIndex extends AbstractIndex implements SpatialIndex { |
|
52 |
|
|
53 |
private static Logger logger = Logger.getLogger(AbstractIntBasedSpatialIndex.class); |
|
54 |
|
|
55 |
/** Keeps the correspondence between the int value used internally and FeatureID */ |
|
56 |
private List ids = new ArrayList(); |
|
57 |
|
|
58 |
public AbstractIntBasedSpatialIndex(IndexParameters params) throws IndexException { |
|
59 |
super(params); |
|
60 |
} |
|
61 |
|
|
62 |
public final void delete(Envelope env, FeatureID fid) { |
|
63 |
int idx = ids.indexOf(fid); |
|
64 |
if (idx >= 0) { |
|
65 |
this.delete(env, idx); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
public final void insert(Envelope env, FeatureID fid) { |
|
70 |
ids.add(fid); |
|
71 |
this.insert(env, ids.size()-1); |
|
72 |
} |
|
73 |
|
|
74 |
public final List query(QueryParameters params) throws IndexException { |
|
75 |
long start = System.currentTimeMillis(); |
|
76 |
try { |
|
77 |
SpatialQueryParameters sqp = (SpatialQueryParameters) params; |
|
78 |
List result = query(sqp.getEnvelope()); |
|
79 |
|
|
80 |
// replace integers by corresponding FeatureIDs in the list |
|
81 |
for (int i=0; i<result.size(); i++) { |
|
82 |
int value = ((Integer) result.get(i)).intValue(); |
|
83 |
result.set(i, ids.get(value)); |
|
84 |
} |
|
85 |
long end = System.currentTimeMillis(); |
|
86 |
logger.debug("total index query time = " + (end-start) + " millis."); |
|
87 |
return result; |
|
88 |
} catch (ClassCastException e) { |
|
89 |
throw new IndexException(e); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
public final void delete(Object o, FeatureID fid) { |
|
94 |
delete((Envelope) o, fid); |
|
95 |
} |
|
96 |
|
|
97 |
public final void insert(Object o, FeatureID fid) { |
|
98 |
insert((Envelope) o, fid); |
|
99 |
} |
|
100 |
|
|
101 |
/* |
|
102 |
* overrides org.gvsig.fmap.data.index.AbstractIndex.insert because these spatial indexes |
|
103 |
* use the geometry envelope instead of the geometry itself. |
|
104 |
*/ |
|
105 |
public final void insert(Feature feat) { |
|
106 |
Geometry geom = (Geometry) feat.get(getFeatureAttributeDescriptor().getName()); |
|
107 |
insert(geom.getEnvelope(), feat.getID()); |
|
108 |
} |
|
109 |
|
|
110 |
/** Spatial indexes based on int values will implement this method for insertion */ |
|
111 |
protected abstract void insert(Envelope env, int index); |
|
112 |
/** Spatial indexes based on int values will implement this method for deletion */ |
|
113 |
protected abstract void delete(Envelope env, int index); |
|
114 |
/** Spatial indexes based on int values will implement this method for querying */ |
|
115 |
protected abstract List query(Envelope env) throws IndexException; |
|
116 |
} |
|
117 |
|
Also available in: Unified diff