Statistics
| Revision:

root / trunk / extensions / extSDE / src / com / iver / cit / gvsig / fmap / drivers / sde / testSDE.java @ 11971

History | View | Annotate | Download (9.5 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.andami.messages.NotificationManager;
58
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
59

    
60

    
61
/**
62
 * DOCUMENT ME!
63
 *
64
 * @author Vicente Caballero Navarro
65
 */
66
public class testSDE {
67
    /**
68
     * DOCUMENT ME!
69
     *
70
     * @param args DOCUMENT ME!
71
     */
72
    public static void main(String[] args) {
73
        // Conexi?n:
74
        SeConnection conn = null;
75
        String server = "192.168.0.114";
76
        int instance = 5151;
77
        String database = "ProvinciasPruebas";
78
        String user = "sde";
79
        String password = "iver";
80

    
81
        try {
82
            conn = new SeConnection(server, instance, database, user, password);
83
        } catch (SeException e) {
84
                NotificationManager.addError(e);
85

    
86
            return;
87
        }
88

    
89
        // Fetching data
90
        String layerName = "EJES";
91
        SeObjectId layerID = null;
92
        String strSpatialColumn = "";
93

    
94
        try {
95
            Vector theLayers = conn.getLayers();
96

    
97
            for (int i = 0; i < theLayers.size(); i++) {
98
                SeLayer layer = (SeLayer) theLayers.elementAt(i);
99

    
100
                if (layer.getName().equals(layerName)) {
101
                    layerID = layer.getID();
102
                    strSpatialColumn = layer.getSpatialColumn();
103
                    System.err.println("Nombre de la capa= " + layer.getName());
104

    
105
                    for (int k = 0; k < layerID.longValue(); k++) {
106
                        layer.getAccess();
107
                        layer.getQualifiedName();
108
                        layer.getArraySize();
109
                        layer.getDescription();
110
                        layer.getInfo();
111
                        layer.getShapeTypes();
112

    
113
                        //                            try{
114
                        System.err.println("Nombre campo= " +
115
                            layerID.longValue());
116

    
117
                        //                            } catch( SeException e ) {
118
                        //                                    //System.out.println(e.getSeError().getErrDesc());
119
                        //                            }
120
                    }
121
                }
122
            }
123

    
124
            if (layerID == null) {
125
                System.err.println("Capa no encontrada");
126

    
127
                return;
128
            }
129

    
130
            SeLayer layer = new SeLayer(conn, layerName, strSpatialColumn);
131
            SeSqlConstruct sqlConstruct = new SeSqlConstruct(layerName);
132
            long t1 = System.currentTimeMillis();
133

    
134
            //      Create a query stream between the client and server
135
            String[] cols = new String[2];
136
            cols[0] = new String("FID");
137
            cols[1] = layer.getSpatialColumn();
138

    
139
            SeQuery query = new SeQuery(conn, cols, sqlConstruct);
140
            query.prepareQuery();
141
            query.execute();
142

    
143
            long t2 = System.currentTimeMillis();
144

    
145
            System.out.println("Tiempo de consulta:" + (t2 - t1) +
146
                " milisegundos");
147
            t1 = System.currentTimeMillis();
148

    
149
            int cont = 0;
150
            SeRow row = query.fetch();
151

    
152
            if (row == null) {
153
                System.out.println(" No rows fetched");
154

    
155
                return;
156
            }
157

    
158
            // String rowID = "2";
159
            // Get the definitions of all the columns retrieved
160
            SeColumnDefinition[] colDefs = row.getColumns();
161

    
162
            while (row != null) {
163
                evaluateRow(row, colDefs);
164
                row = query.fetch();
165
                cont++;
166
            }
167

    
168
            // Close the query.
169
            query.close();
170
            t2 = System.currentTimeMillis();
171

    
172
            System.out.println("Tiempo de recorrido:" + (t2 - t1) +
173
                " milisegundos. " + cont + " registros.");
174

    
175
            /* SeQuery extentQuery = new SeQuery( conn, cols, sqlConstruct );
176
            SeQueryInfo queryInfo = new SeQueryInfo();
177
            queryInfo.setConstruct(sqlConstruct);
178
            // queryInfo.setQueryType(SeQueryInfo.SE_QUERYTYPE_JFA);
179
            // query.prepareQueryInfo(queryInfo);
180

181
            SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo);
182
            extentQuery.close();
183
            System.out.println(seExtent.toString());
184

185

186
            SeQuery queryAux;
187
            t1 = System.currentTimeMillis();
188
            // queryAux = new SeQuery( conn, cols, sqlConstruct );
189
            for (int i=0; i < 250; i++)
190
            {
191
                queryAux = new SeQuery( conn, cols, sqlConstruct );
192
                SeObjectId rowID = new SeObjectId(i+1);
193
                row = queryAux.fetchRow("provin", rowID, cols);
194

195
                evaluateRow(row, colDefs);
196
                queryAux.close();
197
            }
198
            // queryAux.close();
199
            t2 = System.currentTimeMillis();
200
            System.out.println("Tiempo de recorrido:"  + (t2 - t1) + " milisegundos. "); */
201
            /* queryAux = new SeQuery( conn, cols, sqlConstruct );
202
            SeObjectId rowID = new SeObjectId(1);
203
            row = queryAux.fetchRow("provin", rowID, cols);
204
            evaluateRow(row, colDefs);
205
            row = queryAux.fetch();
206
            evaluateRow(row, colDefs);
207

208
            queryAux.close(); */
209
        } catch (SeException e) {
210
            System.out.println(e.getSeError().getErrDesc());
211
        }
212
    }
213

    
214
    static GeneralPathX convertSeShapeToGeneralPathX(SeShape spVal)
215
        throws SeException {
216
        double[][][] points = spVal.getAllCoords();
217
        GeneralPathX gpx = new GeneralPathX();
218

    
219
        // Display the X and Y values
220
        boolean bStartPart;
221

    
222
        for (int partNo = 0; partNo < points.length; partNo++) {
223
            bStartPart = true;
224

    
225
            for (int subPartNo = 0; subPartNo < points[partNo].length;
226
                    subPartNo++)
227
                for (int pointNo = 0;
228
                        pointNo < points[partNo][subPartNo].length;
229
                        pointNo += 2) {
230
                    if (bStartPart) {
231
                        bStartPart = false;
232
                        gpx.moveTo(points[partNo][subPartNo][pointNo],
233
                            points[partNo][subPartNo][(pointNo + 1)]);
234
                    } else {
235
                        gpx.lineTo(points[partNo][subPartNo][pointNo],
236
                            points[partNo][subPartNo][(pointNo + 1)]);
237
                    }
238
                }
239
        }
240

    
241
        return gpx;
242
    }
243

    
244
    static void evaluateRow(SeRow row, SeColumnDefinition[] colDefs) {
245
        try {
246
            for (int colNum = 0; colNum < colDefs.length; colNum++) {
247
                SeColumnDefinition colDef = colDefs[colNum];
248
                int dataType = colDef.getType();
249

    
250
                if (row.getIndicator((short) colNum) != SeRow.SE_IS_NULL_VALUE) {
251
                    switch (dataType) {
252
                    case SeColumnDefinition.TYPE_SMALLINT:
253
                        break;
254

    
255
                    case SeColumnDefinition.TYPE_DATE:
256
                        break;
257

    
258
                    case SeColumnDefinition.TYPE_INTEGER:
259
                        break;
260

    
261
                    case SeColumnDefinition.TYPE_FLOAT:
262
                        break;
263

    
264
                    case SeColumnDefinition.TYPE_DOUBLE:
265
                        break;
266

    
267
                    case SeColumnDefinition.TYPE_STRING:
268

    
269
                        // System.out.println(row.getString(colNum));
270
                        break;
271

    
272
                    case SeColumnDefinition.TYPE_SHAPE:
273

    
274
                        SeShape spVal = row.getShape(colNum);
275
                        convertSeShapeToGeneralPathX(spVal);
276

    
277
                        // GeneralPath gp = spVal.toGeneralPath();
278
                        // GeneralPathX gpx = new GeneralPathX(gp);
279
                        // System.out.println("spVal.FID = " + spVal.getFeatureId().longValue());
280
                        // getShapeDetails(spVal);
281
                        break;
282
                    } // End switch
283
                } // End if
284
            } // for
285
        } catch (SeException e) {
286
                NotificationManager.addError(e);
287
        }
288
    }
289
}