svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / fmap / DefinitionUtils.java @ 39584
History | View | Annotate | Download (5.73 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: DefinitionUtils.java 39584 2013-01-10 14:47:47Z fpuga $
|
47 |
* $Log$
|
48 |
* Revision 1.3 2007-03-06 16:47:58 caballero
|
49 |
* Exceptions
|
50 |
*
|
51 |
* Revision 1.2 2006/06/20 18:19:43 azabala
|
52 |
* refactorizaci?n para que todos los nuevos geoprocesos cuelguen del paquete impl
|
53 |
*
|
54 |
* Revision 1.1 2006/05/24 21:12:16 azabala
|
55 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
56 |
*
|
57 |
* Revision 1.6 2006/05/08 15:38:31 azabala
|
58 |
* converted private constant in public
|
59 |
*
|
60 |
* Revision 1.5 2006/03/26 20:03:31 azabala
|
61 |
* *** empty log message ***
|
62 |
*
|
63 |
* Revision 1.4 2006/03/14 18:32:46 fjp
|
64 |
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
|
65 |
*
|
66 |
* Revision 1.3 2006/02/19 20:56:07 azabala
|
67 |
* *** empty log message ***
|
68 |
*
|
69 |
* Revision 1.2 2006/02/17 16:34:00 azabala
|
70 |
* *** empty log message ***
|
71 |
*
|
72 |
* Revision 1.1 2006/02/09 15:59:48 azabala
|
73 |
* First version in CVS
|
74 |
*
|
75 |
*
|
76 |
*/
|
77 |
package com.iver.cit.gvsig.geoprocess.core.fmap; |
78 |
|
79 |
import java.util.ArrayList; |
80 |
import java.util.List; |
81 |
|
82 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
83 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
84 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
85 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
86 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
87 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
88 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
89 |
|
90 |
/**
|
91 |
* This class has utility methods to work with LayerDefinitions
|
92 |
* @author azabala
|
93 |
*
|
94 |
* TODO By now only works with SHPLayerDefinition. Redesign to work
|
95 |
* with any layer definition.
|
96 |
*/
|
97 |
public class DefinitionUtils { |
98 |
public static int NUM_DECIMALS = 5; |
99 |
/**
|
100 |
* It builds a LayerDefinition from a LyrVect
|
101 |
* @param datasource
|
102 |
* @param shapeType
|
103 |
* @return
|
104 |
* @throws ReadDriverException
|
105 |
* @throws DriverException
|
106 |
* @throws com.iver.cit.gvsig.fmap.DriverException
|
107 |
*/
|
108 |
public static SHPLayerDefinition createLayerDefinition(FLyrVect layer) throws ReadDriverException{ |
109 |
SHPLayerDefinition solution = new SHPLayerDefinition();
|
110 |
solution.setName(layer.getName()); |
111 |
solution.setShapeType(layer.getShapeType()); |
112 |
SelectableDataSource datasource = layer.getRecordset(); |
113 |
FieldDescription[] fieldsDescription = datasource.getFieldsDescription();
|
114 |
solution.setFieldsDesc(fieldsDescription); |
115 |
return solution;
|
116 |
} |
117 |
|
118 |
|
119 |
|
120 |
public static int getDataTypeLength(int dataType){ |
121 |
switch(dataType){
|
122 |
case XTypes.NUMERIC:
|
123 |
case XTypes.DOUBLE:
|
124 |
case XTypes.REAL:
|
125 |
case XTypes.FLOAT:
|
126 |
case XTypes.BIGINT:
|
127 |
case XTypes.INTEGER:
|
128 |
case XTypes.DECIMAL:
|
129 |
return 20; |
130 |
case XTypes.CHAR:
|
131 |
case XTypes.VARCHAR:
|
132 |
case XTypes.LONGVARCHAR:
|
133 |
return 254; |
134 |
case XTypes.DATE:
|
135 |
return 8; |
136 |
case XTypes.BOOLEAN:
|
137 |
case XTypes.BIT:
|
138 |
return 1; |
139 |
} |
140 |
return 0; |
141 |
} |
142 |
|
143 |
/**
|
144 |
* Utility class to overlay geoprocess (that merges
|
145 |
* layer definitions of many features)
|
146 |
* @param firstLayer
|
147 |
* @param secondLayer
|
148 |
* @return
|
149 |
* @throws ReadDriverException
|
150 |
* @throws DriverException
|
151 |
* @throws com.iver.cit.gvsig.fmap.DriverException
|
152 |
*/
|
153 |
public static SHPLayerDefinition mergeLayerDefinitions(FLyrVect firstLayer, |
154 |
FLyrVect secondLayer) throws ReadDriverException{
|
155 |
|
156 |
SHPLayerDefinition solution = new SHPLayerDefinition();
|
157 |
solution.setName(firstLayer.getName() + "-" + secondLayer.getName());
|
158 |
solution.setShapeType(firstLayer.getShapeType()); |
159 |
SelectableDataSource firstDatasource = firstLayer.getRecordset(); |
160 |
SelectableDataSource secondDatasource = secondLayer.getRecordset(); |
161 |
FieldDescription[] fields =
|
162 |
new FieldDescription[firstDatasource.getFieldCount() + secondDatasource.getFieldCount()];
|
163 |
|
164 |
int i = 0; |
165 |
for (FieldDescription fieldDesc:firstDatasource.getFieldsDescription()) {
|
166 |
fields[i++] = fieldDesc; |
167 |
} |
168 |
for (FieldDescription fieldDesc:secondDatasource.getFieldsDescription()) {
|
169 |
fields[i++] = fieldDesc; |
170 |
} |
171 |
|
172 |
solution.setFieldsDesc(fields); |
173 |
return solution;
|
174 |
} |
175 |
/**
|
176 |
* Tells if a FieldDescription is numeric
|
177 |
* @param fieldDesc
|
178 |
* @return
|
179 |
*/
|
180 |
public static boolean isNumeric(FieldDescription fieldDesc){ |
181 |
return XTypes.isNumeric(fieldDesc.getFieldType());
|
182 |
} |
183 |
/**
|
184 |
* Returns all numeric FieldDescriptions of a LayerDefinition
|
185 |
* @param layerDef
|
186 |
* @return
|
187 |
*/
|
188 |
public static List getNumerics(ITableDefinition layerDef){ |
189 |
ArrayList solution = new ArrayList(); |
190 |
FieldDescription[] fields = layerDef.getFieldsDesc();
|
191 |
for(int i = 0; i < fields.length; i++){ |
192 |
//java access to arrays is a consumption operation
|
193 |
FieldDescription field = fields[i]; |
194 |
if(DefinitionUtils.isNumeric(field)){
|
195 |
solution.add(field); |
196 |
} |
197 |
} |
198 |
return solution;
|
199 |
} |
200 |
} |
201 |
|