root / branches / v10 / extensions / extSDE / src / com / iver / cit / gvsig / fmap / drivers / sde / testSDE.java @ 10942
History | View | Annotate | Download (9.28 KB)
1 | 2277 | vcaballero | /*
|
---|---|---|---|
2 | * Created on 13-may-2005
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | 10942 | caballero | *
|
6 | 2277 | vcaballero | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 | 10942 | caballero | *
|
8 | 2277 | vcaballero | * 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 | 10942 | caballero | *
|
13 | 2277 | vcaballero | * 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 | 10942 | caballero | *
|
18 | 2277 | vcaballero | * 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 | 10942 | caballero | *
|
22 | 2277 | vcaballero | * 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 | 10942 | caballero | *
|
34 | 2277 | vcaballero | * or
|
35 | 10942 | caballero | *
|
36 | 2277 | vcaballero | * IVER T.I. S.A
|
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | 10942 | caballero | *
|
41 | 2277 | vcaballero | * +34 963163400
|
42 | * dac@iver.es
|
||
43 | */
|
||
44 | package com.iver.cit.gvsig.fmap.drivers.sde; |
||
45 | |||
46 | import java.util.Vector; |
||
47 | |||
48 | import com.esri.sde.sdk.client.SeColumnDefinition; |
||
49 | import com.esri.sde.sdk.client.SeConnection; |
||
50 | import com.esri.sde.sdk.client.SeException; |
||
51 | import com.esri.sde.sdk.client.SeLayer; |
||
52 | import com.esri.sde.sdk.client.SeObjectId; |
||
53 | import com.esri.sde.sdk.client.SeQuery; |
||
54 | import com.esri.sde.sdk.client.SeRow; |
||
55 | import com.esri.sde.sdk.client.SeShape; |
||
56 | import com.esri.sde.sdk.client.SeSqlConstruct; |
||
57 | import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
||
58 | |||
59 | public class testSDE { |
||
60 | 10942 | caballero | public static void main(String[] args) |
61 | { |
||
62 | 2277 | vcaballero | // Conexi?n:
|
63 | SeConnection conn = null;
|
||
64 | 10942 | caballero | String server = "192.168.0.114"; |
65 | 2277 | vcaballero | int instance = 5151; |
66 | 10942 | caballero | String database = "ProvinciasPruebas"; |
67 | 2277 | vcaballero | String user = "sde"; |
68 | 10942 | caballero | String password = "iver"; |
69 | 2277 | vcaballero | try {
|
70 | 10942 | caballero | conn = new SeConnection(server, instance, database, user, password);
|
71 | 2277 | vcaballero | }catch (SeException e) {
|
72 | e.printStackTrace(); |
||
73 | return;
|
||
74 | 10942 | caballero | } |
75 | |||
76 | 2277 | vcaballero | // Fetching data
|
77 | |||
78 | 10942 | caballero | String layerName = "EJES"; |
79 | 2277 | vcaballero | SeObjectId layerID = null;
|
80 | String strSpatialColumn = ""; |
||
81 | try {
|
||
82 | Vector theLayers = conn.getLayers();
|
||
83 | for (int i=0; i < theLayers.size(); i++) |
||
84 | { |
||
85 | SeLayer layer = (SeLayer)theLayers.elementAt(i); |
||
86 | 10942 | caballero | if (layer.getName().equals(layerName)){
|
87 | 2277 | vcaballero | layerID = layer.getID(); |
88 | strSpatialColumn = layer.getSpatialColumn(); |
||
89 | 10942 | caballero | System.err.println("Nombre de la capa= " + layer.getName()); |
90 | for (int k=0;k<layerID.longValue();k++){ |
||
91 | layer.getAccess(); |
||
92 | layer.getQualifiedName(); |
||
93 | layer.getArraySize(); |
||
94 | layer.getDescription(); |
||
95 | layer.getInfo(); |
||
96 | layer.getShapeTypes(); |
||
97 | // try{
|
||
98 | System.err.println("Nombre campo= " + layerID.longValue()); |
||
99 | // } catch( SeException e ) {
|
||
100 | // //System.out.println(e.getSeError().getErrDesc());
|
||
101 | // }
|
||
102 | } |
||
103 | 2277 | vcaballero | } |
104 | } |
||
105 | if (layerID == null) |
||
106 | { |
||
107 | System.err.println("Capa no encontrada"); |
||
108 | return;
|
||
109 | } |
||
110 | 10942 | caballero | |
111 | 2277 | vcaballero | SeLayer layer = new SeLayer( conn, layerName, strSpatialColumn );
|
112 | SeSqlConstruct sqlConstruct = new SeSqlConstruct( layerName);
|
||
113 | long t1 = System.currentTimeMillis(); |
||
114 | // Create a query stream between the client and server
|
||
115 | String[] cols = new String[2]; |
||
116 | 10942 | caballero | cols[0] = new String("FID"); |
117 | cols[1] = layer.getSpatialColumn();
|
||
118 | 2277 | vcaballero | SeQuery query = new SeQuery( conn, cols, sqlConstruct );
|
119 | query.prepareQuery(); |
||
120 | query.execute(); |
||
121 | long t2 = System.currentTimeMillis(); |
||
122 | 10942 | caballero | |
123 | 2277 | vcaballero | System.out.println("Tiempo de consulta:" + (t2 - t1) + " milisegundos"); |
124 | t1 = System.currentTimeMillis();
|
||
125 | int cont = 0; |
||
126 | SeRow row = query.fetch(); |
||
127 | if( row == null ) { |
||
128 | 10942 | caballero | |
129 | 2277 | vcaballero | System.out.println(" No rows fetched"); |
130 | return;
|
||
131 | } |
||
132 | // String rowID = "2";
|
||
133 | 10942 | caballero | |
134 | 2277 | vcaballero | // Get the definitions of all the columns retrieved
|
135 | SeColumnDefinition[] colDefs = row.getColumns();
|
||
136 | while (row != null) |
||
137 | { |
||
138 | evaluateRow(row, colDefs); |
||
139 | row = query.fetch(); |
||
140 | cont++; |
||
141 | } |
||
142 | // Close the query.
|
||
143 | 10942 | caballero | |
144 | 2277 | vcaballero | query.close(); |
145 | t2 = System.currentTimeMillis();
|
||
146 | |||
147 | System.out.println("Tiempo de recorrido:" + (t2 - t1) + " milisegundos. " + cont + " registros."); |
||
148 | |||
149 | 10942 | caballero | /* SeQuery extentQuery = new SeQuery( conn, cols, sqlConstruct );
|
150 | SeQueryInfo queryInfo = new SeQueryInfo();
|
||
151 | 2277 | vcaballero | queryInfo.setConstruct(sqlConstruct);
|
152 | // queryInfo.setQueryType(SeQueryInfo.SE_QUERYTYPE_JFA);
|
||
153 | // query.prepareQueryInfo(queryInfo);
|
||
154 | 10942 | caballero | |
155 | 2277 | vcaballero | SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo);
|
156 | extentQuery.close();
|
||
157 | System.out.println(seExtent.toString());
|
||
158 | 10942 | caballero | |
159 | |||
160 | 2277 | vcaballero | SeQuery queryAux;
|
161 | t1 = System.currentTimeMillis();
|
||
162 | 10942 | caballero | // queryAux = new SeQuery( conn, cols, sqlConstruct );
|
163 | 2277 | vcaballero | for (int i=0; i < 250; i++)
|
164 | {
|
||
165 | queryAux = new SeQuery( conn, cols, sqlConstruct );
|
||
166 | SeObjectId rowID = new SeObjectId(i+1);
|
||
167 | row = queryAux.fetchRow("provin", rowID, cols);
|
||
168 | 10942 | caballero | |
169 | 2277 | vcaballero | evaluateRow(row, colDefs);
|
170 | queryAux.close();
|
||
171 | }
|
||
172 | // queryAux.close();
|
||
173 | t2 = System.currentTimeMillis();
|
||
174 | System.out.println("Tiempo de recorrido:" + (t2 - t1) + " milisegundos. "); */
|
||
175 | 10942 | caballero | |
176 | 2277 | vcaballero | /* queryAux = new SeQuery( conn, cols, sqlConstruct );
|
177 | SeObjectId rowID = new SeObjectId(1);
|
||
178 | 10942 | caballero | row = queryAux.fetchRow("provin", rowID, cols);
|
179 | 2277 | vcaballero | evaluateRow(row, colDefs);
|
180 | 10942 | caballero | row = queryAux.fetch();
|
181 | 2277 | vcaballero | evaluateRow(row, colDefs);
|
182 | 10942 | caballero | |
183 | 2277 | vcaballero | queryAux.close(); */
|
184 | 10942 | caballero | |
185 | 2277 | vcaballero | } catch( SeException e ) {
|
186 | System.out.println(e.getSeError().getErrDesc());
|
||
187 | } |
||
188 | |||
189 | 10942 | caballero | |
190 | 2277 | vcaballero | } |
191 | |||
192 | static GeneralPathX convertSeShapeToGeneralPathX(SeShape spVal) throws SeException |
||
193 | { |
||
194 | double[][][] points = spVal.getAllCoords(); |
||
195 | GeneralPathX gpx = new GeneralPathX();
|
||
196 | // Display the X and Y values
|
||
197 | boolean bStartPart;
|
||
198 | for( int partNo = 0 ; partNo < points.length ; partNo++) |
||
199 | { |
||
200 | bStartPart = true;
|
||
201 | 10942 | caballero | for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++) |
202 | 2277 | vcaballero | for( int pointNo = 0 ; pointNo < points[partNo][subPartNo].length ; pointNo+=2) |
203 | { |
||
204 | if (bStartPart)
|
||
205 | { |
||
206 | bStartPart = false;
|
||
207 | gpx.moveTo(points[partNo][subPartNo][pointNo], |
||
208 | points[partNo][subPartNo][(pointNo+1)]);
|
||
209 | } |
||
210 | else
|
||
211 | gpx.lineTo(points[partNo][subPartNo][pointNo], |
||
212 | points[partNo][subPartNo][(pointNo+1)]);
|
||
213 | |||
214 | } |
||
215 | 10942 | caballero | } |
216 | 2277 | vcaballero | return gpx;
|
217 | } |
||
218 | static void evaluateRow(SeRow row, SeColumnDefinition[] colDefs) |
||
219 | { |
||
220 | try
|
||
221 | { |
||
222 | for (int colNum = 0; colNum < colDefs.length; colNum++) |
||
223 | 10942 | caballero | { |
224 | 2277 | vcaballero | SeColumnDefinition colDef = colDefs[colNum]; |
225 | int dataType = colDef.getType();
|
||
226 | if ( row.getIndicator((short)colNum) != SeRow.SE_IS_NULL_VALUE) |
||
227 | { |
||
228 | switch( dataType )
|
||
229 | { |
||
230 | case SeColumnDefinition.TYPE_SMALLINT:
|
||
231 | break;
|
||
232 | 10942 | caballero | |
233 | 2277 | vcaballero | case SeColumnDefinition.TYPE_DATE:
|
234 | break;
|
||
235 | 10942 | caballero | |
236 | 2277 | vcaballero | case SeColumnDefinition.TYPE_INTEGER:
|
237 | break;
|
||
238 | 10942 | caballero | |
239 | 2277 | vcaballero | case SeColumnDefinition.TYPE_FLOAT:
|
240 | break;
|
||
241 | 10942 | caballero | |
242 | 2277 | vcaballero | case SeColumnDefinition.TYPE_DOUBLE:
|
243 | break;
|
||
244 | 10942 | caballero | |
245 | 2277 | vcaballero | case SeColumnDefinition.TYPE_STRING:
|
246 | // System.out.println(row.getString(colNum));
|
||
247 | break;
|
||
248 | 10942 | caballero | |
249 | 2277 | vcaballero | case SeColumnDefinition.TYPE_SHAPE:
|
250 | SeShape spVal = row.getShape(colNum); |
||
251 | convertSeShapeToGeneralPathX(spVal); |
||
252 | |||
253 | // GeneralPath gp = spVal.toGeneralPath();
|
||
254 | // GeneralPathX gpx = new GeneralPathX(gp);
|
||
255 | // System.out.println("spVal.FID = " + spVal.getFeatureId().longValue());
|
||
256 | // getShapeDetails(spVal);
|
||
257 | break;
|
||
258 | } // End switch
|
||
259 | } // End if
|
||
260 | } // for
|
||
261 | } catch (SeException e)
|
||
262 | { |
||
263 | e.printStackTrace(); |
||
264 | } |
||
265 | } |
||
266 | } |