svn-gvsig-desktop / branches / v10 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / gml / GMLDriver.java @ 8268
History | View | Annotate | Download (8.47 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 8268 2006-10-24 07:16:41Z jorpiell $
|
75 |
* $Log$
|
76 |
* Revision 1.2.4.3 2006-10-24 07:16:41 jorpiell
|
77 |
* La leyenda se puede escribir desde fuera. Esto es as? para que no se cree una nueva leyenda cada vez que se refresca la capa
|
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 |
if (defaultLegend == null){ |
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 |
|
162 |
int index = 0; |
163 |
|
164 |
IntValue clave; |
165 |
FSymbol theSymbol = null;
|
166 |
|
167 |
boolean setModel = false; |
168 |
FeatureWithAttributes feature; |
169 |
try {
|
170 |
while (iterator.hasNext()) {
|
171 |
try{
|
172 |
feature = (FeatureWithAttributes)iterator.next(); |
173 |
hashRelate.put(feature.getFeature().getID(), new Integer(index)); |
174 |
features.add(feature); |
175 |
|
176 |
if (!setModel){
|
177 |
getTableModel().setColumnIdentifiers(feature.getAttributeName().toArray()); |
178 |
} |
179 |
|
180 |
clave = ValueFactory.createValue(index); |
181 |
IGeometry geom = feature.getFeature().getGeometry(); |
182 |
if (geom != null){ |
183 |
FShape shape = (FShape)geom.getInternalShape(); |
184 |
|
185 |
theSymbol = new FSymbol(getShapeType());
|
186 |
theSymbol.setDescription(clave.toString()); |
187 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
188 |
theSymbol.setSize(3);
|
189 |
theSymbol.setSizeInPixels(true);
|
190 |
|
191 |
addShape(shape, feature.getAttributeValue()); |
192 |
defaultLegend.addSymbol(clave, theSymbol); |
193 |
} |
194 |
index++; |
195 |
}catch(GMLException e){
|
196 |
logger.error(e.getMessage(),e); |
197 |
}catch(Exception e){ |
198 |
logger.error(e.getMessage(),e); |
199 |
} |
200 |
|
201 |
} |
202 |
} catch (GMLException e) {
|
203 |
logger.error(e.getMessage(),e); |
204 |
} |
205 |
|
206 |
} |
207 |
|
208 |
|
209 |
/*
|
210 |
* (non-Javadoc)
|
211 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
|
212 |
*/
|
213 |
public boolean accept(File f) { |
214 |
if ((f.getName().toUpperCase().endsWith("GML")) || |
215 |
(f.getName().toUpperCase().endsWith("XML"))){
|
216 |
return true; |
217 |
} |
218 |
return false; |
219 |
|
220 |
} |
221 |
|
222 |
/*
|
223 |
* (non-Javadoc)
|
224 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFile()
|
225 |
*/
|
226 |
public File getFile() { |
227 |
return m_Fich;
|
228 |
} |
229 |
|
230 |
/*
|
231 |
* (non-Javadoc)
|
232 |
* @see com.hardcode.driverManager.Driver#getName()
|
233 |
*/
|
234 |
public String getName() { |
235 |
return "gvSIG GML Memory Driver"; |
236 |
} |
237 |
|
238 |
/*
|
239 |
* (non-Javadoc)
|
240 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
|
241 |
*/
|
242 |
public int getShapeType() { |
243 |
return FShape.MULTI;
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* @return Returns the hashRelate.
|
248 |
*/
|
249 |
public Hashtable getHashRelate() { |
250 |
return hashRelate;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* @return Returns the features.
|
255 |
*/
|
256 |
public ArrayList getFeatures() { |
257 |
return features;
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* @return Returns the iterator.
|
262 |
*/
|
263 |
public IGMLFeaturesIterator getIterator() {
|
264 |
return iterator;
|
265 |
} |
266 |
|
267 |
/**
|
268 |
* Gets the attributes list
|
269 |
* @return
|
270 |
*/
|
271 |
public String getAttributeName(int position){ |
272 |
if (features.size() > 0){ |
273 |
return ((String)((FeatureWithAttributes)features.get(0)).getAttributeName().get(position)); |
274 |
} |
275 |
return null; |
276 |
} |
277 |
|
278 |
/**
|
279 |
* Gets the attributes list
|
280 |
* @return
|
281 |
*/
|
282 |
public Value getAttributeValue(int position){ |
283 |
if (features.size() > 0){ |
284 |
return ((Value)((FeatureWithAttributes)features.get(0)).getAttributeValue()[position]); |
285 |
} |
286 |
return null; |
287 |
} |
288 |
|
289 |
/**
|
290 |
* Gets the attributes size
|
291 |
* @return
|
292 |
*/
|
293 |
public int getAttributeCount(){ |
294 |
if (features.size() > 0){ |
295 |
return ((FeatureWithAttributes)features.get(0)).getAttributeValue().length; |
296 |
} |
297 |
return 0; |
298 |
} |
299 |
|
300 |
/**
|
301 |
* Gets the defaultLegend
|
302 |
* @return
|
303 |
*/
|
304 |
public VectorialUniqueValueLegend getDefaultLegend() {
|
305 |
return defaultLegend;
|
306 |
} |
307 |
|
308 |
/**
|
309 |
* Sets the defaultLegend
|
310 |
* @return
|
311 |
*/
|
312 |
public void setDefaultLegend(VectorialUniqueValueLegend defaultLegend) { |
313 |
this.defaultLegend = defaultLegend;
|
314 |
} |
315 |
} |