Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / gml / GMLTypesConversor.java @ 6458

History | View | Annotate | Download (7.62 KB)

1
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
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
21
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
22
import com.vividsolutions.jts.geom.Geometry;
23
import com.vividsolutions.jts.geom.GeometryCollection;
24
import com.vividsolutions.jts.geom.LineString;
25
import com.vividsolutions.jts.geom.MultiLineString;
26
import com.vividsolutions.jts.geom.MultiPoint;
27
import com.vividsolutions.jts.geom.MultiPolygon;
28
import com.vividsolutions.jts.geom.Point;
29
import com.vividsolutions.jts.geom.Polygon;
30
import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence.Float;
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: GMLTypesConversor.java 6433 2006-07-19 12:30:09Z jorpiell $
75
 * $Log$
76
 * Revision 1.1  2006-07-19 12:29:39  jorpiell
77
 * A?adido el driver de GML
78
 *
79
 *
80
 */
81
/**
82
 * Types conversor from GML to gvSIG
83
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
84
 */
85
public class GMLTypesConversor {
86

    
87
         /**
88
          * Make a conversion between the gvSIG LayerDefinition and a geotools
89
          * FeatureType.
90
          * @param schema
91
          * gvSIG feature schema that contains a list of attributes
92
          * @return
93
         * @throws SchemaException 
94
         * @throws  
95
          */
96
         public static FeatureType featureTypefromGvSIGToGeotools(LayerDefinition lyrDef) throws Exception{
97
                 FieldDescription[] fDescription = lyrDef.getFieldsDesc();
98
                 AttributeType[] types = new AttributeType[fDescription.length];
99
                 for(int i=0 ; i<fDescription.length ; i++){
100
                         types[i] = attributteTypefromGvSIGToGeotools(fDescription[i]);
101
                 }
102
                 String typeName = lyrDef.getName();
103
                 FeatureType featureType = FeatureTypeBuilder.newFeatureType(types,typeName);                                        
104
                 return featureType;
105
         }         
106
         
107
         
108
        /**
109
         * Make a conversion between the gvSIG FieldDescription and a geotools
110
         * AttributeType.
111
         * @param fDescription
112
         * gvSIG field description
113
         * @return
114
         */
115
         private static AttributeType attributteTypefromGvSIGToGeotools(FieldDescription fDescrition){
116
                 AttributeType type = AttributeTypeFactory.newAttributeType(fDescrition.getFieldName(),
117
                                 typesFromgvSIGtoGeotools(fDescrition.getFieldType()));
118
                 
119
                 return type;
120
         }        
121
         
122
         
123
         /**
124
          * Type conversor from gvSIG types to geotools types
125
          * @param type
126
          * @return
127
          */
128
         private static Class typesFromgvSIGtoGeotools(int type){
129
                 switch (type) {
130
         case Types.SMALLINT:
131
                 return Integer.class;
132
         case Types.BIT:
133
                 return Boolean.class;
134
         case Types.BOOLEAN:
135
                 return Boolean.class;
136
         case Types.VARCHAR:
137
                 return String.class;
138
         case Types.DOUBLE:
139
                 return Double.class;
140
         case Types.INTEGER:
141
                 return Integer.class;
142
         default:
143
                 return String.class;        
144
                 }
145
         } 
146
         
147
         public static String gvSIGToSchemaTypesConversion(int type){
148
                 switch (type) {
149
                 case Types.BIT:
150
                         return "xs:boolean";
151
                 case Types.TINYINT:
152
                         return "xs:integer";
153
                 case Types.SMALLINT:
154
                         return "xs:integer";
155
                 case Types.INTEGER:
156
                         return "xs:double";
157
                 case Types.BIGINT: 
158
                         return "xs:integer";
159
                 case Types.FLOAT:
160
                         return "xs:float";
161
                 case Types.REAL:
162
                         return "xs:double";
163
                 case Types.DOUBLE:
164
                         return "xs:double";
165
                 case Types.NUMERIC:
166
                         return "xs:integer";
167
                 case Types.DECIMAL:
168
                         return "xs:float";
169
                 case Types.CHAR:
170
                         return "xs:string";
171
                 case Types.VARCHAR:
172
                         return "xs:string";
173
                 case Types.LONGVARCHAR: 
174
                         return "xs:string";
175
                 case Types.DATE:
176
                         return "xs:string";
177
                 case Types.TIME:
178
                         return "xs:string";
179
                 case Types.TIMESTAMP:
180
                         return "xs:string";
181
                 case Types.BINARY:
182
                         return "xs:boolean";
183
                 case Types.VARBINARY:
184
                         return "xs:string";
185
                 case Types.LONGVARBINARY:
186
                         return "xs:string";
187
                 case Types.NULL:
188
                         return "xs:string";
189
                 case Types.OTHER:
190
                         return "xs:string";
191
                 case Types.BOOLEAN:
192
                         return "xs:boolean";
193
         default:
194
                 return "xs:string";        
195
                 }
196
         }
197
         
198
         public static String gvSIGToSchemaShapeTypesConversion(int type){
199
                 switch (type) {
200
         case FShape.LINE:
201
                 return "gml:MultiLineStringPropertyType";
202
         case FShape.POINT:
203
                    return "gml:MultiPointPropertyType";
204
         case FShape.POLYGON:
205
                 return "gml:MultiPolygonPropertyType";                 
206
         default:
207
                 return "gml:GeometryPropertyType";        
208
                 }                
209
         }
210
         
211
         /**
212
                 * 
213
                 * @author jorpiell
214
                 *
215
                 */
216
                public static class GmlToJavaConversion{
217
                        private static Hashtable typeMap = new Hashtable();
218

    
219
                    static {
220
                        typeMap.put("STRING", String.class);
221
                        typeMap.put("\"\"", String.class);
222
                        typeMap.put("INTEGER", Integer.class);
223
                        typeMap.put("INT", Integer.class);
224
                        typeMap.put("0", Integer.class);
225
                        typeMap.put("DOUBLE", Double.class);
226
                        typeMap.put("0.0", Double.class);
227
                        typeMap.put("FLOAT", Float.class);
228
                        typeMap.put("0.0F", Float.class);
229
                        typeMap.put("GEOMETRY", Geometry.class);
230
                        typeMap.put("GEOMETRYPROPERTYTYPE", Geometry.class);
231
                        typeMap.put("POINT", Point.class);
232
                        typeMap.put("POINTPROPERTYTYPE", Point.class);
233
                        typeMap.put("LINESTRING", LineString.class);
234
                        typeMap.put("LINESTRINGPROPERTYTYPE", LineString.class);
235
                        typeMap.put("POLYGON", Polygon.class);
236
                        typeMap.put("POLYGONPROPERTYTYPE", Polygon.class);
237
                        typeMap.put("MULTIPOINT", MultiPoint.class);
238
                        typeMap.put("MULTIPOINTPROPERTYTYPE", MultiPoint.class);
239
                        typeMap.put("MULTILINESTRING", MultiLineString.class);
240
                        typeMap.put("MULTILINESTRINGPROPERTYTYPE", MultiLineString.class);
241
                        typeMap.put("MULTIPOLYGON", MultiPolygon.class);
242
                        typeMap.put("MULTIPOLYGONPROPERTYTYPE", MultiPolygon.class);
243
                        typeMap.put("MULTIGEOMETRYPROPERTYTYPE", GeometryCollection.class);
244
                        typeMap.put("GEOMETRYCOLLECTION", GeometryCollection.class);
245
                        typeMap.put("GEOMETRYASSOCIATIONTYPE", Geometry.class);
246
                    }
247
                        
248
                        public static Class get(String key){
249
                                return (Class)typeMap.get(key.toUpperCase());
250
                        }
251
                }        
252
}