Revision 10942
branches/v10/extensions/extSDE/config/config.xml | ||
---|---|---|
7 | 7 |
description="Support to access SDE" |
8 | 8 |
active="true" |
9 | 9 |
priority="1"> |
10 |
</extension>
|
|
10 |
</extension> |
|
11 | 11 |
</extensions> |
12 | 12 |
</plugin-config> |
branches/v10/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/SDELayerDefinition.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers.sde; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* SDE Layer definition. |
|
8 |
* @author Vicente Caballero Navarro |
|
9 |
*/ |
|
10 |
public class SDELayerDefinition extends DBLayerDefinition { |
|
11 |
/** |
|
12 |
* @uml.property name="host" |
|
13 |
*/ |
|
14 |
private String host; |
|
15 |
/** |
|
16 |
* @uml.property name="port" |
|
17 |
*/ |
|
18 |
private String port; |
|
19 |
/** |
|
20 |
* @uml.property name="schema" |
|
21 |
*/ |
|
22 |
private String schema; |
|
23 |
/** |
|
24 |
* @uml.property name="user" |
|
25 |
*/ |
|
26 |
private String user; |
|
27 |
private String pwd; |
|
28 |
/** |
|
29 |
* @uml.property name="connectionName" |
|
30 |
*/ |
|
31 |
private String connectionName; |
|
32 |
|
|
33 |
public SDELayerDefinition() { |
|
34 |
System.out.println("SDE Layer Definition"); |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* @param dbHost |
|
39 |
* @uml.property name="host" |
|
40 |
*/ |
|
41 |
public void setHost(String dbHost) { |
|
42 |
this.host = dbHost; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* @return |
|
47 |
* @uml.property name="host" |
|
48 |
*/ |
|
49 |
public String getHost() { |
|
50 |
return host; |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* @param port |
|
55 |
* @uml.property name="port" |
|
56 |
*/ |
|
57 |
public void setPort(String port) { |
|
58 |
this.port = port; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* @return |
|
63 |
* @uml.property name="port" |
|
64 |
*/ |
|
65 |
public String getPort() { |
|
66 |
return port; |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* @param schema |
|
71 |
* @uml.property name="schema" |
|
72 |
*/ |
|
73 |
public void setSchema(String schema) { |
|
74 |
this.schema = schema; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* @return |
|
79 |
* @uml.property name="schema" |
|
80 |
*/ |
|
81 |
public String getSchema() { |
|
82 |
return schema; |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* @param user |
|
87 |
* @uml.property name="user" |
|
88 |
*/ |
|
89 |
public void setUser(String user) { |
|
90 |
this.user = user; |
|
91 |
} |
|
92 |
|
|
93 |
public void setPassword(String pwd) { |
|
94 |
this.pwd = pwd; |
|
95 |
} |
|
96 |
|
|
97 |
public String getPassword() { |
|
98 |
return pwd; |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* @return |
|
103 |
* @uml.property name="user" |
|
104 |
*/ |
|
105 |
public String getUser() { |
|
106 |
return user; |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* @param connectionName |
|
111 |
* @uml.property name="connectionName" |
|
112 |
*/ |
|
113 |
public void setConnectionName(String connectionName) { |
|
114 |
this.connectionName = connectionName; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* @return |
|
119 |
* @uml.property name="connectionName" |
|
120 |
*/ |
|
121 |
public String getConnectionName() { |
|
122 |
return connectionName; |
|
123 |
} |
|
124 |
} |
|
0 | 125 |
branches/v10/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/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 |
} |
branches/v10/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/testSDE.java | ||
---|---|---|
2 | 2 |
* Created on 13-may-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 |
*/ |
... | ... | |
57 | 57 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
58 | 58 |
|
59 | 59 |
public class testSDE { |
60 |
public static void main(String[] args)
|
|
61 |
{
|
|
60 |
public static void main(String[] args) |
|
61 |
{ |
|
62 | 62 |
// Conexi?n: |
63 | 63 |
SeConnection conn = null; |
64 |
String server = "alvaro";
|
|
64 |
String server = "192.168.0.114";
|
|
65 | 65 |
int instance = 5151; |
66 |
String database = "sigespa";
|
|
66 |
String database = "ProvinciasPruebas";
|
|
67 | 67 |
String user = "sde"; |
68 |
String password = "sde";
|
|
68 |
String password = "iver";
|
|
69 | 69 |
try { |
70 |
conn = new SeConnection(server, instance, database, user, password);
|
|
70 |
conn = new SeConnection(server, instance, database, user, password); |
|
71 | 71 |
}catch (SeException e) { |
72 | 72 |
e.printStackTrace(); |
73 | 73 |
return; |
74 |
}
|
|
75 |
|
|
74 |
} |
|
75 |
|
|
76 | 76 |
// Fetching data |
77 | 77 |
|
78 |
String layerName = "vias";
|
|
78 |
String layerName = "EJES";
|
|
79 | 79 |
SeObjectId layerID = null; |
80 | 80 |
String strSpatialColumn = ""; |
81 | 81 |
try { |
... | ... | |
83 | 83 |
for (int i=0; i < theLayers.size(); i++) |
84 | 84 |
{ |
85 | 85 |
SeLayer layer = (SeLayer)theLayers.elementAt(i); |
86 |
if (layer.getName().compareToIgnoreCase(layerName) == 0 ); |
|
87 |
{ |
|
86 |
if (layer.getName().equals(layerName)){ |
|
88 | 87 |
layerID = layer.getID(); |
89 | 88 |
strSpatialColumn = layer.getSpatialColumn(); |
90 |
|
|
89 |
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 |
// } |
|
102 |
} |
|
91 | 103 |
} |
92 | 104 |
} |
93 | 105 |
if (layerID == null) |
... | ... | |
95 | 107 |
System.err.println("Capa no encontrada"); |
96 | 108 |
return; |
97 | 109 |
} |
98 |
|
|
110 |
|
|
99 | 111 |
SeLayer layer = new SeLayer( conn, layerName, strSpatialColumn ); |
100 | 112 |
SeSqlConstruct sqlConstruct = new SeSqlConstruct( layerName); |
101 | 113 |
long t1 = System.currentTimeMillis(); |
102 | 114 |
// Create a query stream between the client and server |
103 | 115 |
String[] cols = new String[2]; |
104 |
cols[0] = new String("RD_5");
|
|
105 |
cols[1] = layer.getSpatialColumn();
|
|
116 |
cols[0] = new String("FID");
|
|
117 |
cols[1] = layer.getSpatialColumn(); |
|
106 | 118 |
SeQuery query = new SeQuery( conn, cols, sqlConstruct ); |
107 | 119 |
query.prepareQuery(); |
108 | 120 |
query.execute(); |
109 | 121 |
long t2 = System.currentTimeMillis(); |
110 |
|
|
122 |
|
|
111 | 123 |
System.out.println("Tiempo de consulta:" + (t2 - t1) + " milisegundos"); |
112 | 124 |
t1 = System.currentTimeMillis(); |
113 | 125 |
int cont = 0; |
114 | 126 |
SeRow row = query.fetch(); |
115 | 127 |
if( row == null ) { |
116 |
|
|
128 |
|
|
117 | 129 |
System.out.println(" No rows fetched"); |
118 | 130 |
return; |
119 | 131 |
} |
120 | 132 |
// String rowID = "2"; |
121 |
|
|
133 |
|
|
122 | 134 |
// Get the definitions of all the columns retrieved |
123 | 135 |
SeColumnDefinition[] colDefs = row.getColumns(); |
124 | 136 |
while (row != null) |
... | ... | |
128 | 140 |
cont++; |
129 | 141 |
} |
130 | 142 |
// Close the query. |
131 |
|
|
143 |
|
|
132 | 144 |
query.close(); |
133 | 145 |
t2 = System.currentTimeMillis(); |
134 | 146 |
|
135 | 147 |
System.out.println("Tiempo de recorrido:" + (t2 - t1) + " milisegundos. " + cont + " registros."); |
136 | 148 |
|
137 |
/* SeQuery extentQuery = new SeQuery( conn, cols, sqlConstruct );
|
|
138 |
SeQueryInfo queryInfo = new SeQueryInfo();
|
|
149 |
/* SeQuery extentQuery = new SeQuery( conn, cols, sqlConstruct ); |
|
150 |
SeQueryInfo queryInfo = new SeQueryInfo(); |
|
139 | 151 |
queryInfo.setConstruct(sqlConstruct); |
140 | 152 |
// queryInfo.setQueryType(SeQueryInfo.SE_QUERYTYPE_JFA); |
141 | 153 |
// query.prepareQueryInfo(queryInfo); |
142 |
|
|
154 |
|
|
143 | 155 |
SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo); |
144 | 156 |
extentQuery.close(); |
145 | 157 |
System.out.println(seExtent.toString()); |
146 |
|
|
147 |
|
|
158 |
|
|
159 |
|
|
148 | 160 |
SeQuery queryAux; |
149 | 161 |
t1 = System.currentTimeMillis(); |
150 |
// queryAux = new SeQuery( conn, cols, sqlConstruct );
|
|
162 |
// queryAux = new SeQuery( conn, cols, sqlConstruct ); |
|
151 | 163 |
for (int i=0; i < 250; i++) |
152 | 164 |
{ |
153 | 165 |
queryAux = new SeQuery( conn, cols, sqlConstruct ); |
154 | 166 |
SeObjectId rowID = new SeObjectId(i+1); |
155 | 167 |
row = queryAux.fetchRow("provin", rowID, cols); |
156 |
|
|
168 |
|
|
157 | 169 |
evaluateRow(row, colDefs); |
158 | 170 |
queryAux.close(); |
159 | 171 |
} |
160 | 172 |
// queryAux.close(); |
161 | 173 |
t2 = System.currentTimeMillis(); |
162 | 174 |
System.out.println("Tiempo de recorrido:" + (t2 - t1) + " milisegundos. "); */ |
163 |
|
|
175 |
|
|
164 | 176 |
/* queryAux = new SeQuery( conn, cols, sqlConstruct ); |
165 | 177 |
SeObjectId rowID = new SeObjectId(1); |
166 |
row = queryAux.fetchRow("provin", rowID, cols);
|
|
178 |
row = queryAux.fetchRow("provin", rowID, cols); |
|
167 | 179 |
evaluateRow(row, colDefs); |
168 |
row = queryAux.fetch();
|
|
180 |
row = queryAux.fetch(); |
|
169 | 181 |
evaluateRow(row, colDefs); |
170 |
|
|
182 |
|
|
171 | 183 |
queryAux.close(); */ |
172 |
|
|
184 |
|
|
173 | 185 |
} catch( SeException e ) { |
174 | 186 |
System.out.println(e.getSeError().getErrDesc()); |
175 | 187 |
} |
176 | 188 |
|
177 |
|
|
189 |
|
|
178 | 190 |
} |
179 | 191 |
|
180 | 192 |
static GeneralPathX convertSeShapeToGeneralPathX(SeShape spVal) throws SeException |
... | ... | |
186 | 198 |
for( int partNo = 0 ; partNo < points.length ; partNo++) |
187 | 199 |
{ |
188 | 200 |
bStartPart = true; |
189 |
for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++)
|
|
201 |
for( int subPartNo = 0 ; subPartNo < points[partNo].length ; subPartNo++) |
|
190 | 202 |
for( int pointNo = 0 ; pointNo < points[partNo][subPartNo].length ; pointNo+=2) |
191 | 203 |
{ |
192 | 204 |
if (bStartPart) |
... | ... | |
200 | 212 |
points[partNo][subPartNo][(pointNo+1)]); |
201 | 213 |
|
202 | 214 |
} |
203 |
}
|
|
215 |
} |
|
204 | 216 |
return gpx; |
205 | 217 |
} |
206 | 218 |
static void evaluateRow(SeRow row, SeColumnDefinition[] colDefs) |
... | ... | |
208 | 220 |
try |
209 | 221 |
{ |
210 | 222 |
for (int colNum = 0; colNum < colDefs.length; colNum++) |
211 |
{
|
|
223 |
{ |
|
212 | 224 |
SeColumnDefinition colDef = colDefs[colNum]; |
213 | 225 |
int dataType = colDef.getType(); |
214 | 226 |
if ( row.getIndicator((short)colNum) != SeRow.SE_IS_NULL_VALUE) |
... | ... | |
217 | 229 |
{ |
218 | 230 |
case SeColumnDefinition.TYPE_SMALLINT: |
219 | 231 |
break; |
220 |
|
|
232 |
|
|
221 | 233 |
case SeColumnDefinition.TYPE_DATE: |
222 | 234 |
break; |
223 |
|
|
235 |
|
|
224 | 236 |
case SeColumnDefinition.TYPE_INTEGER: |
225 | 237 |
break; |
226 |
|
|
238 |
|
|
227 | 239 |
case SeColumnDefinition.TYPE_FLOAT: |
228 | 240 |
break; |
229 |
|
|
241 |
|
|
230 | 242 |
case SeColumnDefinition.TYPE_DOUBLE: |
231 | 243 |
break; |
232 |
|
|
244 |
|
|
233 | 245 |
case SeColumnDefinition.TYPE_STRING: |
234 | 246 |
// System.out.println(row.getString(colNum)); |
235 | 247 |
break; |
236 |
|
|
248 |
|
|
237 | 249 |
case SeColumnDefinition.TYPE_SHAPE: |
238 | 250 |
SeShape spVal = row.getShape(colNum); |
239 | 251 |
convertSeShapeToGeneralPathX(spVal); |
branches/v10/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/ArcSdeDriver.java | ||
---|---|---|
2 | 2 |
* Created on 13-may-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 |
*/ |
... | ... | |
45 | 45 |
|
46 | 46 |
import java.awt.geom.Rectangle2D; |
47 | 47 |
import java.io.IOException; |
48 |
import java.sql.Connection; |
|
48 | 49 |
import java.sql.Types; |
49 | 50 |
import java.util.Hashtable; |
50 | 51 |
import java.util.Vector; |
... | ... | |
63 | 64 |
import com.esri.sde.sdk.client.SeShapeFilter; |
64 | 65 |
import com.esri.sde.sdk.client.SeSqlConstruct; |
65 | 66 |
import com.esri.sde.sdk.client.SeTable; |
66 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
|
|
67 |
import com.hardcode.gdbms.engine.data.DataSourceFactory;
|
|
67 | 68 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
68 | 69 |
import com.hardcode.gdbms.engine.values.Value; |
69 | 70 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
70 | 71 |
import com.iver.cit.gvsig.fmap.DriverException; |
72 |
import com.iver.cit.gvsig.fmap.DriverJdbcNotFoundExceptionType; |
|
73 |
import com.iver.cit.gvsig.fmap.Messages; |
|
71 | 74 |
import com.iver.cit.gvsig.fmap.core.FShape; |
75 |
import com.iver.cit.gvsig.fmap.core.ICanReproject; |
|
72 | 76 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
73 | 77 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
78 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
|
74 | 79 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
75 | 80 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
76 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
|
81 |
import com.iver.cit.gvsig.fmap.drivers.VectorialSDEDriver; |
|
82 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
|
83 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
|
84 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
85 |
import com.iver.utiles.XMLEntity; |
|
86 |
import com.iver.utiles.swing.JPasswordDlg; |
|
77 | 87 |
|
78 |
public class ArcSdeDriver implements VectorialDatabaseDriver, ObjectDriver { |
|
79 | 88 |
|
89 |
/** |
|
90 |
* Driver of ArcSDE. |
|
91 |
* @author Vicente Caballero Navarro |
|
92 |
* @uml.dependency supplier="com.iver.cit.gvsig.fmap.drivers.sde.ArcSdeFeatureIterator" |
|
93 |
* @uml.dependency supplier="com.iver.cit.gvsig.fmap.drivers.sde.SDELayerDefinition" |
|
94 |
*/ |
|
95 |
public class ArcSdeDriver implements ICanReproject, IWriteable, |
|
96 |
VectorialSDEDriver { |
|
97 |
protected static Hashtable poolPassw = new Hashtable(); |
|
80 | 98 |
private SeLayer layer; |
81 | 99 |
private SeQuery query; |
82 | 100 |
private SeQuery queryAux; |
... | ... | |
84 | 102 |
private SeColumnDefinition[] colDefs; |
85 | 103 |
private SeRow row = null; |
86 | 104 |
private int numReg = -1; |
105 |
/** |
|
106 |
* @uml.property name="fullExtent" |
|
107 |
*/ |
|
87 | 108 |
private Rectangle2D fullExtent = null; |
88 | 109 |
private Hashtable hashRelate = null; |
89 | 110 |
private int idSpatialColumn = -1; |
111 |
/** |
|
112 |
* @uml.property name="fields" |
|
113 |
*/ |
|
90 | 114 |
private String[] fields; |
91 | 115 |
private int[] fieldTypes; |
92 | 116 |
private long lastRowServed = -1; |
93 | 117 |
private SeConnection conn = null; |
118 |
private String strEPSG; |
|
119 |
private String originalEPSG = null; |
|
94 | 120 |
/** |
95 |
* Recorre el recordset creando una tabla Hash que usaremos para |
|
96 |
* relacionar el n?mero de un registro con su identificador ?nico. |
|
97 |
* Debe ser llamado en el setData justo despu?s de crear el recorset |
|
98 |
* principal |
|
121 |
* @uml.property name="sqlTotal" |
|
122 |
*/ |
|
123 |
private String sqlTotal; |
|
124 |
private long posActual = -1; |
|
125 |
private SeRow cachedRow = null; |
|
126 |
/** |
|
127 |
* @uml.property name="lyrDef" |
|
128 |
*/ |
|
129 |
protected SDELayerDefinition lyrDef = null; |
|
130 |
/** |
|
131 |
* @uml.property name="workingArea" |
|
132 |
*/ |
|
133 |
protected Rectangle2D workingArea; |
|
134 |
protected String driverClass; |
|
135 |
protected String className; |
|
136 |
protected String catalogName; |
|
137 |
|
|
138 |
/** |
|
139 |
* Recorre el recordset creando una tabla Hash que usaremos para relacionar |
|
140 |
* el n?mero de un registro con su identificador ?nico. Debe ser llamado |
|
141 |
* en el setData justo despu?s de crear el recorset principal |
|
99 | 142 |
*/ |
100 |
private void doRelateID_FID() |
|
101 |
{ |
|
143 |
protected void doRelateID_FID() { |
|
102 | 144 |
hashRelate = new Hashtable(); |
145 |
|
|
103 | 146 |
try { |
104 |
// query.execute(); |
|
105 |
// row = query.fetch(); |
|
106 |
if( row == null ) { |
|
107 |
|
|
147 |
if (row == null) { |
|
108 | 148 |
System.out.println(" No rows fetched"); |
149 |
|
|
109 | 150 |
return; |
110 | 151 |
} |
152 |
|
|
111 | 153 |
int index = 0; |
112 |
while( row != null ) |
|
113 |
{
|
|
154 |
|
|
155 |
while (row != null) {
|
|
114 | 156 |
SeShape shpVal = row.getShape(idSpatialColumn); |
115 | 157 |
SeObjectId objID = shpVal.getFeatureId(); |
116 | 158 |
String theKey = "" + objID.longValue(); |
117 |
// System.out.println("Antes de meter en el hash " + theKey); |
|
118 | 159 |
hashRelate.put(theKey, new Integer(index)); |
119 | 160 |
row = query.fetch(); |
120 | 161 |
index++; |
121 |
} |
|
162 |
} |
|
163 |
|
|
122 | 164 |
numReg = index; |
123 |
// Close the query. |
|
124 |
// query.close(); |
|
125 |
} catch (SeException e) |
|
126 |
{ |
|
165 |
} catch (SeException e) { |
|
127 | 166 |
e.printStackTrace(); |
128 | 167 |
} |
129 |
|
|
130 | 168 |
} |
131 |
|
|
132 |
public void setData(String host, int port, String db, String userDB, String pwdDB, |
|
133 |
String tableName, String[] cols, |
|
134 |
String whereClause) |
|
135 |
{ |
|
136 |
// Conexi?n: |
|
137 |
|
|
138 |
String server = host; |
|
139 |
int instance = port; |
|
140 |
String database = db; |
|
141 |
String user = userDB; |
|
142 |
String password = pwdDB; |
|
143 |
try { |
|
144 |
conn = new SeConnection(server, instance, database, user, password); |
|
145 |
}catch (SeException e) { |
|
146 |
e.printStackTrace(); |
|
147 |
return; |
|
148 |
} |
|
149 |
|
|
150 |
// Fetching data |
|
151 |
|
|
152 |
String layerName = tableName; |
|
153 |
SeObjectId layerID = null; |
|
154 |
String strSpatialColumn = ""; |
|
155 |
try { |
|
156 |
Vector theLayers = conn.getLayers(); |
|
157 |
for (int i=0; i < theLayers.size(); i++) |
|
158 |
{ |
|
159 |
SeLayer layer = (SeLayer)theLayers.elementAt(i); |
|
160 |
if (layer.getName().compareToIgnoreCase(layerName) == 0 ); |
|
161 |
{ |
|
162 |
layerID = layer.getID(); |
|
163 |
strSpatialColumn = layer.getSpatialColumn(); |
|
164 |
} |
|
165 |
} |
|
166 |
if (layerID == null) |
|
167 |
{ |
|
168 |
System.err.println("Capa no encontrada"); |
|
169 |
return; |
|
170 |
} |
|
171 |
// layerName = layer.getName(); |
|
172 |
layer = new SeLayer( conn, layerName, strSpatialColumn ); |
|
173 |
|
|
174 |
if (cols != null) |
|
175 |
this.fields = cols; |
|
176 |
else |
|
177 |
{ |
|
178 |
SeSqlConstruct sqlConstruct = new SeSqlConstruct( tableName ); |
|
179 |
SeTable table1 = new SeTable(conn, tableName ); |
|
180 |
/* |
|
181 |
* Get the table's column definition. |
|
182 |
*/ |
|
183 |
SeColumnDefinition[] tableDef = table1.describe(); |
|
184 |
this.fields = new String[tableDef.length]; |
|
185 |
|
|
186 |
/* |
|
187 |
* Store the names of all the table's columns in the |
|
188 |
* String array cols. This array specifies the columns |
|
189 |
* to be retrieved from the database. |
|
190 |
*/ |
|
191 |
int idField=1; |
|
192 |
for( int i = 0 ; i < tableDef.length ; i++ ) { |
|
193 |
if (tableDef[i].getType() == SeColumnDefinition.TYPE_SHAPE) |
|
194 |
{ |
|
195 |
this.fields[0] = tableDef[i].getName(); |
|
196 |
} |
|
197 |
else |
|
198 |
{ |
|
199 |
this.fields[idField] = tableDef[i].getName(); |
|
200 |
idField++; |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
|
|
206 |
sqlConstruct = new SeSqlConstruct( layerName); |
|
207 |
// Create a query stream between the client and server |
|
208 |
|
|
209 |
query = new SeQuery( conn, fields, sqlConstruct ); |
|
210 |
query.prepareQuery(); |
|
211 |
query.execute(); |
|
212 |
row = query.fetch(); |
|
213 |
if (row == null) |
|
214 |
{ |
|
215 |
System.out.println("La tabla " + getName() + " no tiene registros"); |
|
216 |
return; |
|
217 |
} |
|
218 |
|
|
219 |
colDefs = row.getColumns(); |
|
220 |
fieldTypes = new int[colDefs.length-1]; |
|
221 |
for (int colNum = 0; colNum < colDefs.length; colNum++) |
|
222 |
{ |
|
223 |
SeColumnDefinition colDef = colDefs[colNum]; |
|
224 |
int dataType = colDef.getType(); |
|
225 |
if (dataType == SeColumnDefinition.TYPE_SHAPE) |
|
226 |
{ |
|
227 |
if (colNum != 0) |
|
228 |
{ |
|
229 |
System.err.println("Por favor, el campo de shapes deber ser el primero"); |
|
230 |
return; |
|
231 |
} |
|
232 |
idSpatialColumn = colNum; |
|
233 |
} |
|
234 |
if (dataType == SeColumnDefinition.TYPE_STRING) |
|
235 |
fieldTypes[colNum-1] = Types.VARCHAR; |
|
236 |
if (dataType == SeColumnDefinition.TYPE_FLOAT) |
|
237 |
fieldTypes[colNum-1] = Types.FLOAT; |
|
238 |
if (dataType == SeColumnDefinition.TYPE_DOUBLE) |
|
239 |
fieldTypes[colNum-1] = Types.DOUBLE; |
|
240 |
if (dataType == SeColumnDefinition.TYPE_INTEGER) |
|
241 |
fieldTypes[colNum-1] = Types.INTEGER; |
|
242 |
if (dataType == SeColumnDefinition.TYPE_SMALLINT) |
|
243 |
fieldTypes[colNum-1] = Types.INTEGER; |
|
244 |
if (dataType == SeColumnDefinition.TYPE_DATE) |
|
245 |
fieldTypes[colNum-1] = Types.DATE; |
|
246 |
|
|
247 |
} |
|
248 |
// query.close(); |
|
249 |
SeQuery extentQuery = new SeQuery( conn, fields, sqlConstruct ); |
|
250 |
SeQueryInfo queryInfo = new SeQueryInfo(); |
|
251 |
queryInfo.setConstruct(sqlConstruct); |
|
252 |
// queryInfo.setQueryType(SeQueryInfo.SE_QUERYTYPE_JFA); |
|
253 |
// extentQuery.prepareQueryInfo(queryInfo); |
|
254 |
|
|
255 |
SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo); |
|
256 |
fullExtent = new Rectangle2D.Double( |
|
257 |
seExtent.getMinX(), seExtent.getMinY(), |
|
258 |
seExtent.getMaxX()- seExtent.getMinX(), |
|
259 |
seExtent.getMaxY()- seExtent.getMinY()); |
|
260 |
extentQuery.close(); |
|
261 |
|
|
262 |
doRelateID_FID(); |
|
263 |
|
|
264 |
} |
|
265 |
catch (SeException e) |
|
266 |
{ |
|
267 |
e.printStackTrace(); |
|
268 |
} |
|
269 |
|
|
270 |
|
|
271 |
} |
|
272 |
|
|
169 |
/** |
|
170 |
* @return |
|
171 |
* @uml.property name="fullExtent" |
|
172 |
*/ |
|
273 | 173 |
public Rectangle2D getFullExtent() { |
274 |
return fullExtent; |
|
275 |
} |
|
276 |
|
|
277 |
public int getShapeType() { |
|
278 |
// TODO Auto-generated method stub |
|
279 |
int shapeType = -1; |
|
280 |
switch (layer.getShapeTypes()) |
|
281 |
{ |
|
282 |
case SeLayer.TYPE_POINT: |
|
283 |
shapeType = FShape.POINT; |
|
284 |
break; |
|
285 |
case SeLayer.TYPE_LINE: |
|
286 |
case SeLayer.TYPE_MULTI_LINE: |
|
287 |
case SeLayer.TYPE_MULTI_SIMPLE_LINE: |
|
288 |
shapeType = FShape.LINE; |
|
289 |
break; |
|
290 |
case SeLayer.TYPE_POLYGON: |
|
291 |
case SeLayer.TYPE_MULTI_POLYGON: |
|
292 |
shapeType = FShape.POLYGON; |
|
293 |
break; |
|
294 |
|
|
295 |
} |
|
296 |
return FShape.MULTI; |
|
297 |
} |
|
298 |
|
|
174 |
return fullExtent; |
|
175 |
} |
|
299 | 176 |
public IGeometry getShape(int index) { |
300 | 177 |
SeRow row; |
178 |
|
|
301 | 179 |
try { |
302 | 180 |
row = obtainRow(index); |
181 |
|
|
303 | 182 |
SeShape spVal = row.getShape(idSpatialColumn); |
304 | 183 |
IGeometry geom = ArcSdeFeatureIterator.getGeometry(spVal); |
305 |
// queryAux.close(); |
|
306 | 184 |
return geom; |
307 | 185 |
} catch (SeException e) { |
308 |
// TODO Auto-generated catch block |
|
309 | 186 |
e.printStackTrace(); |
310 | 187 |
} |
311 |
return null;
|
|
188 |
return null; |
|
312 | 189 |
} |
313 | 190 |
|
314 | 191 |
public IFeatureIterator getFeatureIterator(String sql) |
315 |
throws DriverException { |
|
316 |
// TODO Auto-generated method stub |
|
192 |
throws DriverException { |
|
317 | 193 |
return null; |
318 | 194 |
} |
319 | 195 |
|
320 | 196 |
public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) |
321 |
throws DriverException {
|
|
197 |
throws DriverException { |
|
322 | 198 |
/* |
323 | 199 |
* Generate a rectangular shape that will be used as a filter |
324 | 200 |
*/ |
325 | 201 |
try { |
326 | 202 |
SeShape shape = new SeShape(layer.getCoordRef()); |
327 |
|
|
328 |
SeExtent extent = new SeExtent( r.getMinX(),
|
|
329 |
r.getMinY(),r.getMaxX(),r.getMaxY());
|
|
203 |
|
|
204 |
SeExtent extent = new SeExtent(r.getMinX(), r.getMinY(),
|
|
205 |
r.getMaxX(), r.getMaxY());
|
|
330 | 206 |
shape.generateRectangle(extent); |
331 |
|
|
207 |
|
|
332 | 208 |
SeShape[] shapes = new SeShape[1]; |
333 | 209 |
shapes[0] = shape; |
334 |
|
|
210 |
|
|
335 | 211 |
/* |
336 | 212 |
* Retrieve all the shapes that are contained within the |
337 | 213 |
* rectangles envelope. |
338 | 214 |
*/ |
339 |
SeShapeFilter filters[] = new SeShapeFilter[1];
|
|
215 |
SeShapeFilter[] filters = new SeShapeFilter[1];
|
|
340 | 216 |
SeShapeFilter filter = null; |
341 |
|
|
342 |
filter = new SeShapeFilter( layer.getName(), layer.getSpatialColumn(), shape, SeFilter.METHOD_ENVP); |
|
217 |
|
|
218 |
filter = new SeShapeFilter(layer.getName(), |
|
219 |
layer.getSpatialColumn(), shape, SeFilter.METHOD_ENVP); |
|
343 | 220 |
filters[0] = filter; |
344 |
|
|
221 |
|
|
345 | 222 |
SeQuery spatialQuery = null; |
346 |
SeSqlConstruct sqlCons = new SeSqlConstruct( layer.getName() );
|
|
347 |
|
|
223 |
SeSqlConstruct sqlCons = new SeSqlConstruct(layer.getName());
|
|
224 |
|
|
348 | 225 |
spatialQuery = new SeQuery(conn, fields, sqlCons); |
226 |
|
|
349 | 227 |
/* |
350 | 228 |
* Set spatial constraints |
351 | 229 |
*/ |
352 |
spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, filters); |
|
230 |
spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, |
|
231 |
filters); |
|
353 | 232 |
|
354 | 233 |
spatialQuery.prepareQuery(); |
355 |
|
|
234 |
|
|
356 | 235 |
spatialQuery.execute(); |
357 |
|
|
236 |
|
|
358 | 237 |
return new ArcSdeFeatureIterator(spatialQuery); |
359 | 238 |
} catch (SeException e) { |
360 |
// TODO Auto-generated catch block |
|
361 | 239 |
e.printStackTrace(); |
362 | 240 |
return null; |
363 | 241 |
} |
364 |
|
|
365 | 242 |
} |
366 | 243 |
|
367 |
|
|
368 | 244 |
public void close() { |
369 |
// TODO Auto-generated method stub |
|
370 |
|
|
371 | 245 |
} |
372 | 246 |
|
373 | 247 |
public void open() throws DriverException { |
374 |
// TODO Auto-generated method stub |
|
375 |
|
|
376 | 248 |
} |
377 | 249 |
|
378 | 250 |
public int getRowIndexByFID(IFeature FID) { |
379 | 251 |
int resul; |
380 | 252 |
String strID = FID.getID(); |
381 |
// System.out.println("Recuperando " + strID + " del hash"); |
|
382 | 253 |
Integer rowIndex = (Integer) hashRelate.get(strID); |
383 |
if (rowIndex == null) |
|
384 |
{ |
|
385 |
System.err.println("Error: No se ha encontrado " + strID + " dentro del Hash"); |
|
254 |
|
|
255 |
if (rowIndex == null) { |
|
256 |
System.err.println("Error: No se ha encontrado " + strID + |
|
257 |
" dentro del Hash"); |
|
386 | 258 |
} |
387 | 259 |
resul = rowIndex.intValue(); |
388 | 260 |
return resul; |
... | ... | |
397 | 269 |
} |
398 | 270 |
|
399 | 271 |
public DriverAttributes getDriverAttributes() { |
400 |
// TODO Auto-generated method stub |
|
401 | 272 |
return null; |
402 | 273 |
} |
403 | 274 |
|
... | ... | |
405 | 276 |
return "ArcSDE driver"; |
406 | 277 |
} |
407 | 278 |
|
279 |
/** |
|
280 |
* @return |
|
281 |
* @uml.property name="fields" |
|
282 |
*/ |
|
408 | 283 |
public String[] getFields() { |
409 |
String[] attributes = new String[fields.length-1];
|
|
410 |
for (int i=1; i < fields.length; i++)
|
|
411 |
attributes[i-1] = fields[i];
|
|
412 |
return attributes;
|
|
413 |
}
|
|
284 |
String[] attributes = new String[fields.length - 1];
|
|
285 |
for (int i = 1; i < fields.length; i++)
|
|
286 |
attributes[i - 1] = fields[i];
|
|
287 |
return attributes;
|
|
288 |
}
|
|
414 | 289 |
|
415 |
public String getWhereClause() { |
|
416 |
// TODO Auto-generated method stub |
|
417 |
return ""; |
|
418 |
} |
|
419 |
|
|
420 | 290 |
public String getTableName() { |
421 | 291 |
return layer.getName(); |
422 | 292 |
} |
423 | 293 |
|
424 |
private SeRow obtainRow(long rowIndex) throws SeException |
|
425 |
{ |
|
426 |
if (rowIndex == 0) |
|
427 |
{ |
|
428 |
if (query != null) |
|
429 |
{ |
|
430 |
if (query.inProgress()) |
|
431 |
query.close(); |
|
294 |
private SeRow obtainRow(long rowIndex) throws SeException { |
|
295 |
if (rowIndex != posActual) { |
|
296 |
if (rowIndex == 0) { |
|
297 |
if (query != null) { |
|
298 |
if (query.inProgress()) { |
|
299 |
query.close(); |
|
300 |
} |
|
301 |
} |
|
302 |
query = new SeQuery(conn, fields, sqlConstruct); |
|
303 |
query.prepareQuery(); |
|
304 |
query.execute(); |
|
305 |
|
|
306 |
lastRowServed = -1; |
|
432 | 307 |
} |
433 |
query = new SeQuery( conn, fields, sqlConstruct ); |
|
434 |
query.prepareQuery(); |
|
435 |
query.execute(); |
|
436 |
|
|
437 |
lastRowServed = -1; |
|
308 |
|
|
309 |
if (lastRowServed == (rowIndex - 1)) { |
|
310 |
row = query.fetch(); |
|
311 |
lastRowServed++; |
|
312 |
} else { |
|
313 |
if (queryAux != null) { |
|
314 |
queryAux.close(); |
|
315 |
} |
|
316 |
|
|
317 |
queryAux = new SeQuery(conn, fields, sqlConstruct); |
|
318 |
|
|
319 |
SeObjectId rowID = new SeObjectId(rowIndex + 1); |
|
320 |
row = queryAux.fetchRow(layer.getName(), rowID, fields); |
|
321 |
} |
|
322 |
|
|
323 |
posActual = rowIndex; |
|
324 |
cachedRow = row; |
|
438 | 325 |
} |
439 |
if (lastRowServed == rowIndex-1) |
|
440 |
{ |
|
441 |
row = query.fetch(); |
|
442 |
lastRowServed++; |
|
443 |
} |
|
444 |
else |
|
445 |
{ |
|
446 |
if (queryAux != null) queryAux.close(); |
|
447 |
queryAux = new SeQuery( conn, fields, sqlConstruct ); |
|
448 |
SeObjectId rowID = new SeObjectId(rowIndex+1); |
|
449 |
row = queryAux.fetchRow(layer.getName(), rowID, fields); |
|
450 |
} |
|
451 |
// queryAux.close(); |
|
452 |
return row; |
|
453 |
|
|
454 |
|
|
326 |
|
|
327 |
return cachedRow; |
|
455 | 328 |
} |
456 |
public Value getFieldValue(long rowIndex, int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
329 |
|
|
330 |
public Value getFieldValue(long rowIndex, int fieldId) |
|
331 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
457 | 332 |
SeRow row; |
458 | 333 |
Value val = null; |
334 |
|
|
459 | 335 |
try { |
460 | 336 |
int idFieldArcSDE = fieldId + 1; // SIEMPRE CONTANDO CON |
461 |
// QUE NOS HAN PASADO EL PRIMER CAMPO EL DE SHAPE
|
|
337 |
// QUE NOS HAN PASADO EL PRIMER CAMPO EL DE SHAPE |
|
462 | 338 |
row = obtainRow(rowIndex); |
339 |
|
|
463 | 340 |
int dataType = colDefs[idFieldArcSDE].getType(); |
464 |
if ( dataType == SeColumnDefinition.TYPE_STRING) |
|
465 |
{ |
|
341 |
|
|
342 |
switch (dataType) { |
|
343 |
case SeColumnDefinition.TYPE_INT16: |
|
344 |
val = ValueFactory.createValue(row.getShort(idFieldArcSDE) |
|
345 |
.intValue()); |
|
346 |
|
|
347 |
break; |
|
348 |
|
|
349 |
case SeColumnDefinition.TYPE_INT32: |
|
350 |
case SeColumnDefinition.TYPE_INT64: |
|
351 |
val = ValueFactory.createValue(row.getInteger(idFieldArcSDE) |
|
352 |
.intValue()); |
|
353 |
|
|
354 |
break; |
|
355 |
|
|
356 |
case SeColumnDefinition.TYPE_FLOAT32: |
|
357 |
val = ValueFactory.createValue(row.getFloat(idFieldArcSDE) |
|
358 |
.floatValue()); |
|
359 |
|
|
360 |
break; |
|
361 |
|
|
362 |
case SeColumnDefinition.TYPE_FLOAT64: |
|
363 |
val = ValueFactory.createValue(row.getDouble(idFieldArcSDE) |
|
364 |
.doubleValue()); |
|
365 |
|
|
366 |
break; |
|
367 |
|
|
368 |
case SeColumnDefinition.TYPE_DATE: |
|
369 |
val = ValueFactory.createValue(row.getTime(idFieldArcSDE) |
|
370 |
.getTime()); |
|
371 |
|
|
372 |
break; |
|
373 |
|
|
374 |
default: |
|
375 |
|
|
466 | 376 |
String strAux = row.getString(idFieldArcSDE); |
467 |
if (strAux == null) strAux = ""; |
|
468 |
val = ValueFactory.createValue(strAux); |
|
377 |
|
|
378 |
if (strAux == null) { |
|
379 |
strAux = ""; |
|
380 |
} |
|
381 |
|
|
382 |
val = ValueFactory.createValue(strAux); |
|
383 |
|
|
384 |
break; |
|
469 | 385 |
} |
470 |
if (dataType == SeColumnDefinition.TYPE_FLOAT) |
|
471 |
{ |
|
472 |
val = ValueFactory.createValue(row.getFloat(idFieldArcSDE).floatValue()); |
|
473 |
} |
|
474 |
if (dataType == SeColumnDefinition.TYPE_DOUBLE) |
|
475 |
{ |
|
476 |
val = ValueFactory.createValue(row.getDouble(idFieldArcSDE).doubleValue()); |
|
477 |
} |
|
478 |
if (dataType == SeColumnDefinition.TYPE_INTEGER) |
|
479 |
{ |
|
480 |
val = ValueFactory.createValue(row.getInteger(idFieldArcSDE).intValue()); |
|
481 |
} |
|
482 |
if (dataType == SeColumnDefinition.TYPE_SMALLINT) |
|
483 |
{ |
|
484 |
val = ValueFactory.createValue(row.getShort(idFieldArcSDE).intValue()); |
|
485 |
} |
|
486 |
|
|
487 |
if (dataType == SeColumnDefinition.TYPE_DATE) |
|
488 |
{ |
|
489 |
val = ValueFactory.createValue(row.getDate(idFieldArcSDE)); |
|
490 |
} |
|
491 |
// queryAux.close(); |
|
386 |
|
|
492 | 387 |
return val; |
493 |
|
|
494 | 388 |
} catch (SeException e) { |
495 |
// TODO Auto-generated catch block |
|
496 | 389 |
e.printStackTrace(); |
497 |
|
|
498 | 390 |
} |
499 |
|
|
391 |
|
|
500 | 392 |
return ValueFactory.createNullValue(); |
501 | 393 |
} |
502 | 394 |
|
503 |
public int getFieldCount() throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
504 |
return fields.length-1; |
|
395 |
public int getFieldCount() |
|
396 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
397 |
return fields.length - 1; |
|
505 | 398 |
} |
506 | 399 |
|
507 |
public String getFieldName(int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
|
508 |
// System.out.println("En ArcSdeDriver: getFieldName(" + fieldId + ")=" + fields[fieldId+1]);
|
|
509 |
return fields[fieldId+1];
|
|
400 |
public String getFieldName(int fieldId) |
|
401 |
throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
|
402 |
return fields[fieldId + 1];
|
|
510 | 403 |
} |
511 | 404 |
|
512 |
public long getRowCount() throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
|
405 |
public long getRowCount() { |
|
513 | 406 |
return numReg; |
514 | 407 |
} |
515 | 408 |
|
516 |
public int getFieldType(int i) throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
409 |
public int getFieldType(int i) |
|
410 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
517 | 411 |
return fieldTypes[i]; |
518 | 412 |
} |
519 | 413 |
|
520 | 414 |
/** |
521 | 415 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys() |
522 | 416 |
*/ |
523 |
public int[] getPrimaryKeys() throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
417 |
public int[] getPrimaryKeys() |
|
418 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
524 | 419 |
throw new UnsupportedOperationException(); |
525 | 420 |
} |
526 | 421 |
|
527 | 422 |
/** |
528 | 423 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare) |
529 | 424 |
*/ |
530 |
public void write(DataWare arg0) throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
425 |
public void write(DataWare arg0) |
|
426 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
427 |
} |
|
428 |
|
|
429 |
public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG, |
|
430 |
String[] alphaNumericFieldsNeeded) throws DriverException { |
|
431 |
/* |
|
432 |
* Generate a rectangular shape that will be used as a filter |
|
433 |
*/ |
|
434 |
try { |
|
435 |
SeShape shape = new SeShape(layer.getCoordRef()); |
|
436 |
|
|
437 |
SeExtent extent = new SeExtent(r.getMinX(), r.getMinY(), |
|
438 |
r.getMaxX(), r.getMaxY()); |
|
439 |
shape.generateRectangle(extent); |
|
440 |
|
|
441 |
SeShape[] shapes = new SeShape[1]; |
|
442 |
shapes[0] = shape; |
|
443 |
|
|
444 |
/* |
|
445 |
* Retrieve all the shapes that are contained within the |
|
446 |
* rectangles envelope. |
|
447 |
*/ |
|
448 |
SeShapeFilter[] filters = new SeShapeFilter[1]; |
|
449 |
SeShapeFilter filter = null; |
|
450 |
|
|
451 |
filter = new SeShapeFilter(layer.getName(), |
|
452 |
layer.getSpatialColumn(), shape, SeFilter.METHOD_ENVP); |
|
453 |
filters[0] = filter; |
|
454 |
|
|
455 |
SeQuery spatialQuery = null; |
|
456 |
SeSqlConstruct sqlCons = new SeSqlConstruct(layer.getName()); |
|
457 |
|
|
458 |
spatialQuery = new SeQuery(conn, fields, sqlCons); |
|
459 |
|
|
460 |
/* |
|
461 |
* Set spatial constraints |
|
462 |
*/ |
|
463 |
spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, |
|
464 |
filters); |
|
465 |
|
|
466 |
spatialQuery.prepareQuery(); |
|
467 |
|
|
468 |
spatialQuery.execute(); |
Also available in: Unified diff