Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / gml / GMLDriver.java @ 18335

History | View | Annotate | Download (8.22 KB)

1
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.remoteClient.gml.GMLReader;
9
import org.gvsig.remoteClient.gml.IGMLFeaturesIterator;
10
import org.gvsig.remoteClient.gml.exceptions.GMLException;
11
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory;
12

    
13
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
14
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
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
import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver;
25
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
26
import com.iver.cit.gvsig.fmap.drivers.gml.FMAPGeometryFactory.FeatureWithAttributes;
27

    
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: GMLDriver.java 18335 2008-01-28 13:34:05Z jpiera $
71
 * $Log$
72
 * 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
 * refactored to use ISymbol instead of FSymbol
77
 *
78
 * Revision 1.11  2007/03/06 17:08:56  caballero
79
 * Exceptions
80
 *
81
 * Revision 1.10  2007/02/09 14:11:25  jorpiell
82
 * Soporte para WFS 1.1
83
 *
84
 * Revision 1.9  2007/01/16 08:40:49  jorpiell
85
 * Eliminado un improt para hacer que compile
86
 *
87
 * Revision 1.8  2007/01/16 08:34:37  csanchez
88
 * Sistema de Warnings y Excepciones adaptado a BasicException
89
 *
90
 * Revision 1.7  2006/12/29 17:12:10  jorpiell
91
 * 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
 * Cambios provocados el el cambio de FSymbol
95
 *
96
 * Revision 1.5  2006/10/02 08:41:23  jorpiell
97
 * Actualizados los drivers de GML
98
 *
99
 * 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
 * Revision 1.3  2006/09/18 12:09:43  jorpiell
106
 * El driver de GML ya no depende de geotools
107
 *
108
 * Revision 1.2  2006/08/10 12:03:43  jorpiell
109
 * Se usa el nuevo driver de GML de remoteServices
110
 *
111
 * Revision 1.1  2006/07/19 12:29:39  jorpiell
112
 * A?adido el driver de GML
113
 *
114
 *
115
 */
116
/**
117
 * This class implements the gvSIG GML parser using the geotools
118
 * library
119
 *
120
 * @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
        private IGeometriesFactory factory = new FMAPGeometryFactory();
126
        private Hashtable hashRelate = new Hashtable();
127
        private ArrayList features = new ArrayList();
128
        private IGMLFeaturesIterator iterator = null;
129
        private GMLReader reader;
130

    
131
        /*
132
         *  (non-Javadoc)
133
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
134
         */
135
        public void open(File f) {
136
                m_Fich = f;
137
        }
138

    
139
        /*
140
         *  (non-Javadoc)
141
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
142
         */
143
        public void close() {
144
                // TODO Auto-generated method stub
145

    
146
        }
147

    
148
        /*
149
         *  (non-Javadoc)
150
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
151
         */
152
        public void initialize() throws InitializeDriverException{
153
                float heightText = 10;
154

    
155
                try {
156
                        reader = new GMLReader(m_Fich,factory);
157
                        iterator = reader.getFeaturesIterator();
158
                } catch (GMLException e1) {
159
                        throw new InitializeDriverException(getName(),e1);
160
                }
161

    
162

    
163

    
164

    
165
                int index = 0;
166

    
167
                IntValue clave;
168
                ISymbol theSymbol = null;
169

    
170
                boolean setModel = false;
171
                FeatureWithAttributes feature;
172
                try {
173
                        while (iterator.hasNext()) {
174
                                try{
175
                                        feature = (FeatureWithAttributes)iterator.next();
176
                                        if (feature != null){
177
                                                hashRelate.put(feature.getFeature().getID(), new Integer(index));
178
                                                features.add(feature);
179

    
180
                                                if (!setModel){
181
                                                        getTableModel().setColumnIdentifiers(feature.getAttributeName());
182
                                                }
183
                                                clave = ValueFactory.createValue(index);
184
                                                IGeometry geom = feature.getFeature().getGeometry();
185
                                                if (geom != null){
186
                                                        FShape shape = (FShape)geom.getInternalShape();
187

    
188
                                                        /*jaume, moved to ISymbol
189
                                                         * theSymbol = new FSymbol(getShapeType());
190
                                                        theSymbol.setDescription(clave.toString());
191
                                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
192
                                                        theSymbol.setSize(3);
193
                                                        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

    
206
                                                        addShape(shape, feature.getAttributeValue());
207

    
208
                                                }
209
                                        }
210
                                        index++;
211
                                }catch(GMLException e){
212
                                        logger.error(e.getMessage(),e);
213
                                }
214
                        }
215
                        //ListBaseException listwarnings;
216
                        //listwarnings = reader.getWarnings();
217
                }catch (GMLException e) {
218
                        logger.error(e.getMessage(),e);
219
                }
220
        }
221

    
222

    
223
        /*
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
                }
232
                return false;
233

    
234
        }
235

    
236
        /*
237
         *  (non-Javadoc)
238
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFile()
239
         */
240
        public File getFile() {
241
                return m_Fich;
242
        }
243

    
244
        /*
245
         *  (non-Javadoc)
246
         * @see com.hardcode.driverManager.Driver#getName()
247
         */
248
        public String getName() {
249
                return "gvSIG GML Memory Driver";
250
        }
251

    
252
        /*
253
         *  (non-Javadoc)
254
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
255
         */
256
        public int getShapeType() {
257
                return FShape.MULTI;
258
        }
259

    
260
        /**
261
         * @return Returns the hashRelate.
262
         */
263
        public Hashtable getHashRelate() {
264
                return hashRelate;
265
        }
266

    
267
        /**
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
        }
280

    
281
        /**
282
         * Gets the attributes list
283
         * @return
284
         */
285
        public String getAttributeName(int position){
286
                if (features.size() > 0){
287
                        return ((String)((FeatureWithAttributes)features.get(0)).getAttributeName()[position]);
288
                }
289
                return null;
290
        }
291

    
292
        /**
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

    
303
        /**
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
}