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