svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / gml / GMLDriver.java @ 6507
History | View | Annotate | Download (6.75 KB)
1 | 6433 | jorpiell | 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.net.URI; |
||
8 | import java.util.ArrayList; |
||
9 | import java.util.NoSuchElementException; |
||
10 | |||
11 | import org.apache.log4j.Logger; |
||
12 | import org.cresques.px.dxf.AcadColor; |
||
13 | import org.geotools.data.DefaultQuery; |
||
14 | import org.geotools.data.FeatureReader; |
||
15 | import org.geotools.data.Transaction; |
||
16 | import org.geotools.feature.AttributeType; |
||
17 | import org.geotools.feature.IllegalAttributeException; |
||
18 | |||
19 | import sun.print.PSPrinterJob.PluginPrinter; |
||
20 | |||
21 | import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
||
22 | import com.hardcode.gdbms.engine.values.IntValue; |
||
23 | import com.hardcode.gdbms.engine.values.Value; |
||
24 | import com.hardcode.gdbms.engine.values.ValueFactory; |
||
25 | import com.iver.cit.gvsig.fmap.DriverException; |
||
26 | import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
||
27 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
28 | import com.iver.cit.gvsig.fmap.core.IFeature; |
||
29 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
30 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
31 | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
||
32 | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
||
33 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
34 | import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver; |
||
35 | import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
||
36 | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
||
37 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
38 | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
||
39 | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
||
40 | |||
41 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
42 | *
|
||
43 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
44 | *
|
||
45 | * This program is free software; you can redistribute it and/or
|
||
46 | * modify it under the terms of the GNU General Public License
|
||
47 | * as published by the Free Software Foundation; either version 2
|
||
48 | * of the License, or (at your option) any later version.
|
||
49 | *
|
||
50 | * This program is distributed in the hope that it will be useful,
|
||
51 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
52 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
53 | * GNU General Public License for more details.
|
||
54 | *
|
||
55 | * You should have received a copy of the GNU General Public License
|
||
56 | * along with this program; if not, write to the Free Software
|
||
57 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
58 | *
|
||
59 | * For more information, contact:
|
||
60 | *
|
||
61 | * Generalitat Valenciana
|
||
62 | * Conselleria d'Infraestructures i Transport
|
||
63 | * Av. Blasco Ib??ez, 50
|
||
64 | * 46010 VALENCIA
|
||
65 | * SPAIN
|
||
66 | *
|
||
67 | * +34 963862235
|
||
68 | * gvsig@gva.es
|
||
69 | * www.gvsig.gva.es
|
||
70 | *
|
||
71 | * or
|
||
72 | *
|
||
73 | * IVER T.I. S.A
|
||
74 | * Salamanca 50
|
||
75 | * 46005 Valencia
|
||
76 | * Spain
|
||
77 | *
|
||
78 | * +34 963163400
|
||
79 | * dac@iver.es
|
||
80 | */
|
||
81 | /* CVS MESSAGES:
|
||
82 | *
|
||
83 | * $Id$
|
||
84 | * $Log$
|
||
85 | * Revision 1.1 2006-07-19 12:29:39 jorpiell
|
||
86 | * A?adido el driver de GML
|
||
87 | *
|
||
88 | *
|
||
89 | */
|
||
90 | /**
|
||
91 | * This class implements the gvSIG GML parser using the geotools
|
||
92 | * library
|
||
93 | *
|
||
94 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
95 | */
|
||
96 | public class GMLDriver extends ConcreteMemoryDriver implements VectorialFileDriver{ |
||
97 | private static Logger logger = Logger.getLogger(GMLDriver.class.getName()); |
||
98 | private File m_Fich; |
||
99 | private VectorialUniqueValueLegend defaultLegend;
|
||
100 | |||
101 | /*
|
||
102 | * (non-Javadoc)
|
||
103 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
|
||
104 | */
|
||
105 | public void open(File f) throws IOException { |
||
106 | m_Fich = f; |
||
107 | } |
||
108 | |||
109 | /*
|
||
110 | * (non-Javadoc)
|
||
111 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
||
112 | */
|
||
113 | public void close() throws IOException { |
||
114 | // TODO Auto-generated method stub
|
||
115 | |||
116 | } |
||
117 | |||
118 | /*
|
||
119 | * (non-Javadoc)
|
||
120 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
|
||
121 | */
|
||
122 | public void initialize() throws IOException { |
||
123 | float heightText = 10; |
||
124 | |||
125 | GMLFeaturesIterator iterator; |
||
126 | try {
|
||
127 | iterator = GMLFeaturesParser.getFeatureReader(m_Fich); |
||
128 | } catch (Exception e1) { |
||
129 | e1.printStackTrace(); |
||
130 | throw new IOException(e1.toString()); |
||
131 | } |
||
132 | |||
133 | defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
||
134 | defaultLegend.setFieldName("Color");
|
||
135 | defaultLegend.setLabelField("Text");
|
||
136 | defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
|
||
137 | defaultLegend.getDefaultSymbol().setShapeVisible(false);
|
||
138 | defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
|
||
139 | defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", |
||
140 | Font.PLAIN, 9)); |
||
141 | defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
|
||
142 | defaultLegend.getDefaultSymbol().setFontSize(heightText); |
||
143 | defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
||
144 | defaultLegend.getDefaultSymbol().setSize(3);
|
||
145 | defaultLegend.getDefaultSymbol().setSizeInPixels(true);
|
||
146 | |||
147 | defaultLegend.setLabelHeightField("HeightText");
|
||
148 | defaultLegend.setLabelRotationField("RotationText");
|
||
149 | |||
150 | ArrayList arrayFields = iterator.getAttributeNames();
|
||
151 | Value[] auxRow;
|
||
152 | if (arrayFields.size()<0){ |
||
153 | auxRow = new Value[0]; |
||
154 | }else{
|
||
155 | auxRow = new Value[arrayFields.size()];
|
||
156 | } |
||
157 | |||
158 | int i=0; |
||
159 | |||
160 | getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
||
161 | |||
162 | IntValue clave; |
||
163 | FSymbol theSymbol = null;
|
||
164 | |||
165 | while (iterator.hasNext()) {
|
||
166 | IFeature feature; |
||
167 | try {
|
||
168 | System.out.println("Recuperando feature num: " + i); |
||
169 | feature = iterator.next(); |
||
170 | |||
171 | clave = ValueFactory.createValue(i); |
||
172 | IGeometry geom = feature.getGeometry(); |
||
173 | FShape shape = (FShape)geom.getInternalShape(); |
||
174 | |||
175 | theSymbol = new FSymbol(getShapeType());
|
||
176 | theSymbol.setDescription(clave.toString()); |
||
177 | theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
||
178 | theSymbol.setSize(3);
|
||
179 | theSymbol.setSizeInPixels(true);
|
||
180 | |||
181 | for (int k=0 ; k<auxRow.length ; k++){ |
||
182 | auxRow[k] = feature.getAttribute(k); |
||
183 | } |
||
184 | |||
185 | addShape(shape, auxRow); |
||
186 | defaultLegend.addSymbol(clave, theSymbol); |
||
187 | |||
188 | i++; |
||
189 | } catch (NoSuchElementException e) { |
||
190 | // TODO Auto-generated catch block
|
||
191 | e.printStackTrace(); |
||
192 | } catch (DriverException e) {
|
||
193 | // TODO Auto-generated catch block
|
||
194 | e.printStackTrace(); |
||
195 | } |
||
196 | } |
||
197 | |||
198 | |||
199 | } |
||
200 | |||
201 | |||
202 | /*
|
||
203 | * (non-Javadoc)
|
||
204 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
|
||
205 | */
|
||
206 | public boolean accept(File f) { |
||
207 | if ((f.getName().toUpperCase().endsWith("GML")) || |
||
208 | (f.getName().toUpperCase().endsWith("XML"))){
|
||
209 | return true; |
||
210 | } |
||
211 | return false; |
||
212 | |||
213 | } |
||
214 | |||
215 | /*
|
||
216 | * (non-Javadoc)
|
||
217 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFile()
|
||
218 | */
|
||
219 | public File getFile() { |
||
220 | return m_Fich;
|
||
221 | } |
||
222 | |||
223 | /*
|
||
224 | * (non-Javadoc)
|
||
225 | * @see com.hardcode.driverManager.Driver#getName()
|
||
226 | */
|
||
227 | public String getName() { |
||
228 | return "gvSIG GML Memory Driver"; |
||
229 | } |
||
230 | |||
231 | /*
|
||
232 | * (non-Javadoc)
|
||
233 | * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
|
||
234 | */
|
||
235 | public int getShapeType() { |
||
236 | return FShape.MULTI;
|
||
237 | } |
||
238 | |||
239 | } |