svn-gvsig-desktop / branches / Fmap_GisPlanet / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / arcsde / ArcSdeFeatureIterator.java @ 1940
History | View | Annotate | Download (8.69 KB)
1 |
/*
|
---|---|
2 |
* Created on 11-mar-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.arcsde; |
45 |
|
46 |
import java.awt.geom.GeneralPath; |
47 |
import java.sql.ResultSet; |
48 |
import java.sql.ResultSetMetaData; |
49 |
import java.sql.SQLException; |
50 |
import java.sql.Types; |
51 |
|
52 |
import com.esri.sde.sdk.client.SeColumnDefinition; |
53 |
import com.esri.sde.sdk.client.SeException; |
54 |
import com.esri.sde.sdk.client.SeQuery; |
55 |
import com.esri.sde.sdk.client.SeRow; |
56 |
import com.esri.sde.sdk.client.SeShape; |
57 |
import com.esri.sde.sdk.geom.SePoint; |
58 |
import com.hardcode.gdbms.engine.values.Value; |
59 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
60 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
61 |
import com.iver.cit.gvsig.fmap.core.FNullGeometry; |
62 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
63 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
64 |
import com.iver.cit.gvsig.fmap.core.FShape; |
65 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
66 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
67 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
68 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
69 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
70 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser; |
71 |
|
72 |
/**
|
73 |
* @author FJP
|
74 |
*
|
75 |
* TODO To change the template for this generated type comment go to
|
76 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
77 |
*/
|
78 |
public class ArcSdeFeatureIterator implements IFeatureIterator { |
79 |
IGeometry geom; |
80 |
int numColumns;
|
81 |
private SeQuery query = null; |
82 |
private boolean bFirst; |
83 |
Value[] regAtt;
|
84 |
SeRow row; |
85 |
|
86 |
|
87 |
public static IGeometry getGeometry( SeShape shape ) { |
88 |
|
89 |
try {
|
90 |
/*
|
91 |
* Retrieve the shape type.
|
92 |
*/
|
93 |
int type = -1; |
94 |
type = shape.getType(); |
95 |
|
96 |
// Display the X and Y values
|
97 |
/* for( int partNo = 0 ; partNo < points.length ; partNo++, System.out.println("") )
|
98 |
for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++, System.out.println("") )
|
99 |
for( int pointNo = 0 ; pointNo < points[partNo][subPartNo].length ; pointNo+=2)
|
100 |
System.out.println("X: " + points[partNo][subPartNo][pointNo] + "\tY: "
|
101 |
+ points[partNo][subPartNo][(pointNo+1)] ); */
|
102 |
switch( type )
|
103 |
{ |
104 |
case SeShape.TYPE_POINT:
|
105 |
double[][][] points = shape.getAllCoords(); |
106 |
FPoint2D p = new FPoint2D(points[0][0][0],points[0][0][1]); |
107 |
return ShapeFactory.createPoint2D(p);
|
108 |
|
109 |
case SeShape.TYPE_LINE:
|
110 |
case SeShape.TYPE_MULTI_LINE:
|
111 |
case SeShape.TYPE_MULTI_SIMPLE_LINE:
|
112 |
case SeShape.TYPE_SIMPLE_LINE:
|
113 |
GeneralPathX gpx = new GeneralPathX(shape.toGeneralPath());
|
114 |
return ShapeFactory.createPolyline2D(gpx);
|
115 |
|
116 |
case SeShape.TYPE_MULTI_POINT:
|
117 |
break;
|
118 |
|
119 |
case SeShape.TYPE_NIL:
|
120 |
return new FNullGeometry(); |
121 |
case SeShape.TYPE_POLYGON:
|
122 |
case SeShape.TYPE_MULTI_POLYGON:
|
123 |
GeneralPathX gpx2 = new GeneralPathX(shape.toGeneralPath());
|
124 |
return ShapeFactory.createPolygon2D(gpx2);
|
125 |
} // End switch
|
126 |
} |
127 |
catch (SeException e)
|
128 |
{ |
129 |
e.printStackTrace(); |
130 |
} |
131 |
return new FNullGeometry(); |
132 |
} |
133 |
|
134 |
/**
|
135 |
* @throws SQLException
|
136 |
*
|
137 |
*/
|
138 |
public ArcSdeFeatureIterator(SeQuery query) {
|
139 |
// Debe ser forward only
|
140 |
this.query = query;
|
141 |
try {
|
142 |
row = query.fetch(); |
143 |
numColumns = row.getNumColumns(); |
144 |
regAtt = new Value[numColumns-1]; |
145 |
bFirst = true;
|
146 |
} catch (SeException e) {
|
147 |
// TODO Auto-generated catch block
|
148 |
e.printStackTrace(); |
149 |
} |
150 |
} |
151 |
|
152 |
/* (non-Javadoc)
|
153 |
* @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#hasNext()
|
154 |
*/
|
155 |
public boolean hasNext() throws SQLException { |
156 |
try {
|
157 |
if (!bFirst)
|
158 |
bFirst = false;
|
159 |
else
|
160 |
row = query.fetch(); |
161 |
if (row == null) |
162 |
{ |
163 |
query.close(); |
164 |
return false; |
165 |
} |
166 |
|
167 |
return true; |
168 |
} |
169 |
catch (SeException e) {
|
170 |
e.printStackTrace(); |
171 |
// throw new SQLException(e.getMessage());
|
172 |
} |
173 |
return false; |
174 |
} |
175 |
|
176 |
/* (non-Javadoc)
|
177 |
* @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#next()
|
178 |
*/
|
179 |
public IFeature next() throws SQLException { |
180 |
SeShape spVal = null;
|
181 |
SeColumnDefinition[] colDefs = row.getColumns();
|
182 |
IFeature feat = null;
|
183 |
try
|
184 |
{ |
185 |
if ( row != null ) |
186 |
{ |
187 |
for (int colNum = 0; colNum < colDefs.length; colNum++) |
188 |
{ |
189 |
SeColumnDefinition colDef = colDefs[colNum]; |
190 |
int dataType = colDef.getType();
|
191 |
if ( row.getIndicator((short)colNum) != SeRow.SE_IS_NULL_VALUE) |
192 |
{ |
193 |
switch( dataType )
|
194 |
{ |
195 |
case SeColumnDefinition.TYPE_SMALLINT:
|
196 |
regAtt[colNum-1] = ValueFactory.createValue(row.getShort(colNum).intValue());
|
197 |
break;
|
198 |
case SeColumnDefinition.TYPE_DATE:
|
199 |
regAtt[colNum-1] = ValueFactory.createValue(row.getDate(colNum));
|
200 |
break;
|
201 |
|
202 |
case SeColumnDefinition.TYPE_INTEGER:
|
203 |
regAtt[colNum-1] = ValueFactory.createValue(row.getInteger(colNum).intValue());
|
204 |
break;
|
205 |
|
206 |
case SeColumnDefinition.TYPE_FLOAT:
|
207 |
regAtt[colNum-1] = ValueFactory.createValue(row.getFloat(colNum).floatValue());
|
208 |
break;
|
209 |
|
210 |
case SeColumnDefinition.TYPE_DOUBLE:
|
211 |
regAtt[colNum-1] = ValueFactory.createValue(row.getDouble(colNum).doubleValue());
|
212 |
break;
|
213 |
|
214 |
case SeColumnDefinition.TYPE_STRING:
|
215 |
regAtt[colNum-1] = ValueFactory.createValue(row.getString(colNum));
|
216 |
break;
|
217 |
|
218 |
case SeColumnDefinition.TYPE_SHAPE:
|
219 |
spVal = row.getShape(colNum); |
220 |
geom = getGeometry(spVal); |
221 |
break;
|
222 |
} // End switch
|
223 |
} // End if
|
224 |
} // for
|
225 |
// System.out.println("Dentro de next(): " + spVal.getFeatureId().toString() + " " + regAtt[0]);
|
226 |
|
227 |
feat = new DefaultFeature(geom, regAtt, "" + spVal.getFeatureId().longValue()); |
228 |
} // if
|
229 |
|
230 |
|
231 |
} catch (SeException e)
|
232 |
{ |
233 |
e.printStackTrace(); |
234 |
} |
235 |
|
236 |
|
237 |
return feat;
|
238 |
} |
239 |
|
240 |
} |