Revision 1755
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/DEMO/PruebasGT2.java | ||
---|---|---|
127 | 127 |
String dburl = "jdbc:postgresql://localhost/latin1"; |
128 | 128 |
String dbuser = "postgres"; |
129 | 129 |
String dbpass = "aquilina"; |
130 |
String fields = "ASTEXT(force_2d(the_geom)) as the_geom";
|
|
130 |
String fields = "ASBINARY(the_geom, 'XDR') as the_geom";
|
|
131 | 131 |
String whereClause = ""; |
132 | 132 |
|
133 | 133 |
|
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/wizards/JDBCWizard.java | ||
---|---|---|
347 | 347 |
jPanel.setLayout(null); |
348 | 348 |
jLabel.setText("Usuario:"); |
349 | 349 |
jLabel.setName("jLabel"); |
350 |
jLabel.setSize(125, 19);
|
|
351 |
jLabel.setLocation(19, 12);
|
|
352 |
jLabel1.setBounds(19, 41, 112, 19);
|
|
350 |
jLabel.setSize(80, 19);
|
|
351 |
jLabel.setLocation(151, 12);
|
|
352 |
jLabel1.setBounds(149, 41, 82, 19);
|
|
353 | 353 |
jLabel1.setText("Contrase?a:"); |
354 |
jLabel2.setBounds(19, 67, 118, 20);
|
|
354 |
jLabel2.setBounds(121, 67, 110, 20);
|
|
355 | 355 |
jLabel2.setText("Nombre de la tabla:"); |
356 |
jLabel3.setBounds(19, 96, 205, 22);
|
|
356 |
jLabel3.setBounds(26, 96, 205, 22);
|
|
357 | 357 |
jLabel3.setText("Campos a recuperar (Primero the_geom):"); |
358 |
jLabel4.setBounds(19, 130, 212, 22);
|
|
358 |
jLabel4.setBounds(125, 130, 106, 22);
|
|
359 | 359 |
jLabel4.setText("Cl?usula Where:"); |
360 | 360 |
jPanel.add(jLabel, null); |
361 | 361 |
jPanel.add(getJTxtUser(), null); |
... | ... | |
380 | 380 |
jTxtUser = new JTextField(); |
381 | 381 |
jTxtUser.setName("jTextField"); |
382 | 382 |
jTxtUser.setColumns(0); |
383 |
jTxtUser.setBounds(226, 12, 184, 19); |
|
383 |
jTxtUser.setBounds(241, 12, 169, 19); |
|
384 |
jTxtUser.setText("postgres"); |
|
384 | 385 |
jTxtUser.addFocusListener(new java.awt.event.FocusListener() { |
385 | 386 |
public void focusLost(java.awt.event.FocusEvent e) { |
386 | 387 |
listenerSupport.callStateChanged(true); |
... | ... | |
399 | 400 |
private JPasswordField getJTxtPassword() { |
400 | 401 |
if (jTxtPassword == null) { |
401 | 402 |
jTxtPassword = new JPasswordField(); |
402 |
jTxtPassword.setBounds(225, 39, 185, 20);
|
|
403 |
jTxtPassword.setBounds(241, 39, 169, 20);
|
|
403 | 404 |
} |
404 | 405 |
return jTxtPassword; |
405 | 406 |
} |
... | ... | |
411 | 412 |
private JTextField getJTxtNomTabla() { |
412 | 413 |
if (jTxtNomTabla == null) { |
413 | 414 |
jTxtNomTabla = new JTextField(); |
414 |
jTxtNomTabla.setBounds(223, 66, 187, 20);
|
|
415 |
jTxtNomTabla.setBounds(241, 66, 169, 20);
|
|
415 | 416 |
} |
416 | 417 |
return jTxtNomTabla; |
417 | 418 |
} |
... | ... | |
423 | 424 |
private JTextField getJTxtSqlFields() { |
424 | 425 |
if (jTxtSqlFields == null) { |
425 | 426 |
jTxtSqlFields = new JTextField(); |
426 |
jTxtSqlFields.setBounds(239, 96, 171, 24);
|
|
427 |
jTxtSqlFields.setText("ASTEXT(the_geom), AREA, etc");
|
|
427 |
jTxtSqlFields.setBounds(241, 96, 169, 24);
|
|
428 |
jTxtSqlFields.setText("ASBINARY(the_geom, 'XDR')");
|
|
428 | 429 |
} |
429 | 430 |
return jTxtSqlFields; |
430 | 431 |
} |
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/selectionByTheme/MySelectionByThemeListener.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.cit.gvsig.gui.selectionByTheme; |
42 | 42 |
|
43 |
import java.util.BitSet; |
|
44 |
|
|
45 | 43 |
import com.iver.andami.messages.NotificationManager; |
46 | 44 |
import com.iver.cit.gvsig.fmap.DriverException; |
47 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
|
48 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
49 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
|
50 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
51 | 45 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
52 | 46 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
53 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
54 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
|
55 | 47 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
56 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
|
57 | 48 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
58 | 49 |
import com.iver.cit.gvsig.fmap.operations.strategies.QueryByThemeVisitor; |
59 | 50 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
60 |
import com.vividsolutions.jts.geom.Geometry; |
|
61 |
import com.vividsolutions.jts.geom.IntersectionMatrix; |
|
62 | 51 |
|
63 | 52 |
|
64 | 53 |
/** |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/VectorialDatabaseDriver.java | ||
---|---|---|
58 | 58 |
public String getFields(); |
59 | 59 |
public String getWhereClause(); |
60 | 60 |
public String getTableName(); |
61 |
public void close(); |
|
61 | 62 |
|
62 | 63 |
|
63 | 64 |
} |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/WKBParser.java | ||
---|---|---|
1 |
/* |
|
2 |
* WKBParser.java |
|
3 |
* Based in |
|
4 |
* PostGIS extension for PostgreSQL JDBC driver - Binary Parser |
|
5 |
* |
|
6 |
* NOTA: Es posible que lo mejor sea crear un PostGisGeometry que implemente |
|
7 |
* la interfaz IGeometry, y as? nos sirve de base para tener IGeometries |
|
8 |
* que encapsulan otras posibles geometr?as. Por ejemplo, un JTSGeometry. |
|
9 |
* De esta forma, un driver no necesitar?a reescribirse. |
|
10 |
* |
|
11 |
* (C) 2005 Markus Schaber, schabios@logi-track.com |
|
12 |
* |
|
13 |
* This library is free software; you can redistribute it and/or modify it under |
|
14 |
* the terms of the GNU Lesser General Public License as published by the Free |
|
15 |
* Software Foundation, either version 2.1 of the License. |
|
16 |
* |
|
17 |
* This library is distributed in the hope that it will be useful, but WITHOUT |
|
18 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
19 |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
20 |
* details. |
|
21 |
* |
|
22 |
* You should have received a copy of the GNU Lesser General Public License |
|
23 |
* along with this library; if not, write to the Free Software Foundation, Inc., |
|
24 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at |
|
25 |
* http://www.gnu.org. |
|
26 |
* |
|
27 |
* $Id$ |
|
28 |
*/ |
|
29 |
package com.iver.cit.gvsig.fmap.drivers; |
|
30 |
|
|
31 |
import org.postgis.Geometry; |
|
32 |
import org.postgis.GeometryCollection; |
|
33 |
import org.postgis.LineString; |
|
34 |
import org.postgis.LinearRing; |
|
35 |
import org.postgis.MultiLineString; |
|
36 |
import org.postgis.MultiPoint; |
|
37 |
import org.postgis.MultiPolygon; |
|
38 |
import org.postgis.Point; |
|
39 |
import org.postgis.Polygon; |
|
40 |
import org.postgis.binary.ByteGetter; |
|
41 |
import org.postgis.binary.ValueGetter; |
|
42 |
import org.postgis.binary.ByteGetter.BinaryByteGetter; |
|
43 |
import org.postgis.binary.ByteGetter.StringByteGetter; |
|
44 |
|
|
45 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
|
46 |
import com.iver.cit.gvsig.fmap.core.FMultiPoint2D; |
|
47 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
48 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
|
49 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
|
50 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
|
51 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
52 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
53 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
54 |
|
|
55 |
/** |
|
56 |
* Parse binary representation of geometries. Currently, only text rep (hexed) |
|
57 |
* implementation is tested. |
|
58 |
* |
|
59 |
* It should be easy to add char[] and CharSequence ByteGetter instances, |
|
60 |
* although the latter one is not compatible with older jdks. |
|
61 |
* |
|
62 |
* I did not implement real unsigned 32-bit integers or emulate them with long, |
|
63 |
* as both java Arrays and Strings currently can have only 2^31-1 elements |
|
64 |
* (bytes), so we cannot even get or build Geometries with more than approx. |
|
65 |
* 2^28 coordinates (8 bytes each). |
|
66 |
* |
|
67 |
* @author markus.schaber@logi-track.com |
|
68 |
* |
|
69 |
*/ |
|
70 |
public class WKBParser { |
|
71 |
|
|
72 |
private boolean gHaveM, gHaveZ, gHaveS; // M, Z y SRID |
|
73 |
/** |
|
74 |
* Get the appropriate ValueGetter for my endianness |
|
75 |
* |
|
76 |
* @param bytes The appropriate Byte Getter |
|
77 |
* |
|
78 |
* @return the ValueGetter |
|
79 |
*/ |
|
80 |
public static ValueGetter valueGetterForEndian(ByteGetter bytes) { |
|
81 |
if (bytes.get(0) == ValueGetter.XDR.NUMBER) { // XDR |
|
82 |
return new ValueGetter.XDR(bytes); |
|
83 |
} else if (bytes.get(0) == ValueGetter.NDR.NUMBER) { |
|
84 |
return new ValueGetter.NDR(bytes); |
|
85 |
} else { |
|
86 |
throw new IllegalArgumentException("Unknown Endian type:" + bytes.get(0)); |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Parse a hex encoded geometry |
|
92 |
* |
|
93 |
* Is synchronized to protect offset counter. (Unfortunately, Java does not |
|
94 |
* have neither call by reference nor multiple return values.) |
|
95 |
*/ |
|
96 |
public synchronized IGeometry parse(String value) { |
|
97 |
StringByteGetter bytes = new ByteGetter.StringByteGetter(value); |
|
98 |
return parseGeometry(valueGetterForEndian(bytes)); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Parse a binary encoded geometry. |
|
103 |
* |
|
104 |
* Is synchronized to protect offset counter. (Unfortunately, Java does not |
|
105 |
* have neither call by reference nor multiple return values.) |
|
106 |
*/ |
|
107 |
public synchronized IGeometry parse(byte[] value) { |
|
108 |
BinaryByteGetter bytes = new ByteGetter.BinaryByteGetter(value); |
|
109 |
return parseGeometry(valueGetterForEndian(bytes)); |
|
110 |
} |
|
111 |
|
|
112 |
protected void parseTypeAndSRID(ValueGetter data) |
|
113 |
{ |
|
114 |
byte endian = data.getByte(); //skip and test endian flag |
|
115 |
if (endian != data.endian) { |
|
116 |
throw new IllegalArgumentException("Endian inconsistency!"); |
|
117 |
} |
|
118 |
int typeword = data.getInt(); |
|
119 |
|
|
120 |
int realtype = typeword & 0x1FFFFFFF; //cut off high flag bits |
|
121 |
|
|
122 |
gHaveZ = (typeword & 0x80000000) != 0; |
|
123 |
gHaveM = (typeword & 0x40000000) != 0; |
|
124 |
gHaveS = (typeword & 0x20000000) != 0; |
|
125 |
|
|
126 |
int srid = -1; |
|
127 |
|
|
128 |
if (gHaveS) { |
|
129 |
srid = data.getInt(); |
|
130 |
} |
|
131 |
|
|
132 |
} |
|
133 |
|
|
134 |
/** Parse a geometry starting at offset. */ |
|
135 |
protected IGeometry parseGeometry(ValueGetter data) { |
|
136 |
byte endian = data.getByte(); //skip and test endian flag |
|
137 |
if (endian != data.endian) { |
|
138 |
throw new IllegalArgumentException("Endian inconsistency!"); |
|
139 |
} |
|
140 |
int typeword = data.getInt(); |
|
141 |
|
|
142 |
int realtype = typeword & 0x1FFFFFFF; //cut off high flag bits |
|
143 |
|
|
144 |
boolean haveZ = (typeword & 0x80000000) != 0; |
|
145 |
boolean haveM = (typeword & 0x40000000) != 0; |
|
146 |
boolean haveS = (typeword & 0x20000000) != 0; |
|
147 |
|
|
148 |
int srid = -1; |
|
149 |
|
|
150 |
if (haveS) { |
|
151 |
srid = data.getInt(); |
|
152 |
} |
|
153 |
IGeometry result1; |
|
154 |
switch (realtype) { |
|
155 |
case Geometry.POINT : |
|
156 |
result1 = ShapeFactory.createPoint2D(parsePoint(data, haveZ, haveM)); |
|
157 |
break; |
|
158 |
case Geometry.LINESTRING : |
|
159 |
result1 = ShapeFactory.createGeometry(parseLineString(data, haveZ, haveM)); |
|
160 |
break; |
|
161 |
case Geometry.POLYGON : |
|
162 |
result1 = ShapeFactory.createGeometry(parsePolygon(data, haveZ, haveM)); |
|
163 |
break; |
|
164 |
case Geometry.MULTIPOINT : |
|
165 |
result1 = parseMultiPoint(data); |
|
166 |
break; |
|
167 |
case Geometry.MULTILINESTRING : |
|
168 |
result1 = ShapeFactory.createGeometry(parseMultiLineString(data)); |
|
169 |
break; |
|
170 |
case Geometry.MULTIPOLYGON : |
|
171 |
result1 = ShapeFactory.createGeometry(parseMultiPolygon(data)); |
|
172 |
break; |
|
173 |
case Geometry.GEOMETRYCOLLECTION : |
|
174 |
result1 = parseCollection(data); |
|
175 |
break; |
|
176 |
default : |
|
177 |
throw new IllegalArgumentException("Unknown Geometry Type!"); |
|
178 |
} |
|
179 |
|
|
180 |
/*Geometry result = result1; |
|
181 |
|
|
182 |
if (haveS) { |
|
183 |
result.setSrid(srid); |
|
184 |
} */ |
|
185 |
return result1; |
|
186 |
} |
|
187 |
|
|
188 |
private FPoint2D parsePoint(ValueGetter data, boolean haveZ, boolean haveM) { |
|
189 |
double X = data.getDouble(); |
|
190 |
double Y = data.getDouble(); |
|
191 |
FPoint2D result; |
|
192 |
if (haveZ) { |
|
193 |
double Z = data.getDouble(); |
|
194 |
result = new FPoint3D(X, Y, Z); |
|
195 |
} else { |
|
196 |
result = new FPoint2D(X, Y); |
|
197 |
} |
|
198 |
|
|
199 |
if (haveM) { |
|
200 |
System.err.println("M no soportado. (WKBParser de gvSIG, dentro de parsePoint)"); |
|
201 |
double m = data.getDouble(); |
|
202 |
// result.setM(m); |
|
203 |
} |
|
204 |
|
|
205 |
return result; |
|
206 |
} |
|
207 |
|
|
208 |
/** Parse an Array of "full" Geometries */ |
|
209 |
private void parseGeometryArray(ValueGetter data, IGeometry[] container) { |
|
210 |
for (int i = 0; i < container.length; i++) { |
|
211 |
container[i] = parseGeometry(data); |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
215 |
/** |
|
216 |
* Parse an Array of "slim" Points (without endianness and type, part of |
|
217 |
* LinearRing and Linestring, but not MultiPoint! |
|
218 |
* |
|
219 |
* @param haveZ |
|
220 |
* @param haveM |
|
221 |
*/ |
|
222 |
private FPoint2D[] parsePointArray(ValueGetter data, boolean haveZ, boolean haveM) { |
|
223 |
int count = data.getInt(); |
|
224 |
FPoint2D[] result = new FPoint2D[count]; |
|
225 |
for (int i = 0; i < count; i++) { |
|
226 |
result[i] = parsePoint(data, haveZ, haveM); |
|
227 |
} |
|
228 |
return result; |
|
229 |
} |
|
230 |
|
|
231 |
private FMultiPoint2D parseMultiPoint(ValueGetter data) { |
|
232 |
FPoint2D[] points = new FPoint2D[data.getInt()]; |
|
233 |
for (int i=0; i < points.length; i++) |
|
234 |
{ |
|
235 |
parseTypeAndSRID(data); |
|
236 |
parsePoint(data, gHaveZ, gHaveM); |
|
237 |
} |
|
238 |
return new FMultiPoint2D(points); |
|
239 |
} |
|
240 |
|
|
241 |
private FPolyline2D parseLineString(ValueGetter data, boolean haveZ, boolean haveM) { |
|
242 |
FPoint2D[] points = parsePointArray(data, haveZ, haveM); |
|
243 |
GeneralPathX gp = new GeneralPathX(); |
|
244 |
gp.moveTo(points[0].getX(), points[0].getY()); |
|
245 |
for (int i = 1; i< points.length; i++) |
|
246 |
{ |
|
247 |
gp.lineTo(points[i].getX(), points[i].getY()); |
|
248 |
} |
|
249 |
return new FPolyline2D(gp); |
|
250 |
} |
|
251 |
|
|
252 |
private FPolygon2D parseLinearRing(ValueGetter data, boolean haveZ, boolean haveM) { |
|
253 |
FPoint2D[] points = parsePointArray(data, haveZ, haveM); |
|
254 |
GeneralPathX gp = new GeneralPathX(); |
|
255 |
gp.moveTo(points[0].getX(), points[0].getY()); |
|
256 |
for (int i = 1; i< points.length; i++) |
|
257 |
{ |
|
258 |
gp.lineTo(points[i].getX(), points[i].getY()); |
|
259 |
} |
|
260 |
return new FPolygon2D(gp); |
|
261 |
} |
|
262 |
|
|
263 |
private FPolygon2D parsePolygon(ValueGetter data, boolean haveZ, boolean haveM) { |
|
264 |
int count = data.getInt(); |
|
265 |
FPolygon2D[] rings = new FPolygon2D[count]; |
|
266 |
for (int i = 0; i < count; i++) { |
|
267 |
rings[i] = parseLinearRing(data, haveZ, haveM); |
|
268 |
} |
|
269 |
return rings[0]; //new FPolygon2D(rings[0]); |
|
270 |
} |
|
271 |
|
|
272 |
private FPolyline2D parseMultiLineString(ValueGetter data) { |
|
273 |
int count = data.getInt(); |
|
274 |
FPolyline2D[] strings = new FPolyline2D[count]; |
|
275 |
for (int i=0; i < strings.length; i++) |
|
276 |
{ |
|
277 |
parseTypeAndSRID(data); |
|
278 |
strings[i] = parseLineString(data, gHaveZ, gHaveM); |
|
279 |
} |
|
280 |
|
|
281 |
// parseGeometryArray(data, strings); |
|
282 |
return strings[0]; //new MultiLineString(strings); |
|
283 |
} |
|
284 |
|
|
285 |
private FPolygon2D parseMultiPolygon(ValueGetter data) { |
|
286 |
int count = data.getInt(); |
|
287 |
FPolygon2D[] polys = new FPolygon2D[count]; |
|
288 |
for (int i=0; i < polys.length; i++) |
|
289 |
{ |
|
290 |
parseTypeAndSRID(data); |
|
291 |
polys[i] = parsePolygon(data, gHaveZ, gHaveM); |
|
292 |
} |
|
293 |
|
|
294 |
// parseGeometryArray(data, polys); |
|
295 |
return polys[0]; //new MultiPolygon(polys); |
|
296 |
} |
|
297 |
|
|
298 |
private FGeometryCollection parseCollection(ValueGetter data) { |
|
299 |
int count = data.getInt(); |
|
300 |
IGeometry[] geoms = new IGeometry[count]; |
|
301 |
parseGeometryArray(data, geoms); |
|
302 |
return new FGeometryCollection(geoms); |
|
303 |
} |
|
304 |
} |
|
0 | 305 |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/DefaultDBDriver.java | ||
---|---|---|
79 | 79 |
protected String fields; |
80 | 80 |
protected String sqlOrig; |
81 | 81 |
protected ResultSet rs; |
82 |
protected boolean bCursorActivo = false; |
|
83 |
protected Statement st; |
|
82 | 84 |
protected int numReg=-1; |
83 | 85 |
|
84 | 86 |
protected ResultSetMetaData metaData = null; |
... | ... | |
271 | 273 |
return -1; |
272 | 274 |
} |
273 | 275 |
|
276 |
public void close() |
|
277 |
{ |
|
278 |
try { |
|
279 |
if (bCursorActivo) |
|
280 |
{ |
|
281 |
st.execute("CLOSE wkb_cursor"); |
|
282 |
bCursorActivo = false; |
|
283 |
} |
|
284 |
} catch (SQLException e) { |
|
285 |
// TODO Auto-generated catch block |
|
286 |
e.printStackTrace(); |
|
287 |
} |
|
288 |
} |
|
274 | 289 |
|
275 | 290 |
} |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/jdbc/mysql/MySQLdriver.java | ||
---|---|---|
146 | 146 |
this.sqlOrig = "SELECT " + fields + " FROM " + tableName + " " + whereClause; |
147 | 147 |
try { |
148 | 148 |
st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
149 |
st.setFetchSize(5000);
|
|
149 |
st.setFetchSize(500); |
|
150 | 150 |
rs = st.executeQuery(sqlOrig); |
151 | 151 |
fetch_min = 0; |
152 | 152 |
fetch_max = rs.getFetchSize(); |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/testPostGis.java | ||
---|---|---|
49 | 49 |
import java.sql.Statement; |
50 | 50 |
import java.util.Enumeration; |
51 | 51 |
|
52 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
53 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser; |
|
52 | 54 |
|
55 |
|
|
53 | 56 |
/** |
54 | 57 |
* @author FJP |
55 | 58 |
* |
... | ... | |
71 | 74 |
String dbuser = "postgres"; |
72 | 75 |
String dbpass = "aquilina"; |
73 | 76 |
|
74 |
String dbtable = "jdbc_test";
|
|
77 |
String dbtable = "vias";
|
|
75 | 78 |
|
76 | 79 |
java.sql.Connection conn; |
77 | 80 |
try |
... | ... | |
101 | 104 |
/* |
102 | 105 |
* Create a statement and execute a select query. |
103 | 106 |
*/ |
104 |
String strSQL = "select ASBINARY(the_geom) as geom from vias";
|
|
107 |
String strSQL = "select ASBINARY(the_geom) as geom from " + dbtable;
|
|
105 | 108 |
/* String strSQL = "SELECT gid, rd_3, rd_5, rd_6, rd_10, rd_11, rd_12, rd_13, rd_14,"; |
106 | 109 |
strSQL = strSQL + " rd_15, rd_16, kilometers, cost, metros, AsText(force_2d(the_geom)) FROM vias"; |
107 | 110 |
strSQL = strSQL + " WHERE TRUE"; |
108 | 111 |
*/ |
109 | 112 |
// PreparedStatement s = conn.prepareStatement(strSQL); |
110 | 113 |
long t1 = System.currentTimeMillis(); |
111 |
Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
|
112 |
s.setFetchSize(20000); |
|
113 |
ResultSet r = s.executeQuery(strSQL); |
|
114 |
Statement s = conn.createStatement(); |
|
115 |
// s.execute("begin"); |
|
116 |
|
|
117 |
// Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
|
118 |
s.setFetchSize(2000); |
|
119 |
s.execute("declare wkb_cursor binary cursor for " + strSQL); |
|
120 |
ResultSet r = s.executeQuery("fetch forward all in wkb_cursor"); |
|
121 |
|
|
122 |
// ResultSet r = s.executeQuery(strSQL); |
|
114 | 123 |
long t2 = System.currentTimeMillis(); |
115 | 124 |
|
116 | 125 |
System.out.println("Tiempo de consulta:" + (t2 - t1) + " milisegundos"); |
117 | 126 |
t1 = System.currentTimeMillis(); |
127 |
WKBParser parser = new WKBParser(); |
|
118 | 128 |
while( r.next() ) |
119 | 129 |
{ |
120 | 130 |
/* |
121 | 131 |
* Retrieve the geometry as an object then cast it to the geometry type. |
122 | 132 |
* Print things out. |
123 | 133 |
*/ |
124 |
Object obj = r.getObject(1); |
|
125 |
// InputStream inS = r.getAsciiStream(1); |
|
134 |
// Object obj = r.getObject(1); |
|
135 |
byte[] arrayByte = r.getBytes(1); |
|
136 |
IGeometry gp = parser.parse(arrayByte); |
|
126 | 137 |
// String strAux = r.getString(1); |
127 | 138 |
// int id = r.getInt(2); |
128 | 139 |
// System.out.println("Row " + id + ":"); |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisGeometryIterator.java | ||
---|---|---|
45 | 45 |
|
46 | 46 |
import java.sql.ResultSet; |
47 | 47 |
import java.sql.SQLException; |
48 |
import java.sql.Statement; |
|
48 | 49 |
|
49 | 50 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
51 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser; |
|
50 | 52 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator; |
51 | 53 |
import com.vividsolutions.jts.io.ParseException; |
52 | 54 |
|
... | ... | |
57 | 59 |
* Window - Preferences - Java - Code Generation - Code and Comments |
58 | 60 |
*/ |
59 | 61 |
public class PostGisGeometryIterator implements GeometryIterator { |
60 |
private WKTParser parser = new WKTParser();
|
|
62 |
private WKBParser parser = new WKBParser();
|
|
61 | 63 |
ResultSet rs; |
64 |
Statement st; |
|
62 | 65 |
String strAux; |
63 | 66 |
IGeometry geom; |
64 | 67 |
/** |
... | ... | |
74 | 77 |
* @see com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator#hasNext() |
75 | 78 |
*/ |
76 | 79 |
public boolean hasNext() throws SQLException { |
77 |
if (rs.isAfterLast())
|
|
80 |
try
|
|
78 | 81 |
{ |
79 |
rs.close(); |
|
80 |
return false; |
|
82 |
if (rs.isAfterLast()) |
|
83 |
{ |
|
84 |
rs.close(); |
|
85 |
return false; |
|
86 |
} |
|
87 |
else |
|
88 |
return true; |
|
81 | 89 |
} |
82 |
else |
|
83 |
return true; |
|
90 |
catch (Exception e) |
|
91 |
{ |
|
92 |
e.printStackTrace(); |
|
93 |
} |
|
94 |
return false; |
|
84 | 95 |
} |
85 | 96 |
|
86 | 97 |
/* (non-Javadoc) |
... | ... | |
88 | 99 |
*/ |
89 | 100 |
public IGeometry next() throws SQLException { |
90 | 101 |
rs.next(); |
91 |
strAux = rs.getString(1); |
|
92 |
try { |
|
93 |
geom = parser.read(strAux); |
|
94 |
} catch (ParseException e) { |
|
95 |
// TODO Auto-generated catch block |
|
96 |
e.printStackTrace(); |
|
97 |
} |
|
102 |
byte[] data = rs.getBytes(1); |
|
103 |
geom = parser.parse(data); |
|
98 | 104 |
return geom; |
99 | 105 |
} |
100 | 106 |
|
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java | ||
---|---|---|
68 | 68 |
private WKTParser parser = new WKTParser(); |
69 | 69 |
private int fetch_min=-1; |
70 | 70 |
private int fetch_max=-1; |
71 |
private Statement st; |
|
71 |
|
|
72 | 72 |
private Rectangle2D fullExtent = null; |
73 | 73 |
private String strAux; |
74 | 74 |
|
... | ... | |
147 | 147 |
try { |
148 | 148 |
st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
149 | 149 |
st.setFetchSize(5000); |
150 |
rs = st.executeQuery(sqlOrig); |
|
150 |
st.execute("declare wkb_cursor binary cursor for " + sqlOrig); |
|
151 |
rs = st.executeQuery("fetch forward all in wkb_cursor"); |
|
152 |
st.execute("BEGIN"); |
|
153 |
bCursorActivo = true; |
|
154 |
// rs = st.executeQuery(sqlOrig); |
|
151 | 155 |
fetch_min = 0; |
152 | 156 |
fetch_max = rs.getFetchSize(); |
153 |
metaData = rs.getMetaData(); |
|
157 |
metaData = rs.getMetaData();
|
|
154 | 158 |
} catch (SQLException e) { |
155 | 159 |
// TODO Auto-generated catch block |
156 | 160 |
e.printStackTrace(); |
... | ... | |
189 | 193 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getGeometryIterator(java.lang.String) |
190 | 194 |
*/ |
191 | 195 |
public GeometryIterator getGeometryIterator(String sql) throws com.iver.cit.gvsig.fmap.DriverException { |
192 |
Statement st; |
|
193 | 196 |
PostGisGeometryIterator geomIterator = null; |
194 | 197 |
try { |
195 | 198 |
st = conn.createStatement(); |
196 | 199 |
st.setFetchSize(2000); |
197 |
ResultSet rs = st.executeQuery(sql); |
|
200 |
if (bCursorActivo) |
|
201 |
close(); |
|
202 |
st.execute("declare wkb_cursor binary cursor for " + sql); |
|
203 |
ResultSet rs = st.executeQuery("fetch forward all in wkb_cursor"); |
|
204 |
// st.execute("BEGIN"); |
|
205 |
bCursorActivo = true; |
|
206 |
// ResultSet rs = st.executeQuery(sql); |
|
198 | 207 |
geomIterator = new PostGisGeometryIterator(rs); |
199 | 208 |
} catch (SQLException e) { |
200 | 209 |
e.printStackTrace(); |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/DefaultStrategy.java | ||
---|---|---|
153 | 153 |
rsSel.start(); |
154 | 154 |
|
155 | 155 |
int sc; |
156 |
long t1 = System.currentTimeMillis(); |
|
157 | 156 |
Rectangle2D extent = viewPort.getAdjustedExtent(); |
158 | 157 |
AffineTransform at = viewPort.getAffineTransform(); |
159 | 158 |
|
... | ... | |
205 | 204 |
if (rsSel != null) |
206 | 205 |
rsSel.stop(); |
207 | 206 |
|
208 |
long t2 = System.currentTimeMillis(); |
|
207 |
|
|
209 | 208 |
logger.debug("adapter.stop()"); |
210 | 209 |
adapter.stop(); |
211 | 210 |
// TODO: A revisar si es o no conveniente este sistema |
... | ... | |
221 | 220 |
} |
222 | 221 |
} */ |
223 | 222 |
|
224 |
System.out.println(t2 - t1); |
|
225 | 223 |
} catch (DriverIOException e) { |
226 | 224 |
throw new DriverException(e); |
227 | 225 |
} catch (com.hardcode.gdbms.engine.data.DriverException e) { |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/DBStrategy.java | ||
---|---|---|
86 | 86 |
// teniendo en cuenta el boundingbox que toca. |
87 | 87 |
FLayer capa = getCapa(); |
88 | 88 |
VectorialDBAdapter dbAdapter = (VectorialDBAdapter) ((SingleLayer) capa).getSource(); |
89 |
|
|
89 |
dbAdapter.start(); |
|
90 | 90 |
String strEPSG = viewPort.getProjection().getAbrev().substring(5); |
91 | 91 |
GeometryIterator geomIt = dbAdapter.getGeometryIterator(viewPort.getAdjustedExtent(), strEPSG); |
92 | 92 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend(); |
... | ... | |
94 | 94 |
while (geomIt.hasNext()) |
95 | 95 |
{ |
96 | 96 |
if (cancel.isCanceled()) { |
97 |
// TODO: Deber?amos cerrar el resulset que va dentro del iterator
|
|
97 |
dbAdapter.stop();
|
|
98 | 98 |
break; |
99 | 99 |
} |
100 | 100 |
|
... | ... | |
111 | 111 |
e.printStackTrace(); |
112 | 112 |
throw new DriverException(e); |
113 | 113 |
} |
114 |
dbAdapter.stop(); |
|
114 | 115 |
|
115 |
|
|
116 | 116 |
} |
117 | 117 |
|
118 | 118 |
|
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FPoint3D.java | ||
---|---|---|
59 | 59 |
super(x, y); |
60 | 60 |
this.z = z; |
61 | 61 |
} |
62 |
public double getZ() |
|
63 |
{ |
|
64 |
return z; |
|
65 |
} |
|
62 | 66 |
} |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/ShapeFactory.java | ||
---|---|---|
56 | 56 |
public static IGeometry createPoint2D(double x, double y) { |
57 | 57 |
return new FGeometry(new FPoint2D(x, y)); |
58 | 58 |
} |
59 |
public static IGeometry createPoint2D(FPoint2D p) { |
|
60 |
return new FGeometry(p); |
|
61 |
} |
|
59 | 62 |
|
63 |
|
|
60 | 64 |
/** |
61 | 65 |
* Crea una geometr?a que contiene como shape un Multipunto 2D. |
62 | 66 |
* |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/VectorialDBAdapter.java | ||
---|---|---|
87 | 87 |
* al driver que cierre la conexion con el servidor de base de datos |
88 | 88 |
*/ |
89 | 89 |
public void stop() { |
90 |
((VectorialDatabaseDriver)driver).close(); |
|
90 | 91 |
} |
91 | 92 |
|
92 | 93 |
/** |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLayers.java | ||
---|---|---|
295 | 295 |
|
296 | 296 |
if (lyr.isVisible()) { |
297 | 297 |
if (lyr.isWithinScale()) |
298 |
{ |
|
299 |
long t1 = System.currentTimeMillis(); |
|
298 | 300 |
lyr.draw(image, g, viewPort, cancel); |
301 |
long t2 = System.currentTimeMillis(); |
|
302 |
System.out.println("Layer " + lyr.getName() + " " |
|
303 |
+ (t2-t1) + " milisecs."); |
|
304 |
} |
|
299 | 305 |
} |
300 | 306 |
} |
301 | 307 |
|
Also available in: Unified diff