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