Revision 10942 branches/v10/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/ArcSdeFeatureIterator.java

View differences:

ArcSdeFeatureIterator.java
2 2
 * Created on 11-mar-2005
3 3
 *
4 4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 * 
5
 *
6 6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 * 
7
 *
8 8
 * This program is free software; you can redistribute it and/or
9 9
 * modify it under the terms of the GNU General Public License
10 10
 * as published by the Free Software Foundation; either version 2
11 11
 * of the License, or (at your option) any later version.
12
 *  
12
 *
13 13
 * This program is distributed in the hope that it will be useful,
14 14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
 * GNU General Public License for more details.
17
 * 
17
 *
18 18
 * You should have received a copy of the GNU General Public License
19 19
 * along with this program; if not, write to the Free Software
20 20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *  
21
 *
22 22
 * For more information, contact:
23 23
 *
24 24
 *  Generalitat Valenciana
......
30 30
 *      +34 963862235
31 31
 *   gvsig@gva.es
32 32
 *      www.gvsig.gva.es
33
 * 
33
 *
34 34
 *    or
35
 * 
35
 *
36 36
 *   IVER T.I. S.A
37 37
 *   Salamanca 50
38 38
 *   46005 Valencia
39 39
 *   Spain
40
 * 
40
 *
41 41
 *   +34 963163400
42 42
 *   dac@iver.es
43 43
 */
......
52 52
import com.esri.sde.sdk.client.SeShape;
53 53
import com.hardcode.gdbms.engine.values.Value;
54 54
import com.hardcode.gdbms.engine.values.ValueFactory;
55
import com.iver.cit.gvsig.fmap.DriverException;
55 56
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
56 57
import com.iver.cit.gvsig.fmap.core.FNullGeometry;
57 58
import com.iver.cit.gvsig.fmap.core.FPoint2D;
......
62 63
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
63 64

  
64 65
/**
65
 * @author FJP
66
 *
67
 * TODO To change the template for this generated type comment go to
68
 * Window - Preferences - Java - Code Generation - Code and Comments
66
 * @author   FJP
69 67
 */
70 68
public class ArcSdeFeatureIterator implements IFeatureIterator {
71 69
    IGeometry geom;
......
74 72
    private boolean bFirst;
75 73
    Value[] regAtt;
76 74
    SeRow row;
77
    
75

  
78 76
    static GeneralPathX convertSeShapeToGeneralPathX(SeShape spVal) throws SeException
79 77
    {
80 78
        double[][][] points = spVal.getAllCoords(SeShape.TURN_RIGHT);
......
82 80
        // Display the X and Y values
83 81
        boolean bStartPart;
84 82
        for( int partNo = 0 ; partNo < points.length ; partNo++)
85
        {            
83
        {
86 84
            for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++)
87 85
            {
88 86
                bStartPart = true;
......
100 98

  
101 99
                }
102 100
            }
103
        }  
101
        }
104 102
        return gpx;
105 103
    }
106
    
