Statistics
| Revision:

svn-gvsig-desktop / branches / Fmap_GisPlanet / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / wfs / WFSFeatureIterator.java @ 1919

History | View | Annotate | Download (4.36 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 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 com.iver.cit.gvsig.fmap.drivers.wfs;
42

    
43
import java.io.IOException;
44
import java.sql.SQLException;
45
import java.util.ArrayList;
46
import java.util.Date;
47
import java.util.NoSuchElementException;
48

    
49
import org.geotools.data.FeatureReader;
50
import org.geotools.feature.DefaultFeature;
51
import org.geotools.feature.Feature;
52
import org.geotools.feature.IllegalAttributeException;
53

    
54
import com.hardcode.gdbms.engine.values.Value;
55
import com.hardcode.gdbms.engine.values.ValueFactory;
56
import com.iver.cit.gvsig.fmap.core.IFeature;
57
import com.iver.cit.gvsig.fmap.core.IGeometry;
58
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
59
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
60
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
61

    
62
public class WFSFeatureIterator implements IFeatureIterator{
63
        //private IFeature[] features=null;
64
        private FeatureReader featureReader;
65
        //private ArrayList features;
66
        //private int index=-1;
67
        //private int pos=0;
68
        public WFSFeatureIterator(FeatureReader fr){
69
                featureReader=fr;
70
        }
71
        /*public WFSFeatureIterator(ArrayList l){
72
                features=l;
73
        }*/
74
        public boolean hasNext(){
75
                /*if (features !=null){
76
                        if (index<features.size()-1)
77
                                return true;
78
                        else{
79
                                index=-1;
80
                                features=null;
81
                                return false;
82
                        }
83
                }*/
84
                try {
85
                        if (featureReader.hasNext()){
86
                                return true;
87
                        }else{
88
                                featureReader.close();
89
                                
90
                                return false;
91
                        }
92
                } catch (IOException e) {
93
                        e.printStackTrace();
94
                }
95
                return false;
96
        }
97

    
98
        public IFeature next() throws SQLException {
99
        /*        if (features !=null){
100
                        return (IFeature)features.get(++index);
101
                }*/
102
                Feature feature=null;
103
                try {
104
                        feature = featureReader.next();
105
                } catch (NoSuchElementException e) {
106
                        e.printStackTrace();
107
                } catch (IOException e) {
108
                        e.printStackTrace();
109
                } catch (IllegalAttributeException e) {
110
                        e.printStackTrace();
111
                }
112
                Object[] attr=null;
113
                attr=feature.getAttributes(attr);
114
                Value[] values=getValues(attr);
115
                
116
                IGeometry g=ShapeFactory.createGeometry(FConverter.jts_to_java2d(feature.getDefaultGeometry()));
117
                return new com.iver.cit.gvsig.fmap.core.DefaultFeature(g,values,feature.getID());
118
        }
119
        private Value[] getValues(Object[] attr) {
120
                Value[] values=new Value[attr.length];
121
                for (int i=1;i<attr.length;i++){
122
                        if (attr[i]!=null){
123
                                if (attr[i] instanceof Double){
124
                                        values[i]=ValueFactory.createValue(((Double)attr[i]).doubleValue());
125
                                }else if (attr[i] instanceof String){
126
                                        values[i]=ValueFactory.createValue(String.valueOf(attr[i]));
127
                                }else if (attr[i] instanceof Long){
128
                                        values[i]=ValueFactory.createValue(((Long)attr[i]).longValue());
129
                                }else if (attr[i] instanceof Integer){
130
                                        values[i]=ValueFactory.createValue(((Integer)attr[i]).intValue());
131
                                }else if (attr[i] instanceof Float){
132
                                        values[i]=ValueFactory.createValue(((Float)attr[i]).floatValue());
133
                                }else if (attr[i] instanceof Short){
134
                                        values[i]=ValueFactory.createValue(((Short)attr[i]).shortValue());
135
                                }else if (attr[i] instanceof Boolean){
136
                                        values[i]=ValueFactory.createValue(((Boolean)attr[i]).booleanValue());
137
                                }else if (attr[i] instanceof Date){
138
                                        values[i]=ValueFactory.createValue(((Date)attr[i]));
139
                                }
140
                        //        System.out.println("class = "+attr[i].getClass());
141
                                        
142
                        }else{
143
                                values[i]=ValueFactory.createValue("");
144
                        }
145
                }
146
                return values;
147
        }
148
        
149
}