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