Statistics
| Revision:

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

History | View | Annotate | Download (7.83 KB)

1
package com.iver.cit.gvsig.fmap.drivers.gml;
2

    
3
import java.awt.Color;
4
import java.awt.Font;
5
import java.io.File;
6
import java.util.ArrayList;
7
import java.util.Hashtable;
8

    
9
import org.apache.log4j.Logger;
10
import org.gvsig.exceptions.ListBaseException;
11
import org.gvsig.remoteClient.gml.GMLReader;
12
import org.gvsig.remoteClient.gml.IGMLFeaturesIterator;
13
import org.gvsig.remoteClient.gml.exceptions.GMLException;
14
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory;
15

    
16
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
17
import com.hardcode.gdbms.engine.values.IntValue;
18
import com.hardcode.gdbms.engine.values.Value;
19
import com.hardcode.gdbms.engine.values.ValueFactory;
20
import com.iver.cit.gvsig.fmap.core.FShape;
21
import com.iver.cit.gvsig.fmap.core.IGeometry;
22
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
23
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
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 10627 2007-03-06 17:10:21Z caballero $
71
 * $Log$
72
 * Revision 1.11  2007-03-06 17:08:56  caballero
73
 * Exceptions
74
 *
75
 * Revision 1.10  2007/02/09 14:11:25  jorpiell
76
 * Soporte para WFS 1.1
77
 *
78
 * Revision 1.9  2007/01/16 08:40:49  jorpiell
79
 * Eliminado un improt para hacer que compile
80
 *
81
 * Revision 1.8  2007/01/16 08:34:37  csanchez
82
 * Sistema de Warnings y Excepciones adaptado a BasicException
83
 *
84
 * Revision 1.7  2006/12/29 17:12:10  jorpiell
85
 * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
86
 *
87
 * Revision 1.6  2006/10/02 08:49:50  jorpiell
88
 * Cambios provocados el el cambio de FSymbol
89
 *
90
 * Revision 1.5  2006/10/02 08:41:23  jorpiell
91
 * Actualizados los drivers de GML
92
 *
93
 * Revision 1.2.4.2  2006/09/28 08:53:47  jorpiell
94
 * No se tiene en cuanta la reproyecci?n
95
 *
96
 * Revision 1.2.4.1  2006/09/19 12:22:48  jorpiell
97
 * Ya no se depende de geotools
98
 *
99
 * Revision 1.3  2006/09/18 12:09:43  jorpiell
100
 * El driver de GML ya no depende de geotools
101
 *
102
 * Revision 1.2  2006/08/10 12:03:43  jorpiell
103
 * Se usa el nuevo driver de GML de remoteServices
104
 *
105
 * Revision 1.1  2006/07/19 12:29:39  jorpiell
106
 * A?adido el driver de GML
107
 *
108
 *
109
 */
110
/**
111
 * This class implements the gvSIG GML parser using the geotools
112
 * library
113
 *
114
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
115
 */
116
public class GMLDriver extends ConcreteMemoryDriver implements VectorialFileDriver{
117
        private static Logger logger = Logger.getLogger(GMLDriver.class.getName());
118
        private File m_Fich;
119
        private IGeometriesFactory factory = new FMAPGeometryFactory();
120
        private Hashtable hashRelate = new Hashtable();
121
        private ArrayList features = new ArrayList();
122
        private IGMLFeaturesIterator iterator = null;
123
        private GMLReader reader;
124

    
125
        /*
126
         *  (non-Javadoc)
127
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
128
         */
129
        public void open(File f) {
130
                m_Fich = f;
131
        }
132

    
133
        /*
134
         *  (non-Javadoc)
135
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
136
         */
137
        public void close() {
138
                // TODO Auto-generated method stub
139

    
140
        }
141

    
142
        /*
143
         *  (non-Javadoc)
144
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
145
         */
146
        public void initialize() throws InitializeDriverException{
147
                float heightText = 10;
148

    
149
                try {
150
                        reader = new GMLReader(m_Fich,factory);
151
                        iterator = reader.getFeaturesIterator();
152
                } catch (GMLException e1) {
153
                        throw new InitializeDriverException(getName(),e1);
154
                }
155

    
156

    
157
                FSymbol symbol = new FSymbol(getShapeType());
158
                symbol.setShapeVisible(false);
159
                symbol.setFontSizeInPixels(false);
160
                symbol.setFont(new Font("SansSerif",
161
                                Font.PLAIN, 9));
162
                symbol.setFontColor(Color.BLACK);
163
                symbol.setFontSize(heightText);
164
                symbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
165
                symbol.setSize(3);
166
                symbol.setSizeInPixels(true);
167

    
168
                int index = 0;
169

    
170
                IntValue clave;
171
                FSymbol theSymbol = null;
172

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

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

    
191
                                                        theSymbol = new FSymbol(getShapeType());
192
                                                        theSymbol.setDescription(clave.toString());
193
                                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
194
                                                        theSymbol.setSize(3);
195
                                                        theSymbol.setSizeInPixels(true);
196

    
197
                                                        addShape(shape, feature.getAttributeValue());
198

    
199
                                                }
200
                                        }
201
                                        index++;
202
                                }catch(GMLException e){
203
                                        logger.error(e.getMessage(),e);
204
                                }
205
                        }
206
                        ListBaseException listwarnings;
207
                        listwarnings = reader.getWarnings();
208
                }catch (GMLException e) {
209
                        logger.error(e.getMessage(),e);
210
                }
211
        }
212

    
213

    
214
        /*
215
         *  (non-Javadoc)
216
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
217
         */
218
        public boolean accept(File f) {
219
                if ((f.getName().toUpperCase().endsWith("GML")) ||
220
                                (f.getName().toUpperCase().endsWith("XML"))){
221
                        return true;
222
                }
223
                return false;
224

    
225
        }
226

    
227
        /*
228
         *  (non-Javadoc)
229
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFile()
230
         */
231
        public File getFile() {
232
                return m_Fich;
233
        }
234

    
235
        /*
236
         *  (non-Javadoc)
237
         * @see com.hardcode.driverManager.Driver#getName()
238
         */
239
        public String getName() {
240
                return "gvSIG GML Memory Driver";
241
        }
242

    
243
        /*
244
         *  (non-Javadoc)
245
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
246
         */
247
        public int getShapeType() {
248
                return FShape.MULTI;
249
        }
250

    
251
        /**
252
         * @return Returns the hashRelate.
253
         */
254
        public Hashtable getHashRelate() {
255
                return hashRelate;
256
        }
257

    
258
        /**
259
         * @return Returns the features.
260
         */
261
        public ArrayList getFeatures() {
262
                return features;
263
        }
264

    
265
        /**
266
         * @return Returns the iterator.
267
         */
268
        public IGMLFeaturesIterator getIterator() {
269
                return iterator;
270
        }
271

    
272
        /**
273
         * Gets the attributes list
274
         * @return
275
         */
276
        public String getAttributeName(int position){
277
                if (features.size() > 0){
278
                        return ((String)((FeatureWithAttributes)features.get(0)).getAttributeName()[position]);
279
                }
280
                return null;
281
        }
282

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

    
294
        /**
295
         * Gets the attributes size
296
         * @return
297
         */
298
        public int getAttributeCount(){
299
                if (features.size() > 0){
300
                        return ((FeatureWithAttributes)features.get(0)).getAttributeValue().length;
301
                }
302
                return 0;
303
        }
304
}