Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / index / spatial / AbstractIntBasedSpatialIndex.java @ 23285

History | View | Annotate | Download (2.76 KB)

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.Iterator;
33
import java.util.List;
34

    
35
import org.apache.log4j.Logger;
36
import org.gvsig.fmap.data.feature.FeatureID;
37
import org.gvsig.fmap.data.index.IndexException;
38
import org.gvsig.fmap.data.index.QueryParameters;
39
import org.gvsig.fmap.geom.primitive.Envelope;
40

    
41
/**
42
 * This class is a wrapper for indexes based on int values, 
43
 * so that they can use FeatureID instead.
44
 *
45
 * @author jyarza
46
 *
47
 */
48
public abstract class AbstractIntBasedSpatialIndex implements SpatialIndex {
49

    
50
        private static Logger logger = Logger.getLogger(AbstractIntBasedSpatialIndex.class);
51
        
52
        /** Keeps the correspondence between the int value used internally and FeatureID */
53
        private ArrayList ids = new ArrayList();
54
        
55
        public void delete(org.gvsig.fmap.geom.primitive.Envelope env, FeatureID fid) {                
56
                int idx = ids.indexOf(fid);
57
                if (idx >= 0) {
58
                        this.delete(env, idx);
59
                }
60
        }
61

    
62
        public void insert(Envelope env, FeatureID fid) {
63
                ids.add(fid);
64
                this.insert(env, ids.size()-1);
65
        }
66

    
67
        public List query(QueryParameters params) throws IndexException {
68
                long start = System.currentTimeMillis();
69
                try {
70
                        SpatialQueryParameters sqp = (SpatialQueryParameters) params;
71
                        List result = query(sqp.getEnvelope());
72
                        
73
                        // replace integers by corresponding FeatureIDs in the list
74
                        for (int i=0; i<result.size(); i++) {
75
                                int value = ((Integer) result.get(i)).intValue();
76
                                result.set(i, ids.get(value));
77
                        }
78
                        long end = System.currentTimeMillis();
79
                        logger.debug("total index query time = " + (end-start) + " milis.");
80
                        return result;
81
                } catch (ClassCastException e) {
82
                        throw new IndexException(e);
83
                }
84
        }
85
        
86
        public abstract void insert(Envelope env, int index);
87
        public abstract void delete(Envelope env, int index);
88
        public abstract List query(Envelope env) throws IndexException;
89
}
90