Revision 11193 trunk/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/ArcSdeFeatureIterator.java
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 |
*/ |
44 | 44 |
package com.iver.cit.gvsig.fmap.drivers.sde; |
45 | 45 |
|
46 |
import java.awt.geom.PathIterator; |
|
46 | 47 |
import java.sql.SQLException; |
48 |
import java.util.ArrayList; |
|
47 | 49 |
|
50 |
import com.esri.sde.sdk.client.SDEPoint; |
|
48 | 51 |
import com.esri.sde.sdk.client.SeColumnDefinition; |
52 |
import com.esri.sde.sdk.client.SeCoordinateReference; |
|
49 | 53 |
import com.esri.sde.sdk.client.SeException; |
50 | 54 |
import com.esri.sde.sdk.client.SeQuery; |
51 | 55 |
import com.esri.sde.sdk.client.SeRow; |
52 | 56 |
import com.esri.sde.sdk.client.SeShape; |
53 | 57 |
import com.hardcode.gdbms.engine.values.Value; |
54 | 58 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
59 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
55 | 60 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
61 |
import com.iver.cit.gvsig.fmap.core.FMultiPoint2D; |
|
56 | 62 |
import com.iver.cit.gvsig.fmap.core.FNullGeometry; |
57 | 63 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
64 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
58 | 65 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
59 | 66 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
60 | 67 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
... | ... | |
62 | 69 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
63 | 70 |
|
64 | 71 |
/** |
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 |
|
72 |
* @author FJP |
|
69 | 73 |
*/ |
70 | 74 |
public class ArcSdeFeatureIterator implements IFeatureIterator { |
71 | 75 |
IGeometry geom; |
... | ... | |
74 | 78 |
private boolean bFirst; |
75 | 79 |
Value[] regAtt; |
76 | 80 |
SeRow row; |
77 |
|
|
81 |
private int index=0; |
|
82 |
|
|
78 | 83 |
static GeneralPathX convertSeShapeToGeneralPathX(SeShape spVal) throws SeException |
79 | 84 |
{ |
80 | 85 |
double[][][] points = spVal.getAllCoords(SeShape.TURN_RIGHT); |
... | ... | |
82 | 87 |
// Display the X and Y values |
83 | 88 |
boolean bStartPart; |
84 | 89 |
for( int partNo = 0 ; partNo < points.length ; partNo++) |
85 |
{
|
|
90 |
{ |
|
86 | 91 |
for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++) |
87 | 92 |
{ |
88 | 93 |
bStartPart = true; |
... | ... | |
100 | 105 |
|
101 | 106 |
} |
102 | 107 |
} |
103 |
}
|
|
108 |
} |
|
104 | 109 |
return gpx; |
105 | 110 |
} |
106 |
|
|
111 |
|
|
107 | 112 |
public static IGeometry getGeometry( SeShape shape ) { |
108 |
|
|
113 |
|
|
109 | 114 |
try { |
110 | 115 |
/* |
111 | 116 |
* Retrieve the shape type. |
112 | 117 |
*/ |
113 | 118 |
int type = -1; |
114 | 119 |
type = shape.getType(); |
115 |
|
|
120 |
|
|
116 | 121 |
// 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)
|
|
122 |
/* for( int partNo = 0 ; partNo < points.length ; partNo++, System.out.println("") ) |
|
123 |
for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++, System.out.println("") ) |
|
124 |
for( int pointNo = 0 ; pointNo < points[partNo][subPartNo].length ; pointNo+=2) |
|
120 | 125 |
System.out.println("X: " + points[partNo][subPartNo][pointNo] + "\tY: " |
121 |
+ points[partNo][subPartNo][(pointNo+1)] ); */
|
|
126 |
+ points[partNo][subPartNo][(pointNo+1)] ); */ |
|
122 | 127 |
switch( type ) |
123 | 128 |
{ |
124 | 129 |
case SeShape.TYPE_POINT: |
125 | 130 |
double[][][] points = shape.getAllCoords(); |
126 | 131 |
FPoint2D p = new FPoint2D(points[0][0][0],points[0][0][1]); |
127 | 132 |
return ShapeFactory.createPoint2D(p); |
128 |
|
|
133 |
|
|
129 | 134 |
case SeShape.TYPE_LINE: |
130 | 135 |
case SeShape.TYPE_MULTI_LINE: |
131 | 136 |
case SeShape.TYPE_MULTI_SIMPLE_LINE: |
132 | 137 |
case SeShape.TYPE_SIMPLE_LINE: |
133 | 138 |
GeneralPathX gpx = new GeneralPathX(shape.toGeneralPath()); |
134 | 139 |
return ShapeFactory.createPolyline2D(gpx); |
135 |
|
|
136 |
case SeShape.TYPE_MULTI_POINT:
|
|
140 |
|
|
141 |
case SeShape.TYPE_MULTI_POINT: |
|
137 | 142 |
break; |
138 |
|
|
143 |
|
|
139 | 144 |
case SeShape.TYPE_NIL: |
140 | 145 |
return new FNullGeometry(); |
141 | 146 |
case SeShape.TYPE_POLYGON: |
142 |
case SeShape.TYPE_MULTI_POLYGON:
|
|
147 |
case SeShape.TYPE_MULTI_POLYGON: |
|
143 | 148 |
// GeneralPathX gpx2 = new GeneralPathX(shape.toGeneralPath()); |
144 | 149 |
GeneralPathX gpx2 = convertSeShapeToGeneralPathX(shape); |
145 | 150 |
/* SeExtent r = shape.getExtent(); |
... | ... | |
158 | 163 |
e.printStackTrace(); |
159 | 164 |
} |
160 | 165 |
return new FNullGeometry(); |
161 |
} |
|
162 |
|
|
166 |
} |
|
167 |
|
|
168 |
|
|
169 |
public static SeShape constructShape(IGeometry geometry, SeCoordinateReference seSrs) { |
|
170 |
SeShape shape = null; |
|
171 |
|
|
172 |
try { |
|
173 |
shape = new SeShape(seSrs); |
|
174 |
} catch (SeException ex) { |
|
175 |
|
|
176 |
} |
|
177 |
|
|
178 |
// if (geometry.isEmpty()) { |
|
179 |
// return shape; |
|
180 |
// } |
|
181 |
|
|
182 |
int numParts=1; |
|
183 |
// GeometryCollection gcol = null; |
|
184 |
// |
|
185 |
// if (geometry instanceof GeometryCollection) { |
|
186 |
// gcol = (GeometryCollection) geometry; |
|
187 |
// } else { |
|
188 |
// Geometry[] geoms = { geometry }; |
|
189 |
// gcol = new GeometryFactory().createGeometryCollection(geoms); |
|
190 |
// } |
|
191 |
|
|
192 |
// List allPoints = new ArrayList(); |
|
193 |
// numParts = gcol.getNumGeometries(); |
|
194 |
|
|
195 |
int[] partOffsets = new int[numParts]; |
|
196 |
// Geometry geom; |
|
197 |
// Coordinate[] coords; |
|
198 |
// Coordinate c; |
|
199 |
SDEPoint[] points = getPoints(geometry); |
|
200 |
partOffsets[0]=points.length; |
|
201 |
// for (int currGeom = 0; currGeom < numParts; currGeom++) { |
|
202 |
// partOffsets[currGeom] = allPoints.size(); |
|
203 |
// geom = gcol.getGeometryN(currGeom); |
|
204 |
// |
|
205 |
// coords = geom.getCoordinates(); |
|
206 |
// |
|
207 |
// for (int i = 0; i < coords.length; i++) { |
|
208 |
// c = coords[i]; |
|
209 |
// allPoints.add(new SDEPoint(c.x, c.y)); |
|
210 |
// } |
|
211 |
// } |
|
212 |
|
|
213 |
// SDEPoint[] points = new SDEPoint[allPoints.size()]; |
|
214 |
// allPoints.toArray(points); |
|
215 |
|
|
216 |
try { |
|
217 |
if (geometry.getGeometryType()==FShape.POINT || geometry instanceof FMultiPoint2D) { |
|
218 |
shape.generatePoint(points.length, points); |
|
219 |
} else if (geometry.getGeometryType()==FShape.LINE) { |
|
220 |
shape |
|
221 |
.generateLine(points.length, numParts, partOffsets, |
|
222 |
points); |
|
223 |
} else { |
|
224 |
shape.generatePolygon(points.length, numParts, partOffsets, |
|
225 |
points); |
|
226 |
} |
|
227 |
} catch (SeException e) { |
|
228 |
e.printStackTrace(); |
|
229 |
} |
|
230 |
|
|
231 |
return shape; |
|
232 |
} |
|
233 |
|
|
234 |
private static SDEPoint[] getPoints(IGeometry g) { |
|
235 |
// if (FConstant.SHAPE_TYPE_MULTIPOINTZ == m_type){ |
|
236 |
// zs=((IGeometry3D)g).getZs(); |
|
237 |
// } |
|
238 |
PathIterator theIterator = g.getPathIterator(null); //polyLine.getPathIterator(null, flatness); |
|
239 |
double[] theData = new double[6]; |
|
240 |
ArrayList ps=new ArrayList(); |
|
241 |
while (!theIterator.isDone()) { |
|
242 |
//while not done |
|
243 |
int theType = theIterator.currentSegment(theData); |
|
244 |
|
|
245 |
ps.add(new SDEPoint(theData[0], theData[1])); |
|
246 |
theIterator.next(); |
|
247 |
} //end while loop |
|
248 |
SDEPoint[] points = (SDEPoint[])ps.toArray(new SDEPoint[0]); |
|
249 |
return points; |
|
250 |
} |
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
163 | 255 |
/** |
164 | 256 |
* @throws SQLException |
165 |
*
|
|
257 |
* |
|
166 | 258 |
*/ |
167 | 259 |
public ArcSdeFeatureIterator(SeQuery query) { |
168 | 260 |
// Debe ser forward only |
... | ... | |
177 | 269 |
numColumns = row.getNumColumns(); |
178 | 270 |
regAtt = new Value[numColumns-1]; |
179 | 271 |
bFirst = true; |
272 |
SeColumnDefinition[] colDefs = row.getColumns(); |
|
273 |
for (int i=0; i<colDefs.length;i++){ |
|
274 |
if (colDefs[i].getName().equals("OBJECTID")){ |
|
275 |
index=i; |
|
276 |
} |
|
277 |
} |
|
180 | 278 |
} catch (SeException e) { |
181 | 279 |
// TODO Auto-generated catch block |
182 | 280 |
e.printStackTrace(); |
183 | 281 |
} |
184 | 282 |
} |
185 |
|
|
283 |
|
|
186 | 284 |
/* (non-Javadoc) |
187 | 285 |
* @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#hasNext() |
188 | 286 |
*/ |
189 |
public boolean hasNext() throws SQLException {
|
|
287 |
public boolean hasNext() throws DriverException {
|
|
190 | 288 |
try { |
191 | 289 |
if (bFirst) |
192 | 290 |
bFirst = false; |
... | ... | |
197 | 295 |
query.close(); |
198 | 296 |
return false; |
199 | 297 |
} |
200 |
|
|
298 |
|
|
201 | 299 |
return true; |
202 | 300 |
} |
203 |
catch (SeException e) {
|
|
204 |
e.printStackTrace();
|
|
301 |
catch (SeException e) { |
|
302 |
e.printStackTrace(); |
|
205 | 303 |
// throw new SQLException(e.getMessage()); |
206 | 304 |
} |
207 | 305 |
return false; |
... | ... | |
210 | 308 |
/* (non-Javadoc) |
211 | 309 |
* @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#next() |
212 | 310 |
*/ |
213 |
public IFeature next() throws SQLException {
|
|
311 |
public IFeature next() throws DriverException {
|
|
214 | 312 |
SeShape spVal = null; |
215 |
SeColumnDefinition[] colDefs = row.getColumns();
|
|
313 |
SeColumnDefinition[] colDefs = row.getColumns(); |
|
216 | 314 |
IFeature feat = null; |
217 | 315 |
try |
218 |
{ |
|
219 |
if ( row != null ) |
|
220 |
{ |
|
316 |
{ |
|
317 |
|
|
318 |
if ( row != null ) |
|
319 |
{ |
|
221 | 320 |
for (int colNum = 0; colNum < colDefs.length; colNum++) |
222 |
{
|
|
321 |
{ |
|
223 | 322 |
SeColumnDefinition colDef = colDefs[colNum]; |
224 | 323 |
int dataType = colDef.getType(); |
225 | 324 |
if ( row.getIndicator((short)colNum) != SeRow.SE_IS_NULL_VALUE) |
226 | 325 |
{ |
227 | 326 |
switch( dataType ) |
228 | 327 |
{ |
229 |
case SeColumnDefinition.TYPE_SMALLINT:
|
|
328 |
case SeColumnDefinition.TYPE_INT16:
|
|
230 | 329 |
regAtt[colNum-1] = ValueFactory.createValue(row.getShort(colNum).intValue()); |
231 |
break;
|
|
330 |
break; |
|
232 | 331 |
case SeColumnDefinition.TYPE_DATE: |
233 |
regAtt[colNum-1] = ValueFactory.createValue(row.getDate(colNum));
|
|
332 |
regAtt[colNum-1] = ValueFactory.createValue(row.getTime(colNum).getTime());
|
|
234 | 333 |
break; |
235 |
|
|
236 |
case SeColumnDefinition.TYPE_INTEGER: |
|
334 |
|
|
335 |
case SeColumnDefinition.TYPE_INT32: |
|
336 |
case SeColumnDefinition.TYPE_INT64: |
|
237 | 337 |
regAtt[colNum-1] = ValueFactory.createValue(row.getInteger(colNum).intValue()); |
238 | 338 |
break; |
239 |
|
|
240 |
case SeColumnDefinition.TYPE_FLOAT: |
|
339 |
|
|
340 |
case SeColumnDefinition.TYPE_FLOAT32:
|
|
241 | 341 |
regAtt[colNum-1] = ValueFactory.createValue(row.getFloat(colNum).floatValue()); |
242 | 342 |
break; |
243 |
|
|
244 |
case SeColumnDefinition.TYPE_DOUBLE:
|
|
343 |
|
|
344 |
case SeColumnDefinition.TYPE_FLOAT64:
|
|
245 | 345 |
regAtt[colNum-1] = ValueFactory.createValue(row.getDouble(colNum).doubleValue()); |
246 | 346 |
break; |
247 |
|
|
347 |
|
|
248 | 348 |
case SeColumnDefinition.TYPE_STRING: |
249 | 349 |
regAtt[colNum-1] = ValueFactory.createValue(row.getString(colNum)); |
250 | 350 |
break; |
251 |
|
|
351 |
|
|
252 | 352 |
case SeColumnDefinition.TYPE_SHAPE: |
253 |
spVal = row.getShape(colNum);
|
|
353 |
spVal = row.getShape(colNum); |
|
254 | 354 |
geom = getGeometry(spVal); |
255 | 355 |
break; |
256 | 356 |
} // End switch |
257 | 357 |
} // End if |
258 | 358 |
} // for |
259 |
// System.out.println("Dentro de next(): " + spVal.getFeatureId().toString() + " " + regAtt[0]);
|
|
260 |
|
|
261 |
feat = new DefaultFeature(geom, regAtt, "" + spVal.getFeatureId().longValue());
|
|
359 |
//System.out.println("Dentro de next(): " + spVal.getFeatureId().longValue() + " " + regAtt[0]);
|
|
360 |
|
|
361 |
feat = new DefaultFeature(geom, regAtt,String.valueOf(regAtt[index-1]));//""+ spVal.getFeatureId().longValue());
|
|
262 | 362 |
} // if |
263 | 363 |
|
264 |
|
|
364 |
|
|
265 | 365 |
} catch (SeException e) |
266 | 366 |
{ |
267 | 367 |
e.printStackTrace(); |
268 | 368 |
} |
269 |
|
|
270 |
|
|
369 |
|
|
370 |
|
|
271 | 371 |
return feat; |
272 | 372 |
} |
273 | 373 |
|
374 |
public void closeIterator() throws DriverException { |
|
375 |
try { |
|
376 |
bFirst=false; |
|
377 |
query.close(); |
|
378 |
} catch (SeException e) { |
|
379 |
// TODO Auto-generated catch block |
|
380 |
e.printStackTrace(); |
|
381 |
} |
|
382 |
|
|
383 |
} |
|
384 |
|
|
274 | 385 |
} |
Also available in: Unified diff