Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / gml / GMLDriver.java @ 7717

History | View | Annotate | Download (8.03 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.io.IOException;
7
import java.util.ArrayList;
8
import java.util.Hashtable;
9

    
10
import org.apache.log4j.Logger;
11
import org.cresques.cts.ICoordTrans;
12
import org.cresques.cts.IProjection;
13
import org.cresques.cts.ProjectionPool;
14
import org.gvsig.remoteClient.gml.GMLException;
15
import org.gvsig.remoteClient.gml.GMLReader;
16
import org.gvsig.remoteClient.gml.IGMLFeaturesIterator;
17
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory;
18

    
19
import com.hardcode.gdbms.engine.values.IntValue;
20
import com.hardcode.gdbms.engine.values.Value;
21
import com.hardcode.gdbms.engine.values.ValueFactory;
22
import com.iver.cit.gvsig.fmap.core.FShape;
23
import com.iver.cit.gvsig.fmap.core.IGeometry;
24
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
25
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
26
import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver;
27
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
28
import com.iver.cit.gvsig.fmap.drivers.gml.FMAPGeometryFactory.FeatureWithAttributes;
29
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
30
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
31

    
32
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
33
 *
34
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
35
 *
36
 * This program is free software; you can redistribute it and/or
37
 * modify it under the terms of the GNU General Public License
38
 * as published by the Free Software Foundation; either version 2
39
 * of the License, or (at your option) any later version.
40
 *
41
 * This program is distributed in the hope that it will be useful,
42
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44
 * GNU General Public License for more details.
45
 *
46
 * You should have received a copy of the GNU General Public License
47
 * along with this program; if not, write to the Free Software
48
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
49
 *
50
 * For more information, contact:
51
 *
52
 *  Generalitat Valenciana
53
 *   Conselleria d'Infraestructures i Transport
54
 *   Av. Blasco Ib??ez, 50
55
 *   46010 VALENCIA
56
 *   SPAIN
57
 *
58
 *      +34 963862235
59
 *   gvsig@gva.es
60
 *      www.gvsig.gva.es
61
 *
62
 *    or
63
 *
64
 *   IVER T.I. S.A
65
 *   Salamanca 50
66
 *   46005 Valencia
67
 *   Spain
68
 *
69
 *   +34 963163400
70
 *   dac@iver.es
71
 */
72
/* CVS MESSAGES:
73
 *
74
 * $Id: GMLDriver.java 7717 2006-10-02 08:41:23Z jorpiell $
75
 * $Log$
76
 * Revision 1.5  2006-10-02 08:41:23  jorpiell
77
 * Actualizados los drivers de GML
78
 *
79
 * Revision 1.2.4.2  2006/09/28 08:53:47  jorpiell
80
 * No se tiene en cuanta la reproyecci?n
81
 *
82
 * Revision 1.2.4.1  2006/09/19 12:22:48  jorpiell
83
 * Ya no se depende de geotools
84
 *
85
 * Revision 1.3  2006/09/18 12:09:43  jorpiell
86
 * El driver de GML ya no depende de geotools
87
 *
88
 * Revision 1.2  2006/08/10 12:03:43  jorpiell
89
 * Se usa el nuevo driver de GML de remoteServices
90
 *
91
 * Revision 1.1  2006/07/19 12:29:39  jorpiell
92
 * A?adido el driver de GML
93
 *
94
 *
95
 */
96
/**
97
 * This class implements the gvSIG GML parser using the geotools
98
 * library
99
 * 
100
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
101
 */
102
public class GMLDriver extends ConcreteMemoryDriver implements VectorialFileDriver{
103
        private static Logger logger = Logger.getLogger(GMLDriver.class.getName());
104
        private File m_Fich;
105
        private VectorialUniqueValueLegend defaultLegend;
106
        private IGeometriesFactory factory = new FMAPGeometryFactory();
107
        private Hashtable hashRelate = new Hashtable();
108
        private ArrayList features = new ArrayList();
109
        private IGMLFeaturesIterator iterator = null;
110
        
111
        /*
112
         *  (non-Javadoc)
113
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
114
         */
115
        public void open(File f) throws IOException {
116
                m_Fich = f;
117
        }
118
        
119
        /*
120
         *  (non-Javadoc)
121
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
122
         */
123
        public void close() throws IOException {
124
                // TODO Auto-generated method stub
125
                
126
        }
127
        
128
        /*
129
         *  (non-Javadoc)
130
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
131
         */
132
        public void initialize() throws IOException {
133
                float heightText = 10;
134
                
135
                try {
136
                        GMLReader reader = new GMLReader(m_Fich,factory);
137
                        iterator = reader.getFeaturesIterator();
138
                } catch (Exception e1) {
139
                        e1.printStackTrace();
140
                        throw new IOException(e1.toString());
141
                }
142
                
143
                
144
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
145
                defaultLegend.setFieldName("Color");
146
                defaultLegend.setLabelField("Text");
147
                defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
148
                defaultLegend.getDefaultSymbol().setShapeVisible(false);
149
                defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
150
                defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif",
151
                                Font.PLAIN, 9));
152
                defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
153
                defaultLegend.getDefaultSymbol().setFontSize(heightText);
154
                defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
155
                defaultLegend.getDefaultSymbol().setSize(3);
156
                defaultLegend.getDefaultSymbol().setSizeInPixels(true);
157
                
158
                defaultLegend.setLabelHeightField("HeightText");
159
                defaultLegend.setLabelRotationField("RotationText");
160
                
161
                int index = 0;                
162
                
163
                IntValue clave;
164
                FSymbol theSymbol = null;
165
                                        
166
                boolean setModel = false;        
167
                FeatureWithAttributes feature;
168
                try {
169
                        while (iterator.hasNext()) {                                                
170
                                try{        
171
                                        feature = (FeatureWithAttributes)iterator.next();
172
                                        hashRelate.put(feature.getFeature().getID(), new Integer(index));
173
                                        features.add(feature);
174
                                        
175
                                        if (!setModel){
176
                                                getTableModel().setColumnIdentifiers(feature.getAttributeName().toArray());
177
                                        }
178
                                        
179
                                        clave = ValueFactory.createValue(index);
180
                                        IGeometry geom = feature.getFeature().getGeometry();
181
                                        if (geom != null){        
182
                                                FShape shape = (FShape)geom.getInternalShape();                                
183
                                                
184
                                                theSymbol = new FSymbol(getShapeType());
185
                                                theSymbol.setDescription(clave.toString());
186
                                                theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
187
                                                theSymbol.setSize(3);
188
                                                theSymbol.setSizeInPixels(true);                                                
189
                                                
190
                                                addShape(shape, feature.getAttributeValue());
191
                                                defaultLegend.addSymbol(clave, theSymbol);        
192
                                        }                                        
193
                                        index++;                                
194
                                }catch(GMLException e){
195
                                        logger.error(e.getMessage(),e);
196
                                }catch(Exception e){
197
                                        logger.error(e.getMessage(),e);
198
                                }
199
                                
200
                        }
201
                } catch (GMLException e) {
202
                        logger.error(e.getMessage(),e);
203
                }         
204
                
205
        }
