svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / gml / GMLDriver.java @ 19509
History | View | Annotate | Download (8.62 KB)
1 | 19509 | jcarrasco | package com.iver.cit.gvsig.fmap.drivers.gml; |
---|---|---|---|
2 | |||
3 | import java.io.File; |
||
4 | import java.util.ArrayList; |
||
5 | import java.util.Hashtable; |
||
6 | |||
7 | import org.apache.log4j.Logger; |
||
8 | import org.gvsig.exceptions.ListBaseException; |
||
9 | import org.gvsig.remoteClient.gml.GMLReader; |
||
10 | import org.gvsig.remoteClient.gml.IGMLFeaturesIterator; |
||
11 | import org.gvsig.remoteClient.gml.exceptions.GMLException; |
||
12 | import org.gvsig.remoteClient.gml.factories.IGeometriesFactory; |
||
13 | |||
14 | import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
||
15 | import com.hardcode.gdbms.engine.values.IntValue; |
||
16 | import com.hardcode.gdbms.engine.values.Value; |
||
17 | import com.hardcode.gdbms.engine.values.ValueFactory; |
||
18 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
19 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
20 | import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
||
21 | import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
||
22 | import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
||
23 | import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
||
24 | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
||
25 | import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver; |
||
26 | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
||
27 | import com.iver.cit.gvsig.fmap.drivers.gml.FMAPGeometryFactory.FeatureWithAttributes; |
||
28 | |||
29 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
30 | *
|
||
31 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
32 | *
|
||
33 | * This program is free software; you can redistribute it and/or
|
||
34 | * modify it under the terms of the GNU General Public License
|
||
35 | * as published by the Free Software Foundation; either version 2
|
||
36 | * of the License, or (at your option) any later version.
|
||
37 | *
|
||
38 | * This program is distributed in the hope that it will be useful,
|
||
39 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
41 | * GNU General Public License for more details.
|
||
42 | *
|
||
43 | * You should have received a copy of the GNU General Public License
|
||
44 | * along with this program; if not, write to the Free Software
|
||
45 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
46 | *
|
||
47 | * For more information, contact:
|
||
48 | *
|
||
49 | * Generalitat Valenciana
|
||
50 | * Conselleria d'Infraestructures i Transport
|
||
51 | * Av. Blasco Ib??ez, 50
|
||
52 | * 46010 VALENCIA
|
||
53 | * SPAIN
|
||
54 | *
|
||
55 | * +34 963862235
|
||
56 | * gvsig@gva.es
|
||
57 | * www.gvsig.gva.es
|
||
58 | *
|
||
59 | * or
|
||
60 | *
|
||
61 | * IVER T.I. S.A
|
||
62 | * Salamanca 50
|
||
63 | * 46005 Valencia
|
||
64 | * Spain
|
||
65 | *
|
||
66 | * +34 963163400
|
||
67 | * dac@iver.es
|
||
68 | */
|
||
69 | /* CVS MESSAGES:
|
||
70 | *
|
||
71 | * $Id: GMLDriver.java 13882 2007-09-19 16:25:05Z jaume $
|
||
72 | * $Log$
|
||
73 | * Revision 1.13 2007-09-19 16:25:05 jaume
|
||
74 | * ReadExpansionFileException removed from this context
|
||
75 | *
|
||
76 | * Revision 1.12 2007/03/20 16:09:41 jaume
|
||
77 | * refactored to use ISymbol instead of FSymbol
|
||
78 | *
|
||
79 | * Revision 1.11 2007/03/06 17:08:56 caballero
|
||
80 | * Exceptions
|
||
81 | *
|
||
82 | * Revision 1.10 2007/02/09 14:11:25 jorpiell
|
||
83 | * Soporte para WFS 1.1
|
||
84 | *
|
||
85 | * Revision 1.9 2007/01/16 08:40:49 jorpiell
|
||
86 | * Eliminado un improt para hacer que compile
|
||
87 | *
|
||
88 | * Revision 1.8 2007/01/16 08:34:37 csanchez
|
||
89 | * Sistema de Warnings y Excepciones adaptado a BasicException
|
||
90 | *
|
||
91 | * Revision 1.7 2006/12/29 17:12:10 jorpiell
|
||
92 | * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
|
||
93 | *
|
||
94 | * Revision 1.6 2006/10/02 08:49:50 jorpiell
|
||
95 | * Cambios provocados el el cambio de FSymbol
|
||
96 | *
|
||
97 | * Revision 1.5 2006/10/02 08:41:23 jorpiell
|
||
98 | * Actualizados los drivers de GML
|
||
99 | *
|
||
100 | * Revision 1.2.4.2 2006/09/28 08:53:47 jorpiell
|
||
101 | * No se tiene en cuanta la reproyecci?n
|
||
102 | *
|
||
103 | * Revision 1.2.4.1 2006/09/19 12:22:48 jorpiell
|
||
104 | * Ya no se depende de geotools
|
||
105 | *
|
||
106 | * Revision 1.3 2006/09/18 12:09:43 jorpiell
|
||
107 | * El driver de GML ya no depende de geotools
|
||
108 | *
|
||
109 | * Revision 1.2 2006/08/10 12:03:43 jorpiell
|
||
110 | * Se usa el nuevo driver de GML de remoteServices
|
||
111 | *
|
||
112 | * Revision 1.1 2006/07/19 12:29:39 jorpiell
|
||
113 | * A?adido el driver de GML
|
||
114 | *
|
||
115 | *
|
||
116 | */
|
||
117 | /**
|
||
118 | * This class implements the gvSIG GML parser using the geotools
|
||
119 | * library
|
||
120 | *
|
||
121 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
122 | */
|
||
123 | public class GMLDriver extends ConcreteMemoryDriver implements VectorialFileDriver{ |
||
124 | private static Logger logger = Logger.getLogger(GMLDriver.class.getName()); |
||
125 | private File m_Fich; |
||
126 | private IGeometriesFactory factory = new FMAPGeometryFactory(); |
||
127 | private Hashtable hashRelate = new Hashtable(); |
||
128 | private ArrayList features = new ArrayList(); |
||
129 | private IGMLFeaturesIterator iterator = null; |
||
130 | private GMLReader reader;
|
||
131 | |||
132 | /*
|
||
133 | * (non-Javadoc)
|
||
134 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
|
||
135 | */
|
||
136 | public void open(File f) { |
||
137 | m_Fich = f; |
||
138 | } |
||
139 | |||
140 | /*
|
||
141 | * (non-Javadoc)
|
||
142 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
||
143 | */
|
||
144 | public void close() { |
||
145 | // TODO Auto-generated method stub
|
||
146 | |||
147 | } |
||
148 | |||
149 | /*
|
||
150 | * (non-Javadoc)
|
||
151 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
|
||
152 | */
|
||
153 | public void initialize() throws InitializeDriverException{ |
||
154 | float heightText = 10; |
||
155 | |||
156 | try {
|
||
157 | reader = new GMLReader(m_Fich,factory);
|
||
158 | iterator = reader.getFeaturesIterator(); |
||
159 | } catch (GMLException e1) {
|
||
160 | throw new InitializeDriverException(getName(),e1); |
||
161 | } |
||
162 | |||
163 | |||
164 | |||
165 | |||
166 | int index = 0; |
||
167 | |||
168 | IntValue clave; |
||
169 | ISymbol theSymbol = null;
|
||
170 | |||
171 | boolean setModel = false; |
||
172 | FeatureWithAttributes feature; |
||
173 | try {
|
||
174 | while (iterator.hasNext()) {
|
||
175 | try{
|
||
176 | feature = (FeatureWithAttributes)iterator.next(); |
||
177 | if (feature != null){ |
||
178 | hashRelate.put(feature.getFeature().getID(), new Integer(index)); |
||
179 | features.add(feature); |
||
180 | |||
181 | if (!setModel){
|
||
182 | getTableModel().setColumnIdentifiers(feature.getAttributeName()); |
||
183 | } |
||
184 | clave = ValueFactory.createValue(index); |
||
185 | IGeometry geom = feature.getFeature().getGeometry(); |
||
186 | if (geom != null){ |
||
187 | FShape shape = (FShape)geom.getInternalShape(); |
||
188 | |||
189 | /*jaume, moved to ISymbol
|
||
190 | * theSymbol = new FSymbol(getShapeType());
|
||
191 | theSymbol.setDescription(clave.toString());
|
||
192 | theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
|
||
193 | theSymbol.setSize(3);
|
||
194 | theSymbol.setSizeInPixels(true);*/
|
||
195 | theSymbol = SymbologyFactory. |
||
196 | createDefaultSymbolByShapeType(getShapeType()); |
||
197 | if (theSymbol instanceof IMarkerSymbol) { |
||
198 | ((IMarkerSymbol) theSymbol).setSize(3);
|
||
199 | } |
||
200 | if (theSymbol instanceof ILineSymbol) { |
||
201 | ((ILineSymbol) theSymbol).setLineWidth(3);
|
||
202 | } |
||
203 | if (theSymbol instanceof IFillSymbol) { |
||
204 | ((IFillSymbol) theSymbol).getOutline().setLineWidth(3);
|
||
205 | } |
||
206 | |||
207 | addShape(shape, feature.getAttributeValue()); |
||
208 | |||
209 | } |
||
210 | } |
||
211 | index++; |
||
212 | }catch(GMLException e){
|
||
213 | logger.error(e.getMessage(),e); |
||
214 | } |
||
215 | } |
||
216 | ListBaseException listwarnings; |
||
217 | listwarnings = reader.getWarnings(); |
||
218 | }catch (GMLException e) {
|
||
219 | logger.error(e.getMessage(),e); |
||
220 | } |
||
221 | } |
||
222 | |||
223 | |||
224 | /*
|
||
225 | * (non-Javadoc)
|
||
226 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
|
||
227 | */
|
||
228 | public boolean accept(File f) { |
||
229 | if ((f.getName().toUpperCase().endsWith("GML")) || |
||
230 | (f.getName().toUpperCase().endsWith("XML"))){
|
||
231 | return true; |
||
232 | } |
||
233 | return false; |
||
234 | |||
235 | } |
||
236 | |||
237 | /*
|
||
238 | * (non-Javadoc)
|
||
239 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFile()
|
||
240 | */
|
||
241 | public File getFile() { |
||
242 | return m_Fich;
|
||
243 | } |
||
244 | |||
245 | /*
|
||
246 | * (non-Javadoc)
|
||
247 | * @see com.hardcode.driverManager.Driver#getName()
|
||
248 | */
|
||
249 | public String getName() { |
||
250 | return "gvSIG GML Memory Driver"; |
||
251 | } |
||
252 | |||
253 | /*
|
||
254 | * (non-Javadoc)
|
||
255 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
|
||
256 | */
|
||
257 | public int getShapeType() { |
||
258 | return FShape.MULTI;
|
||
259 | } |
||
260 | |||
261 | /**
|
||
262 | * @return Returns the hashRelate.
|
||
263 | */
|
||
264 | public Hashtable getHashRelate() { |
||
265 | return hashRelate;
|
||
266 | } |
||
267 | |||
268 | /**
|
||
269 | * @return Returns the features.
|
||
270 | */
|
||
271 | public ArrayList getFeatures() { |
||
272 | return features;
|
||
273 | } |
||
274 | |||
275 | /**
|
||
276 | * @return Returns the iterator.
|
||
277 | */
|
||
278 | public IGMLFeaturesIterator getIterator() {
|
||
279 | return iterator;
|
||
280 | } |
||
281 | |||
282 | /**
|
||
283 | * Gets the attributes list
|
||
284 | * @return
|
||
285 | */
|
||
286 | public String getAttributeName(int position){ |
||
287 | if (features.size() > 0){ |
||
288 | return ((String)((FeatureWithAttributes)features.get(0)).getAttributeName()[position]); |
||
289 | } |
||
290 | return null; |
||
291 | } |
||
292 | |||
293 | /**
|
||
294 | * Gets the attributes list
|
||
295 | * @return
|
||
296 | */
|
||
297 | public Value getAttributeValue(int position){ |
||
298 | if (features.size() > 0){ |
||
299 | return ((Value)((FeatureWithAttributes)features.get(0)).getAttributeValue()[position]); |
||
300 | } |
||
301 | return null; |
||
302 | } |
||
303 | |||
304 | /**
|
||
305 | * Gets the attributes size
|
||
306 | * @return
|
||
307 | */
|
||
308 | public int getAttributeCount(){ |
||
309 | if (features.size() > 0){ |
||
310 | return ((FeatureWithAttributes)features.get(0)).getAttributeValue().length; |
||
311 | } |
||
312 | return 0; |
||
313 | } |
||
314 | } |