svn-gvsig-desktop / trunk / extensions / extWFS / src / com / iver / cit / gvsig / fmap / drivers / wfs / WFSFeatureIterator.java @ 3412
History | View | Annotate | Download (4.41 KB)
1 | 2277 | vcaballero | /* 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.Date; |
||
46 | import java.util.NoSuchElementException; |
||
47 | |||
48 | import org.geotools.data.FeatureReader; |
||
49 | import org.geotools.feature.Feature; |
||
50 | import org.geotools.feature.IllegalAttributeException; |
||
51 | |||
52 | import com.hardcode.gdbms.engine.values.Value; |
||
53 | import com.hardcode.gdbms.engine.values.ValueFactory; |
||
54 | import com.iver.cit.gvsig.fmap.core.IFeature; |
||
55 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
56 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
57 | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
||
58 | import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
||
59 | |||
60 | public class WFSFeatureIterator implements IFeatureIterator{ |
||
61 | //private IFeature[] features=null;
|
||
62 | private FeatureReader featureReader;
|
||
63 | //private ArrayList features;
|
||
64 | //private int index=-1;
|
||
65 | //private int pos=0;
|
||
66 | public WFSFeatureIterator(FeatureReader fr){
|
||
67 | featureReader=fr; |
||
68 | } |
||
69 | /*public WFSFeatureIterator(ArrayList l){
|
||
70 | features=l;
|
||
71 | }*/
|
||
72 | public boolean hasNext(){ |
||
73 | /*if (features !=null){
|
||
74 | if (index<features.size()-1)
|
||
75 | return true;
|
||
76 | else{
|
||
77 | index=-1;
|
||
78 | features=null;
|
||
79 | return false;
|
||
80 | }
|
||
81 | }*/
|
||
82 | try {
|
||
83 | if (featureReader.hasNext()){
|
||
84 | return true; |
||
85 | }else{
|
||
86 | featureReader.close(); |
||
87 | |||
88 | return false; |
||
89 | } |
||
90 | } catch (IOException e) { |
||
91 | e.printStackTrace(); |
||
92 | } |
||
93 | return false; |
||
94 | } |
||
95 | |||
96 | public IFeature next() throws SQLException { |
||
97 | /* if (features !=null){
|
||
98 | return (IFeature)features.get(++index);
|
||
99 | }*/
|
||
100 | Feature feature=null;
|
||
101 | try {
|
||
102 | feature = featureReader.next(); |
||
103 | } catch (NoSuchElementException e) { |
||
104 | e.printStackTrace(); |
||
105 | } catch (IOException e) { |
||
106 | e.printStackTrace(); |
||
107 | } catch (IllegalAttributeException e) {
|
||
108 | e.printStackTrace(); |
||
109 | } |
||
110 | Object[] attr=null; |
||
111 | attr=feature.getAttributes(attr); |
||
112 | Value[] values=getValues(attr);
|
||
113 | 3412 | fjp | |
114 | 2277 | vcaballero | |
115 | IGeometry g=ShapeFactory.createGeometry(FConverter.jts_to_java2d(feature.getDefaultGeometry())); |
||
116 | return new com.iver.cit.gvsig.fmap.core.DefaultFeature(g,values,feature.getID()); |
||
117 | } |
||
118 | private Value[] getValues(Object[] attr) { |
||
119 | Value[] values=new Value[attr.length]; |
||
120 | for (int i=1;i<attr.length;i++){ |
||
121 | if (attr[i]!=null){ |
||
122 | if (attr[i] instanceof Double){ |
||
123 | values[i]=ValueFactory.createValue(((Double)attr[i]).doubleValue());
|
||
124 | }else if (attr[i] instanceof String){ |
||
125 | values[i]=ValueFactory.createValue(String.valueOf(attr[i]));
|
||
126 | }else if (attr[i] instanceof Long){ |
||
127 | values[i]=ValueFactory.createValue(((Long)attr[i]).longValue());
|
||
128 | }else if (attr[i] instanceof Integer){ |
||
129 | values[i]=ValueFactory.createValue(((Integer)attr[i]).intValue());
|
||
130 | }else if (attr[i] instanceof Float){ |
||
131 | values[i]=ValueFactory.createValue(((Float)attr[i]).floatValue());
|
||
132 | }else if (attr[i] instanceof Short){ |
||
133 | values[i]=ValueFactory.createValue(((Short)attr[i]).shortValue());
|
||
134 | }else if (attr[i] instanceof Boolean){ |
||
135 | values[i]=ValueFactory.createValue(((Boolean)attr[i]).booleanValue());
|
||
136 | }else if (attr[i] instanceof Date){ |
||
137 | values[i]=ValueFactory.createValue(((Date)attr[i]));
|
||
138 | } |
||
139 | // System.out.println("class = "+attr[i].getClass());
|
||
140 | |||
141 | }else{
|
||
142 | values[i]=ValueFactory.createValue("");
|
||
143 | } |
||
144 | } |
||
145 | return values;
|
||
146 | } |
||
147 | 3273 | jmorell | public void closeIterator() throws SQLException { |
148 | // TODO Auto-generated method stub
|
||
149 | |||
150 | } |
||
151 | 2277 | vcaballero | |
152 | } |