104

  
107 105
    public static IGeometry getGeometry( SeShape shape ) {
108
        
106

  
109 107
        try {
110 108
            /*
111 109
             *   Retrieve the shape type.
112 110
             */
113 111
            int type = -1;
114 112
            type = shape.getType();
115
            
113

  
116 114
            // Display the X and Y values
117
            /* for( int partNo = 0 ; partNo < points.length ; partNo++, System.out.println("") ) 
118
                for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++, System.out.println("") ) 
119
                    for( int pointNo = 0 ; pointNo < points[partNo][subPartNo].length ; pointNo+=2) 
115
            /* for( int partNo = 0 ; partNo < points.length ; partNo++, System.out.println("") )
116
                for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++, System.out.println("") )
117
                    for( int pointNo = 0 ; pointNo < points[partNo][subPartNo].length ; pointNo+=2)
120 118
                        System.out.println("X: " + points[partNo][subPartNo][pointNo] + "\tY: "
121
                                                 + points[partNo][subPartNo][(pointNo+1)] ); */            
119
                                                 + points[partNo][subPartNo][(pointNo+1)] ); */
122 120
            switch( type )
123 121
            {
124 122
                case SeShape.TYPE_POINT:
125 123
                    double[][][] points = shape.getAllCoords();
126 124
                    FPoint2D p =  new FPoint2D(points[0][0][0],points[0][0][1]);
127 125
                    return ShapeFactory.createPoint2D(p);
128
                
126

  
129 127
                case SeShape.TYPE_LINE:
130 128
                case SeShape.TYPE_MULTI_LINE:
131 129
                case SeShape.TYPE_MULTI_SIMPLE_LINE:
132 130
                case SeShape.TYPE_SIMPLE_LINE:
133 131
                    GeneralPathX gpx = new GeneralPathX(shape.toGeneralPath());
134 132
                    return ShapeFactory.createPolyline2D(gpx);
135
                    
136
                case SeShape.TYPE_MULTI_POINT:                    
133

  
134
                case SeShape.TYPE_MULTI_POINT:
137 135
                    break;
138
                
136

  
139 137
                case SeShape.TYPE_NIL:
140 138
                    return new FNullGeometry();
141 139
                case SeShape.TYPE_POLYGON:
142
                case SeShape.TYPE_MULTI_POLYGON:                     
140
                case SeShape.TYPE_MULTI_POLYGON:
143 141
                    // GeneralPathX gpx2 = new GeneralPathX(shape.toGeneralPath());
144 142
                    GeneralPathX gpx2 = convertSeShapeToGeneralPathX(shape);
145 143
                    /* SeExtent r = shape.getExtent();
......
158 156
            e.printStackTrace();
159 157
        }
160 158
        return new FNullGeometry();
161
    }     
162
    
159
    }
160

  
163 161
    /**
164 162
     * @throws SQLException
165
     * 
163
     *
166 164
     */
167 165
    public ArcSdeFeatureIterator(SeQuery query) {
168 166
        // Debe ser forward only
......
182 180
            e.printStackTrace();
183 181
        }
184 182
    }
185
    
183

  
186 184
    /* (non-Javadoc)
187 185
     * @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#hasNext()
188 186
     */
189
    public boolean hasNext() throws SQLException {
187
    public boolean hasNext() throws DriverException {
190 188
        try {
191 189
            if (bFirst)
192 190
                bFirst = false;
......
197 195
                query.close();
198 196
                return false;
199 197
            }
200
            
198

  
201 199
            return true;
202 200
        }
203
        catch (SeException e) {            
204
            e.printStackTrace();            
201
        catch (SeException e) {
202
            e.printStackTrace();
205 203
            // throw new SQLException(e.getMessage());
206 204
        }
207 205
        return false;
......
210 208
    /* (non-Javadoc)
211 209
     * @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#next()
212 210
     */
213
    public IFeature next() throws SQLException {
211
    public IFeature next() throws DriverException {
214 212
        SeShape spVal = null;
215
        SeColumnDefinition[] colDefs = row.getColumns(); 
213
        SeColumnDefinition[] colDefs = row.getColumns();
216 214
        IFeature feat = null;
217 215
        try
218
        {            
219
            if ( row != null ) 
220
            { 
216
        {
217
            if ( row != null )
218
            {
221 219
                for (int colNum = 0; colNum < colDefs.length; colNum++)
222
                {                
220
                {
223 221
                    SeColumnDefinition colDef = colDefs[colNum];
224 222
                    int dataType = colDef.getType();
225 223
                    if ( row.getIndicator((short)colNum) != SeRow.SE_IS_NULL_VALUE)
226 224
                    {
227 225
                        switch( dataType )
228 226
                        {
229
                            case SeColumnDefinition.TYPE_SMALLINT:
227
                            case SeColumnDefinition.TYPE_INT16:
230 228
                                regAtt[colNum-1] =  ValueFactory.createValue(row.getShort(colNum).intValue());
231
                                break;                                
229
                                break;
232 230
                            case SeColumnDefinition.TYPE_DATE:
233
                                regAtt[colNum-1] =  ValueFactory.createValue(row.getDate(colNum));
231
                                regAtt[colNum-1] =  ValueFactory.createValue(row.getTime(colNum).getTime());
234 232
                                break;
235
                                
236
                            case SeColumnDefinition.TYPE_INTEGER:
233

  
234
                            case SeColumnDefinition.TYPE_INT32:
235
                            case SeColumnDefinition.TYPE_INT64:
237 236
                                regAtt[colNum-1] =  ValueFactory.createValue(row.getInteger(colNum).intValue());
238 237
                                break;
239
                                                            
240
                            case SeColumnDefinition.TYPE_FLOAT:
238

  
239
                            case SeColumnDefinition.TYPE_FLOAT32:
241 240
                                regAtt[colNum-1] =  ValueFactory.createValue(row.getFloat(colNum).floatValue());
242 241
                                break;
243
                                
244
                            case SeColumnDefinition.TYPE_DOUBLE:
242

  
243
                            case SeColumnDefinition.TYPE_FLOAT64:
245 244
                                regAtt[colNum-1] =  ValueFactory.createValue(row.getDouble(colNum).doubleValue());
246 245
                                break;
247
                                
246

  
248 247
                            case SeColumnDefinition.TYPE_STRING:
249 248
                                regAtt[colNum-1] =  ValueFactory.createValue(row.getString(colNum));
250 249
                                break;
251
                                
250

  
252 251
                            case SeColumnDefinition.TYPE_SHAPE:
253
                                spVal = row.getShape(colNum);                               
252
                                spVal = row.getShape(colNum);
254 253
                                geom = getGeometry(spVal);
255 254
                                break;
256 255
                        } // End switch
257 256
                    } // End if
258 257
                } // for
259 258
                // System.out.println("Dentro de next(): " + spVal.getFeatureId().toString() + " " + regAtt[0]);
260
            
259

  
261 260
                feat = new DefaultFeature(geom, regAtt, "" + spVal.getFeatureId().longValue());
262 261
            } // if
263 262

  
264
            
263

  
265 264
        } catch (SeException e)
266 265
        {
267 266
            e.printStackTrace();
268 267
        }
269
              
270
        
268

  
269

  
271 270
        return feat;
272 271
    }
273 272

  
273
	public void closeIterator() throws DriverException {
274
		try {
275
			bFirst=false;
276
			query.close();
277
		} catch (SeException e) {
278
			// TODO Auto-generated catch block
279
			e.printStackTrace();
280
		}
281

  
282
	}
283

  
274 284
}

Also available in: Unified diff