root / branches / v10 / extensions / extSDE / src / com / iver / cit / gvsig / fmap / drivers / sde / testSDE.java @ 10942
History | View | Annotate | Download (9.28 KB)
1 |
/*
|
---|---|
2 |
* Created on 13-may-2005
|
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 |
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 |
public static void main(String[] args) |
61 |
{ |
62 |
// Conexi?n:
|
63 |
SeConnection conn = null;
|
64 |
String server = "192.168.0.114"; |
65 |
int instance = 5151; |
66 |
String database = "ProvinciasPruebas"; |
67 |
String user = "sde"; |
68 |
String password = "iver"; |
69 |
try {
|
70 |
conn = new SeConnection(server, instance, database, user, password);
|
71 |
}catch (SeException e) {
|
72 |
e.printStackTrace(); |
73 |
return;
|
74 |
} |
75 |
|
76 |
// Fetching data
|
77 |
|
78 |
String layerName = "EJES"; |
79 |
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 |
if (layer.getName().equals(layerName)){
|
87 |
layerID = layer.getID(); |
88 |
strSpatialColumn = layer.getSpatialColumn(); |
89 |
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 |
} |
104 |
} |
105 |
if (layerID == null) |
106 |
{ |
107 |
System.err.println("Capa no encontrada"); |
108 |
return;
|
109 |
} |
110 |
|
111 |
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 |
cols[0] = new String("FID"); |
117 |
cols[1] = layer.getSpatialColumn();
|
118 |
SeQuery query = new SeQuery( conn, cols, sqlConstruct );
|
119 |
query.prepareQuery(); |
120 |
query.execute(); |
121 |
long t2 = System.currentTimeMillis(); |
122 |
|
123 |
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 |
|
129 |
System.out.println(" No rows fetched"); |
130 |
return;
|
131 |
} |
132 |
// String rowID = "2";
|
133 |
|
134 |
// 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 |
|
144 |
query.close(); |
145 |
t2 = System.currentTimeMillis();
|
146 |
|
147 |
System.out.println("Tiempo de recorrido:" + (t2 - t1) + " milisegundos. " + cont + " registros."); |
148 |
|
149 |
/* SeQuery extentQuery = new SeQuery( conn, cols, sqlConstruct );
|
150 |
SeQueryInfo queryInfo = new SeQueryInfo();
|
151 |
queryInfo.setConstruct(sqlConstruct);
|
152 |
// queryInfo.setQueryType(SeQueryInfo.SE_QUERYTYPE_JFA);
|
153 |
// query.prepareQueryInfo(queryInfo);
|
154 |
|
155 |
SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo);
|
156 |
extentQuery.close();
|
157 |
System.out.println(seExtent.toString());
|
158 |
|
159 |
|
160 |
SeQuery queryAux;
|
161 |
t1 = System.currentTimeMillis();
|
162 |
// queryAux = new SeQuery( conn, cols, sqlConstruct );
|
163 |
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 |
|
169 |
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 |
|
176 |
/* queryAux = new SeQuery( conn, cols, sqlConstruct );
|
177 |
SeObjectId rowID = new SeObjectId(1);
|
178 |
row = queryAux.fetchRow("provin", rowID, cols);
|
179 |
evaluateRow(row, colDefs);
|
180 |
row = queryAux.fetch();
|
181 |
evaluateRow(row, colDefs);
|
182 |
|
183 |
queryAux.close(); */
|
184 |
|
185 |
} catch( SeException e ) {
|
186 |
System.out.println(e.getSeError().getErrDesc());
|
187 |
} |
188 |
|
189 |
|
190 |
} |
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 |
for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++) |
202 |
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 |
} |
216 |
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 |
{ |
224 |
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 |
|
233 |
case SeColumnDefinition.TYPE_DATE:
|
234 |
break;
|
235 |
|
236 |
case SeColumnDefinition.TYPE_INTEGER:
|
237 |
break;
|
238 |
|
239 |
case SeColumnDefinition.TYPE_FLOAT:
|
240 |
break;
|
241 |
|
242 |
case SeColumnDefinition.TYPE_DOUBLE:
|
243 |
break;
|
244 |
|
245 |
case SeColumnDefinition.TYPE_STRING:
|
246 |
// System.out.println(row.getString(colNum));
|
247 |
break;
|
248 |
|
249 |
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 |
} |