206
        
207
        
208
        /*
209
         *  (non-Javadoc)
210
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
211
         */
212
        public boolean accept(File f) {
213
                if ((f.getName().toUpperCase().endsWith("GML")) ||
214
                                (f.getName().toUpperCase().endsWith("XML"))){
215
                        return true;
216
                }
217
                return false;
218
                
219
        }
220
        
221
        /*
222
         *  (non-Javadoc)
223
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFile()
224
         */
225
        public File getFile() {
226
                return m_Fich;
227
        }
228
        
229
        /*
230
         *  (non-Javadoc)
231
         * @see com.hardcode.driverManager.Driver#getName()
232
         */
233
        public String getName() {
234
                return "gvSIG GML Memory Driver";
235
        }
236
        
237
        /*
238
         *  (non-Javadoc)
239
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
240
         */
241
        public int getShapeType() {
242
                return FShape.MULTI;
243
        }
244

    
245
        /**
246
         * @return Returns the hashRelate.
247
         */
248
        public Hashtable getHashRelate() {
249
                return hashRelate;
250
        }
251
        
252
        /**
253
         * @return Returns the features.
254
         */
255
        public ArrayList getFeatures() {
256
                return features;
257
        }
258

    
259
        /**
260
         * @return Returns the iterator.
261
         */
262
        public IGMLFeaturesIterator getIterator() {
263
                return iterator;
264
        }        
265

    
266
        /**
267
         * Gets the attributes list
268
         * @return
269
         */
270
        public String getAttributeName(int position){
271
                if (features.size() > 0){
272
                        return ((String)((FeatureWithAttributes)features.get(0)).getAttributeName().get(position));
273
                }
274
                return null;
275
        }
276
        
277
        /**
278
         * Gets the attributes list
279
         * @return
280
         */
281
        public Value getAttributeValue(int position){
282
                if (features.size() > 0){
283
                        return ((Value)((FeatureWithAttributes)features.get(0)).getAttributeValue()[position]);
284
                }
285
                return null;
286
        }
287
        
288
        /**
289
         * Gets the attributes size
290
         * @return
291
         */
292
        public int getAttributeCount(){
293
                if (features.size() > 0){
294
                        return ((FeatureWithAttributes)features.get(0)).getAttributeValue().length;
295
                }
296
                return 0;
297
        }
298
}