Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / core / CacheFeatureExtractor.java @ 30840

History | View | Annotate | Download (2.42 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
* 2009 Software Colaborativo (www.scolab.es)   development
26
*/
27
 
28
package org.gvsig.graph.core;
29

    
30
import java.util.ArrayList;
31

    
32
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
33
import com.hardcode.gdbms.engine.values.Value;
34
import com.iver.cit.gvsig.fmap.core.IFeature;
35
import com.iver.cit.gvsig.fmap.core.IGeometry;
36
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
37
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
38

    
39
public class CacheFeatureExtractor implements IFeatureExtractor {
40

    
41
        ArrayList<IFeature> feats;
42
        
43
        /**
44
         * @param lyr The layer from features will be extracted.
45
         * @param fields null if you want to use all the fields. If you need only some
46
         * fields, put here their names.
47
         */
48
        public CacheFeatureExtractor(FLyrVect lyr, String[] fields) {
49
                try {
50
                        IFeatureIterator iterator = null;
51
                        if (fields != null)
52
                                iterator = lyr.getSource().getFeatureIterator(fields, null);
53
                        else
54
                                iterator = lyr.getSource().getFeatureIterator();
55
                        
56
                        while (iterator.hasNext()) {
57
                                IFeature feat = iterator.next();
58
                                feats.add(feat);
59
                        }
60
                        iterator.closeIterator();
61
                } catch (ReadDriverException e) {
62
                        // TODO Auto-generated catch block
63
                        e.printStackTrace();
64
                }
65
        }
66
        
67
        public IFeature getFeature(long i) {
68
                return feats.get((int) i);
69
        }
70

    
71
        public Value getFieldValue(long idRec, int idField) {
72
                return getFeature(idRec).getAttribute(idField);
73
        }
74

    
75
        public IGeometry getGeometry(long i) {
76
                return getFeature(i).getGeometry();
77
        }
78

    
79
}
80