svn-gvsig-desktop / tags / v1_1_Build_1013 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / fmap / XTypes.java @ 13521
History | View | Annotate | Download (7.88 KB)
1 |
/*
|
---|---|
2 |
* Created on 07-feb-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: XTypes.java 13521 2007-09-04 14:02:46Z $
|
47 |
* $Log$
|
48 |
* Revision 1.1.4.1 2007-07-12 16:54:35 azabala
|
49 |
* bug solved when try to do a one to many spatial join with layers without numeric fields
|
50 |
*
|
51 |
* Revision 1.1 2006/05/24 21:12:16 azabala
|
52 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
53 |
*
|
54 |
* Revision 1.4 2006/02/19 20:56:07 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.3 2006/02/17 16:34:00 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.2 2006/02/13 18:37:41 azabala
|
61 |
* *** empty log message ***
|
62 |
*
|
63 |
* Revision 1.1 2006/02/09 15:59:48 azabala
|
64 |
* First version in CVS
|
65 |
*
|
66 |
*
|
67 |
*/
|
68 |
package com.iver.cit.gvsig.geoprocess.core.fmap; |
69 |
|
70 |
import java.sql.Types; |
71 |
import java.util.ArrayList; |
72 |
import java.util.Date; |
73 |
|
74 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
75 |
import com.hardcode.gdbms.engine.values.DateValue; |
76 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
77 |
import com.hardcode.gdbms.engine.values.FloatValue; |
78 |
import com.hardcode.gdbms.engine.values.IntValue; |
79 |
import com.hardcode.gdbms.engine.values.LongValue; |
80 |
import com.hardcode.gdbms.engine.values.StringValue; |
81 |
import com.hardcode.gdbms.engine.values.Value; |
82 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
83 |
import com.iver.cit.gvsig.fmap.DriverException; |
84 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
85 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
86 |
|
87 |
/**
|
88 |
* This is a similar try to com.iver.cit.gvsig.jdbc_spatial.XTypes to do a Types
|
89 |
* management in GvSig
|
90 |
*
|
91 |
* @author azabala
|
92 |
*
|
93 |
*/
|
94 |
public abstract class XTypes { |
95 |
// Geometry types
|
96 |
public final static int SHAPE_NULL = 0; |
97 |
public final static int POINT = 1; |
98 |
public final static int LINE = 2; |
99 |
public final static int POLYGON = 4; |
100 |
public final static int TEXT = 8; |
101 |
public final static int MULTI = 16; |
102 |
public final static int MULTIPOINT = 32; |
103 |
public final static int CIRCLE = 64; |
104 |
public final static int ARC = 128; |
105 |
public final static int ELLIPSE = 256; |
106 |
public final static int Z = 512; |
107 |
|
108 |
public static final int BIT = Types.BIT; |
109 |
public static final int TINYINT = Types.TINYINT; |
110 |
public static final int SMALLINT = Types.SMALLINT; |
111 |
public static final int INTEGER = Types.INTEGER; |
112 |
public static final int BIGINT = Types.BIGINT; |
113 |
public static final int FLOAT = Types.FLOAT; |
114 |
public static final int REAL = Types.REAL; |
115 |
public static final int DOUBLE = Types.DOUBLE; |
116 |
public static final int NUMERIC = Types.NUMERIC; |
117 |
public static final int DECIMAL = Types.DECIMAL; |
118 |
public static final int CHAR = Types.CHAR; |
119 |
public static final int VARCHAR = Types.VARCHAR; |
120 |
public static final int LONGVARCHAR = Types.LONGVARCHAR; |
121 |
public static final int DATE = Types.DATE; |
122 |
public static final int TIME = Types.TIME; |
123 |
public static final int TIMESTAMP = Types.TIMESTAMP; |
124 |
public static final int BINARY = Types.BINARY; |
125 |
public static final int VARBINARY = Types.VARBINARY; |
126 |
public static final int LONGVARBINARY = Types.LONGVARBINARY; |
127 |
public static final int NULL = Types.NULL; |
128 |
public static final int OTHER = Types.OTHER; |
129 |
public static final int JAVA_OBJECT = Types.JAVA_OBJECT; |
130 |
public static final int DISTINCT = Types.DISTINCT; |
131 |
public static final int STRUCT = Types.STRUCT; |
132 |
public static final int ARRAY = Types.ARRAY; |
133 |
public static final int BLOB = Types.BLOB; |
134 |
public static final int CLOB = Types.CLOB; |
135 |
public static final int REF = Types.REF; |
136 |
public static final int DATALINK = Types.DATALINK; |
137 |
public static final int BOOLEAN = Types.BOOLEAN; |
138 |
|
139 |
public static boolean isNumeric(int fieldType) { |
140 |
switch (fieldType) {
|
141 |
case DOUBLE:
|
142 |
case FLOAT:
|
143 |
case INTEGER:
|
144 |
case SMALLINT:
|
145 |
case BIGINT:
|
146 |
case NUMERIC:
|
147 |
case REAL:
|
148 |
case TINYINT:
|
149 |
case DECIMAL:
|
150 |
return true; |
151 |
} |
152 |
return false; |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Convert an int data type in a text sql type. Is abstract because it will
|
157 |
* be strongly dependant of sql rdbms.
|
158 |
*
|
159 |
* @param fieldType
|
160 |
* @return
|
161 |
*/
|
162 |
public abstract String fieldTypeToString(int fieldType); |
163 |
|
164 |
|
165 |
|
166 |
public static Object getObject(Value value, int fieldType){ |
167 |
Object solution = null; |
168 |
switch (fieldType) {
|
169 |
case Types.VARCHAR: |
170 |
StringValue str = (StringValue) value; |
171 |
solution = str.getValue(); |
172 |
break;
|
173 |
case Types.FLOAT: |
174 |
FloatValue fval = (FloatValue) value; |
175 |
solution = new Float(fval.floatValue()); |
176 |
break;
|
177 |
case Types.DOUBLE: |
178 |
DoubleValue dval = (DoubleValue)value; |
179 |
solution = new Double(dval.doubleValue()); |
180 |
break;
|
181 |
case Types.INTEGER: |
182 |
IntValue intval = (IntValue)value; |
183 |
solution = new Integer(intval.intValue()); |
184 |
break;
|
185 |
case Types.BIGINT: |
186 |
LongValue lval = (LongValue) value; |
187 |
solution = new Long(lval.longValue()); |
188 |
break;
|
189 |
case Types.BIT: |
190 |
BooleanValue bval = (BooleanValue) value; |
191 |
solution = new Boolean(bval.getValue()); |
192 |
break;
|
193 |
case Types.DATE: |
194 |
DateValue dtval = (DateValue) value; |
195 |
solution = dtval.getValue(); |
196 |
break;
|
197 |
} |
198 |
return solution;
|
199 |
} |
200 |
|
201 |
/**
|
202 |
* Returns a Value from its data type (fieldType) and an Object with its
|
203 |
* value
|
204 |
*
|
205 |
* TODO Move to ValueFactory
|
206 |
*
|
207 |
* @param plainObject
|
208 |
* @param fieldType
|
209 |
* @return
|
210 |
*/
|
211 |
public static Value getValue(Object object, int fieldType) { |
212 |
if(object == null) |
213 |
return ValueFactory.createNullValue();
|
214 |
Value solution = null;
|
215 |
switch (fieldType) {
|
216 |
case Types.VARCHAR: |
217 |
String str = (String) object; |
218 |
solution = ValueFactory.createValue(str); |
219 |
break;
|
220 |
case Types.FLOAT: |
221 |
float fval = ((Float) object).floatValue(); |
222 |
solution = ValueFactory.createValue(fval); |
223 |
break;
|
224 |
case Types.DOUBLE: |
225 |
double dval = ((Double) object).doubleValue(); |
226 |
solution = ValueFactory.createValue(dval); |
227 |
break;
|
228 |
case Types.INTEGER: |
229 |
int ival = ((Integer) object).intValue(); |
230 |
solution = ValueFactory.createValue(ival); |
231 |
break;
|
232 |
case Types.BIGINT: |
233 |
long lval = ((Long) object).longValue(); |
234 |
solution = ValueFactory.createValue(lval); |
235 |
break;
|
236 |
case Types.BIT: |
237 |
boolean bval = ((Boolean) object).booleanValue(); |
238 |
solution = ValueFactory.createValue(bval); |
239 |
break;
|
240 |
case Types.DATE: |
241 |
Date dtval = (Date) object; |
242 |
solution = ValueFactory.createValue(dtval); |
243 |
break;
|
244 |
default:
|
245 |
solution = ValueFactory.createNullValue(); |
246 |
} |
247 |
return solution;
|
248 |
} |
249 |
|
250 |
public static String[] getNumericFieldsNames(FLyrVect layer) { |
251 |
String[] solution = null; |
252 |
if(layer == null) |
253 |
return null; |
254 |
ArrayList list = new ArrayList(); |
255 |
try {
|
256 |
SelectableDataSource recordset = layer.getRecordset(); |
257 |
int numFields = recordset.getFieldCount();
|
258 |
for (int i = 0; i < numFields; i++) { |
259 |
if (XTypes.isNumeric(recordset.getFieldType(i))) {
|
260 |
list.add(recordset.getFieldName(i)); |
261 |
} |
262 |
}// for
|
263 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
264 |
return null; |
265 |
} catch (DriverException e) {
|
266 |
return null; |
267 |
} |
268 |
solution = new String[list.size()]; |
269 |
list.toArray(solution); |
270 |
return solution;
|
271 |
} |
272 |
|
273 |
|
274 |
} |