Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / fmap / drivers / featureiterators / FeatureSelectionIterator.java @ 30110

History | View | Annotate | Download (2.97 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.drivers.featureiterators;
42

    
43
import org.cresques.cts.IProjection;
44

    
45
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
46
import com.hardcode.gdbms.engine.values.Value;
47
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
48
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
49
import com.iver.cit.gvsig.fmap.core.IFeature;
50
import com.iver.cit.gvsig.fmap.core.IGeometry;
51
import com.iver.cit.gvsig.fmap.drivers.featureiterators.DefaultFeatureIterator;
52
import com.iver.cit.gvsig.fmap.layers.FBitSet;
53
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
54

    
55
/**
56
 * 
57
 * Iterates over the selected features of a layer.
58
 * 
59
 * @author Alvaro Zabala
60
 *
61
 */
62
public class FeatureSelectionIterator extends DefaultFeatureIterator {
63

    
64
        
65
        FBitSet selection;
66

    
67
        public FeatureSelectionIterator(ReadableVectorial source,
68
                                                                                IProjection sourceProj, 
69
                                                                                IProjection targetProj, 
70
                                                                                String[] fieldNames)
71
                        throws ReadDriverException {
72
                super(source, sourceProj, targetProj, fieldNames);
73
                selection = this.source.getRecordset().getSelection();
74
                this.currentFeature = selection.nextSetBit(0);
75
        }
76

    
77
        public FeatureSelectionIterator(ReadableVectorial source)
78
                        throws ReadDriverException {
79
                super(source);
80
        }
81
        
82
        public boolean hasNext() throws ReadDriverException {
83
                return currentFeature != -1;
84
        }
85

    
86
        public IFeature next() throws ReadDriverException {
87
                try {
88
                        IGeometry geom = chekIfCloned(source.getShape(currentFeature));
89
                        reprojectIfNecessary(geom);
90
                        Value[] regAtt = getValues(currentFeature);
91
                        IFeature feat  = new DefaultFeature(geom, regAtt, currentFeature + "");
92
                        currentFeature = selection.nextSetBit(currentFeature + 1);
93
                        return feat;
94
                } catch (ExpansionFileReadException e) {
95
                        throw new ReadDriverException("",e);
96
                } 
97
        }
98
        
99
}