svn-gvsig-desktop / tags / v10_RC2c / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / gml / GMLTypesConversor.java @ 8745
History | View | Annotate | Download (9.78 KB)
1 | 6433 | jorpiell | package com.iver.cit.gvsig.fmap.drivers.gml; |
---|---|---|---|
2 | |||
3 | import java.sql.Types; |
||
4 | |||
5 | 7355 | jorpiell | import org.exolab.castor.xml.schema.SchemaException; |
6 | 6433 | jorpiell | import org.geotools.feature.AttributeType; |
7 | import org.geotools.feature.AttributeTypeFactory; |
||
8 | import org.geotools.feature.FeatureType; |
||
9 | import org.geotools.feature.FeatureTypeBuilder; |
||
10 | |||
11 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
12 | import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
||
13 | import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
||
14 | import com.vividsolutions.jts.geom.Geometry; |
||
15 | import com.vividsolutions.jts.geom.GeometryCollection; |
||
16 | import com.vividsolutions.jts.geom.LineString; |
||
17 | import com.vividsolutions.jts.geom.MultiLineString; |
||
18 | import com.vividsolutions.jts.geom.MultiPoint; |
||
19 | import com.vividsolutions.jts.geom.MultiPolygon; |
||
20 | import com.vividsolutions.jts.geom.Point; |
||
21 | import com.vividsolutions.jts.geom.Polygon; |
||
22 | import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence.Float; |
||
23 | |||
24 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
25 | *
|
||
26 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
27 | *
|
||
28 | * This program is free software; you can redistribute it and/or
|
||
29 | * modify it under the terms of the GNU General Public License
|
||
30 | * as published by the Free Software Foundation; either version 2
|
||
31 | * of the License, or (at your option) any later version.
|
||
32 | *
|
||
33 | * This program is distributed in the hope that it will be useful,
|
||
34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
36 | * GNU General Public License for more details.
|
||
37 | *
|
||
38 | * You should have received a copy of the GNU General Public License
|
||
39 | * along with this program; if not, write to the Free Software
|
||
40 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
41 | *
|
||
42 | * For more information, contact:
|
||
43 | *
|
||
44 | * Generalitat Valenciana
|
||
45 | * Conselleria d'Infraestructures i Transport
|
||
46 | * Av. Blasco Ib??ez, 50
|
||
47 | * 46010 VALENCIA
|
||
48 | * SPAIN
|
||
49 | *
|
||
50 | * +34 963862235
|
||
51 | * gvsig@gva.es
|
||
52 | * www.gvsig.gva.es
|
||
53 | *
|
||
54 | * or
|
||
55 | *
|
||
56 | * IVER T.I. S.A
|
||
57 | * Salamanca 50
|
||
58 | * 46005 Valencia
|
||
59 | * Spain
|
||
60 | *
|
||
61 | * +34 963163400
|
||
62 | * dac@iver.es
|
||
63 | */
|
||
64 | /* CVS MESSAGES:
|
||
65 | *
|
||
66 | * $Id$
|
||
67 | * $Log$
|
||
68 | 7355 | jorpiell | * Revision 1.4.4.1 2006-09-19 12:22:48 jorpiell
|
69 | * Ya no se depende de geotools
|
||
70 | *
|
||
71 | * Revision 1.5 2006/09/18 12:09:43 jorpiell
|
||
72 | * El driver de GML ya no depende de geotools
|
||
73 | *
|
||
74 | * Revision 1.4 2006/07/24 08:28:09 jorpiell
|
||
75 | 6509 | jorpiell | * A?adidos algunos tipos de datos en la conversi?n de java a gvSIG
|
76 | *
|
||
77 | * Revision 1.3 2006/07/24 07:36:40 jorpiell
|
||
78 | 6507 | jorpiell | * Se han hecho un cambio en los nombres de los metodos para clarificar
|
79 | *
|
||
80 | * Revision 1.2 2006/07/21 08:57:28 jorpiell
|
||
81 | 6485 | jorpiell | * Se ha a?adido la exportaci?n de capas de puntos
|
82 | *
|
||
83 | * Revision 1.1 2006/07/19 12:29:39 jorpiell
|
||
84 | 6433 | jorpiell | * A?adido el driver de GML
|
85 | *
|
||
86 | *
|
||
87 | */
|
||
88 | /**
|
||
89 | * Types conversor from GML to gvSIG
|
||
90 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
91 | */
|
||
92 | public class GMLTypesConversor { |
||
93 | |||
94 | /**
|
||
95 | * Make a conversion between the gvSIG LayerDefinition and a geotools
|
||
96 | * FeatureType.
|
||
97 | * @param schema
|
||
98 | * gvSIG feature schema that contains a list of attributes
|
||
99 | * @return
|
||
100 | * @throws SchemaException
|
||
101 | * @throws
|
||
102 | */
|
||
103 | public static FeatureType featureTypefromGvSIGToGeotools(LayerDefinition lyrDef) throws Exception{ |
||
104 | FieldDescription[] fDescription = lyrDef.getFieldsDesc();
|
||
105 | AttributeType[] types = new AttributeType[fDescription.length]; |
||
106 | for(int i=0 ; i<fDescription.length ; i++){ |
||
107 | types[i] = attributteTypefromGvSIGToGeotools(fDescription[i]); |
||
108 | } |
||
109 | String typeName = lyrDef.getName();
|
||
110 | FeatureType featureType = FeatureTypeBuilder.newFeatureType(types,typeName); |
||
111 | return featureType;
|
||
112 | } |
||
113 | |||
114 | |||
115 | /**
|
||
116 | * Make a conversion between the gvSIG FieldDescription and a geotools
|
||
117 | * AttributeType.
|
||
118 | * @param fDescription
|
||
119 | * gvSIG field description
|
||
120 | * @return
|
||
121 | */
|
||
122 | private static AttributeType attributteTypefromGvSIGToGeotools(FieldDescription fDescrition){ |
||
123 | AttributeType type = AttributeTypeFactory.newAttributeType(fDescrition.getFieldName(), |
||
124 | typesFromgvSIGtoGeotools(fDescrition.getFieldType())); |
||
125 | |||
126 | return type;
|
||
127 | } |
||
128 | |||
129 | |||
130 | /**
|
||
131 | * Type conversor from gvSIG types to geotools types
|
||
132 | * @param type
|
||
133 | * @return
|
||
134 | */
|
||
135 | private static Class typesFromgvSIGtoGeotools(int type){ |
||
136 | switch (type) {
|
||
137 | case Types.SMALLINT: |
||
138 | return Integer.class; |
||
139 | case Types.BIT: |
||
140 | return Boolean.class; |
||
141 | case Types.BOOLEAN: |
||
142 | return Boolean.class; |
||
143 | case Types.VARCHAR: |
||
144 | return String.class; |
||
145 | case Types.DOUBLE: |
||
146 | return Double.class; |
||
147 | case Types.INTEGER: |
||
148 | return Integer.class; |
||
149 | default:
|
||
150 | return String.class; |
||
151 | } |
||
152 | } |
||
153 | |||
154 | 6507 | jorpiell | /**
|
155 | * From gvSIG types to xlink types used in GML
|
||
156 | * @param gmlType
|
||
157 | * @return
|
||
158 | */
|
||
159 | public static String gvSIGToXlinkTypes(int type){ |
||
160 | 6433 | jorpiell | switch (type) {
|
161 | case Types.BIT: |
||
162 | return "xs:boolean"; |
||
163 | case Types.TINYINT: |
||
164 | return "xs:integer"; |
||
165 | case Types.SMALLINT: |
||
166 | return "xs:integer"; |
||
167 | case Types.INTEGER: |
||
168 | return "xs:double"; |
||
169 | case Types.BIGINT: |
||
170 | return "xs:integer"; |
||
171 | case Types.FLOAT: |
||
172 | return "xs:float"; |
||
173 | case Types.REAL: |
||
174 | return "xs:double"; |
||
175 | case Types.DOUBLE: |
||
176 | return "xs:double"; |
||
177 | case Types.NUMERIC: |
||
178 | return "xs:integer"; |
||
179 | case Types.DECIMAL: |
||
180 | return "xs:float"; |
||
181 | case Types.CHAR: |
||
182 | return "xs:string"; |
||
183 | case Types.VARCHAR: |
||
184 | return "xs:string"; |
||
185 | case Types.LONGVARCHAR: |
||
186 | return "xs:string"; |
||
187 | case Types.DATE: |
||
188 | return "xs:string"; |
||
189 | case Types.TIME: |
||
190 | return "xs:string"; |
||
191 | case Types.TIMESTAMP: |
||
192 | return "xs:string"; |
||
193 | case Types.BINARY: |
||
194 | return "xs:boolean"; |
||
195 | case Types.VARBINARY: |
||
196 | return "xs:string"; |
||
197 | case Types.LONGVARBINARY: |
||
198 | return "xs:string"; |
||
199 | case Types.NULL: |
||
200 | return "xs:string"; |
||
201 | case Types.OTHER: |
||
202 | return "xs:string"; |
||
203 | case Types.BOOLEAN: |
||
204 | return "xs:boolean"; |
||
205 | default:
|
||
206 | return "xs:string"; |
||
207 | } |
||
208 | } |
||
209 | |||
210 | 6507 | jorpiell | /**
|
211 | * From gvSIG to GML types
|
||
212 | * @param gmlType
|
||
213 | * @return
|
||
214 | */
|
||
215 | public static String gvSIGToGMLTypes(int type){ |
||
216 | 6433 | jorpiell | switch (type) {
|
217 | case FShape.LINE:
|
||
218 | return "gml:MultiLineStringPropertyType"; |
||
219 | case FShape.POINT:
|
||
220 | 6485 | jorpiell | return "gml:PointPropertyType"; |
221 | case FShape.MULTIPOINT:
|
||
222 | return "gml:MultiPointPropertyType"; |
||
223 | 6433 | jorpiell | case FShape.POLYGON:
|
224 | 6485 | jorpiell | return "gml:MultiPolygonPropertyType"; |
225 | 6433 | jorpiell | default:
|
226 | return "gml:GeometryPropertyType"; |
||
227 | } |
||
228 | } |
||
229 | |||
230 | 6507 | jorpiell | /**
|
231 | * From GML to Java types
|
||
232 | * @param gmlType
|
||
233 | * @return
|
||
234 | */
|
||
235 | public static Class gmlToJavaTypes(String gmlType){ |
||
236 | if (gmlType.toUpperCase().compareTo("STRING") == 0){ |
||
237 | return String.class; |
||
238 | } |
||
239 | if (gmlType.toUpperCase().compareTo("\"\"") == 0){ |
||
240 | return String.class; |
||
241 | } |
||
242 | if (gmlType.toUpperCase().compareTo("INTEGER") == 0){ |
||
243 | return Integer.class; |
||
244 | } |
||
245 | if (gmlType.toUpperCase().compareTo("INT") == 0){ |
||
246 | return Integer.class; |
||
247 | } |
||
248 | 6509 | jorpiell | if (gmlType.toUpperCase().compareTo("LONG") == 0){ |
249 | return Long.class; |
||
250 | } |
||
251 | 6507 | jorpiell | if (gmlType.toUpperCase().compareTo("DOUBLE") == 0){ |
252 | return Double.class; |
||
253 | } |
||
254 | if (gmlType.toUpperCase().compareTo("FLOAT") == 0){ |
||
255 | return Float.class; |
||
256 | } |
||
257 | if (gmlType.toUpperCase().compareTo("GEOMETRY") == 0){ |
||
258 | return Geometry.class;
|
||
259 | } |
||
260 | if (gmlType.toUpperCase().compareTo("GEOMETRYPROPERTYTYPE") == 0){ |
||
261 | return Geometry.class;
|
||
262 | } |
||
263 | if (gmlType.toUpperCase().compareTo("POINT") == 0){ |
||
264 | return Point.class; |
||
265 | } |
||
266 | if (gmlType.toUpperCase().compareTo("POINTPROPERTYTYPE") == 0){ |
||
267 | return Point.class; |
||
268 | } |
||
269 | if (gmlType.toUpperCase().compareTo("LINESTRING") == 0){ |
||
270 | return LineString.class;
|
||
271 | } |
||
272 | if (gmlType.toUpperCase().compareTo("LINESTRINGPROPERTYTYPE") == 0){ |
||
273 | return LineString.class;
|
||
274 | } |
||
275 | if (gmlType.toUpperCase().compareTo("POLYGON") == 0){ |
||
276 | return Polygon.class; |
||
277 | } |
||
278 | if (gmlType.toUpperCase().compareTo("POLYGONPROPERTYTYPE") == 0){ |
||
279 | return Polygon.class; |
||
280 | } |
||
281 | if (gmlType.toUpperCase().compareTo("MULTIPOINT") == 0){ |
||
282 | return MultiPoint.class;
|
||
283 | } |
||
284 | if (gmlType.toUpperCase().compareTo("MULTIPOINTPROPERTYTYPE") == 0){ |
||
285 | return MultiPoint.class;
|
||
286 | } |
||
287 | if (gmlType.toUpperCase().compareTo("MULTILINESTRING") == 0){ |
||
288 | return MultiLineString.class;
|
||
289 | } |
||
290 | if (gmlType.toUpperCase().compareTo("MULTILINESTRINGPROPERTYTYPE") == 0){ |
||
291 | return MultiLineString.class;
|
||
292 | } |
||
293 | if (gmlType.toUpperCase().compareTo("MULTIPOLYGON") == 0){ |
||
294 | return MultiPolygon.class;
|
||
295 | } |
||
296 | if (gmlType.toUpperCase().compareTo("MULTIPOLYGONPROPERTYTYPE") == 0){ |
||
297 | return MultiPolygon.class;
|
||
298 | } |
||
299 | if (gmlType.toUpperCase().compareTo("MULTIGEOMETRYPROPERTYTYPE") == 0){ |
||
300 | return GeometryCollection.class;
|
||
301 | } |
||
302 | if (gmlType.toUpperCase().compareTo("GEOMETRYCOLLECTION") == 0){ |
||
303 | return GeometryCollection.class;
|
||
304 | } |
||
305 | if (gmlType.toUpperCase().compareTo("GEOMETRYASSOCIATIONTYPE") == 0){ |
||
306 | return Geometry.class;
|
||
307 | } |
||
308 | return String.class; |
||
309 | } |
||
310 | |||
311 | /**
|
||
312 | * From Java to gvSIG types
|
||
313 | * @param type
|
||
314 | * @return
|
||
315 | */
|
||
316 | public static int javaToGvSIGTypes(Class type){ |
||
317 | if (type == String.class){ |
||
318 | return Types.VARCHAR; |
||
319 | } |
||
320 | if (type == Integer.class){ |
||
321 | return Types.INTEGER; |
||
322 | } |
||
323 | if (type == Double.class){ |
||
324 | return Types.DOUBLE; |
||
325 | } |
||
326 | 6509 | jorpiell | if (type == Float.class){ |
327 | 6507 | jorpiell | return Types.FLOAT; |
328 | } |
||
329 | 6509 | jorpiell | if (type == Long.class){ |
330 | return Types.INTEGER; |
||
331 | } |
||
332 | 6507 | jorpiell | return Types.VARCHAR; |
333 | |||
334 | } |
||
335 | 7355 | jorpiell | |
336 | |||
337 | public static int gmlToGvSigType(String gmlType) { |
||
338 | if (gmlType.toUpperCase().compareTo("STRING") == 0){ |
||
339 | return Types.VARCHAR; |
||
340 | } |
||
341 | if (gmlType.toUpperCase().compareTo("\"\"") == 0){ |
||
342 | return Types.VARCHAR; |
||
343 | } |
||
344 | if (gmlType.toUpperCase().compareTo("INTEGER") == 0){ |
||
345 | return Types.INTEGER; |
||
346 | } |
||
347 | if (gmlType.toUpperCase().compareTo("INT") == 0){ |
||
348 | return Types.INTEGER; |
||
349 | } |
||
350 | if (gmlType.toUpperCase().compareTo("LONG") == 0){ |
||
351 | return Types.INTEGER; |
||
352 | } |
||
353 | if (gmlType.toUpperCase().compareTo("DOUBLE") == 0){ |
||
354 | return Types.DOUBLE; |
||
355 | } |
||
356 | if (gmlType.toUpperCase().compareTo("FLOAT") == 0){ |
||
357 | return Types.DOUBLE; |
||
358 | } |
||
359 | return Types.VARCHAR; |
||
360 | } |
||
361 | 6433 | jorpiell | } |