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