root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / gml / GMLTypesConversor.java @ 6507
History | View | Annotate | Download (9.04 KB)
1 | 6433 | jorpiell | package com.iver.cit.gvsig.fmap.drivers.gml; |
---|---|---|---|
2 | |||
3 | import java.sql.SQLException; |
||
4 | import java.sql.Time; |
||
5 | import java.sql.Timestamp; |
||
6 | import java.sql.Types; |
||
7 | import java.util.Date; |
||
8 | import java.util.Hashtable; |
||
9 | |||
10 | import org.geotools.factory.FactoryConfigurationError; |
||
11 | import org.geotools.feature.AttributeType; |
||
12 | import org.geotools.feature.AttributeTypeFactory; |
||
13 | import org.geotools.feature.FeatureType; |
||
14 | import org.geotools.feature.FeatureTypeBuilder; |
||
15 | import org.geotools.feature.SchemaException; |
||
16 | |||
17 | import com.hardcode.gdbms.engine.values.ValueFactory; |
||
18 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
19 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
20 | 6507 | jorpiell | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
21 | 6433 | jorpiell | import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
22 | import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
||
23 | import com.vividsolutions.jts.geom.Geometry; |
||
24 | import com.vividsolutions.jts.geom.GeometryCollection; |
||
25 | import com.vividsolutions.jts.geom.LineString; |
||
26 | import com.vividsolutions.jts.geom.MultiLineString; |
||
27 | import com.vividsolutions.jts.geom.MultiPoint; |
||
28 | import com.vividsolutions.jts.geom.MultiPolygon; |
||
29 | import com.vividsolutions.jts.geom.Point; |
||
30 | import com.vividsolutions.jts.geom.Polygon; |
||
31 | import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence.Float; |
||
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$
|
||
76 | * $Log$
|
||
77 | 6507 | jorpiell | * Revision 1.3 2006-07-24 07:36:40 jorpiell
|
78 | * 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 | if (gmlType.toUpperCase().compareTo("DOUBLE") == 0){ |
||
249 | return Double.class; |
||
250 | } |
||
251 | if (gmlType.toUpperCase().compareTo("FLOAT") == 0){ |
||
252 | return Float.class; |
||
253 | } |
||
254 | if (gmlType.toUpperCase().compareTo("GEOMETRY") == 0){ |
||
255 | return Geometry.class;
|
||
256 | } |
||
257 | if (gmlType.toUpperCase().compareTo("GEOMETRYPROPERTYTYPE") == 0){ |
||
258 | return Geometry.class;
|
||
259 | } |
||
260 | if (gmlType.toUpperCase().compareTo("POINT") == 0){ |
||
261 | return Point.class; |
||
262 | } |
||
263 | if (gmlType.toUpperCase().compareTo("POINTPROPERTYTYPE") == 0){ |
||
264 | return Point.class; |
||
265 | } |
||
266 | if (gmlType.toUpperCase().compareTo("LINESTRING") == 0){ |
||
267 | return LineString.class;
|
||
268 | } |
||
269 | if (gmlType.toUpperCase().compareTo("LINESTRINGPROPERTYTYPE") == 0){ |
||
270 | return LineString.class;
|
||
271 | } |
||
272 | if (gmlType.toUpperCase().compareTo("POLYGON") == 0){ |
||
273 | return Polygon.class; |
||
274 | } |
||
275 | if (gmlType.toUpperCase().compareTo("POLYGONPROPERTYTYPE") == 0){ |
||
276 | return Polygon.class; |
||
277 | } |
||
278 | if (gmlType.toUpperCase().compareTo("MULTIPOINT") == 0){ |
||
279 | return MultiPoint.class;
|
||
280 | } |
||
281 | if (gmlType.toUpperCase().compareTo("MULTIPOINTPROPERTYTYPE") == 0){ |
||
282 | return MultiPoint.class;
|
||
283 | } |
||
284 | if (gmlType.toUpperCase().compareTo("MULTILINESTRING") == 0){ |
||
285 | return MultiLineString.class;
|
||
286 | } |
||
287 | if (gmlType.toUpperCase().compareTo("MULTILINESTRINGPROPERTYTYPE") == 0){ |
||
288 | return MultiLineString.class;
|
||
289 | } |
||
290 | if (gmlType.toUpperCase().compareTo("MULTIPOLYGON") == 0){ |
||
291 | return MultiPolygon.class;
|
||
292 | } |
||
293 | if (gmlType.toUpperCase().compareTo("MULTIPOLYGONPROPERTYTYPE") == 0){ |
||
294 | return MultiPolygon.class;
|
||
295 | } |
||
296 | if (gmlType.toUpperCase().compareTo("MULTIGEOMETRYPROPERTYTYPE") == 0){ |
||
297 | return GeometryCollection.class;
|
||
298 | } |
||
299 | if (gmlType.toUpperCase().compareTo("GEOMETRYCOLLECTION") == 0){ |
||
300 | return GeometryCollection.class;
|
||
301 | } |
||
302 | if (gmlType.toUpperCase().compareTo("GEOMETRYASSOCIATIONTYPE") == 0){ |
||
303 | return Geometry.class;
|
||
304 | } |
||
305 | return String.class; |
||
306 | } |
||
307 | |||
308 | /**
|
||
309 | * From Java to gvSIG types
|
||
310 | * @param type
|
||
311 | * @return
|
||
312 | */
|
||
313 | public static int javaToGvSIGTypes(Class type){ |
||
314 | if (type == String.class){ |
||
315 | return Types.VARCHAR; |
||
316 | } |
||
317 | if (type == Integer.class){ |
||
318 | return Types.INTEGER; |
||
319 | } |
||
320 | if (type == Double.class){ |
||
321 | return Types.DOUBLE; |
||
322 | } |
||
323 | if (type == Double.class){ |
||
324 | return Types.FLOAT; |
||
325 | } |
||
326 | return Types.VARCHAR; |
||
327 | |||
328 | } |
||
329 | 6433 | jorpiell | } |