Revision 2131
branches/gvSIG_03_SLD/applications/appgvSIG/src/com/iver/cit/gvsig/Abrir.java | ||
---|---|---|
63 | 63 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
64 | 64 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
65 | 65 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
66 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.mysql.MySQLdriver;
|
|
66 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.mysql.MySQLDriver;
|
|
67 | 67 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGisDriver; |
68 | 68 |
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSDriver; |
69 | 69 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
... | ... | |
269 | 269 |
|
270 | 270 |
VectorialDatabaseDriver driver = null; |
271 | 271 |
if (dbUrl.indexOf("mysql") != -1) |
272 |
driver = new MySQLdriver();
|
|
272 |
driver = new MySQLDriver();
|
|
273 | 273 |
if (dbUrl.indexOf("postgresql") != -1) |
274 | 274 |
driver = new PostGisDriver(); |
275 | 275 |
|
branches/gvSIG_03_SLD/applications/appgvSIG/src/com/iver/cit/gvsig/DEMO/PruebasGT2.java | ||
---|---|---|
59 | 59 |
import org.geotools.data.DataSourceException; |
60 | 60 |
import org.geotools.data.DataStore; |
61 | 61 |
import org.geotools.data.FeatureSource; |
62 |
import org.geotools.data.postgis.PostgisDataStoreFactory; |
|
62 |
//import org.geotools.data.postgis.PostgisDataStoreFactory;
|
|
63 | 63 |
import org.geotools.map.DefaultMapLayer; |
64 | 64 |
import org.geotools.map.MapLayer; |
65 | 65 |
import org.geotools.styling.Style; |
... | ... | |
67 | 67 |
|
68 | 68 |
import com.iver.cit.gvsig.fmap.FMap; |
69 | 69 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
70 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.mysql.MySQLdriver;
|
|
70 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.mysql.MySQLDriver;
|
|
71 | 71 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGisDriver; |
72 | 72 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
73 | 73 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
... | ... | |
84 | 84 |
* @author Luis W. Sevilla (sevilla_lui@gva.es) |
85 | 85 |
*/ |
86 | 86 |
public class PruebasGT2 implements ActionListener { |
87 |
static PostgisDataStoreFactory postGisFactory = new PostgisDataStoreFactory(); |
|
87 |
// static PostgisDataStoreFactory postGisFactory = new PostgisDataStoreFactory();
|
|
88 | 88 |
// static ArcSDEDataStoreFactory arcSdeFactory = new ArcSDEDataStoreFactory(); |
89 | 89 |
|
90 | 90 |
Map remote; |
... | ... | |
151 | 151 |
protected void addLayer_mySQL() |
152 | 152 |
{ |
153 | 153 |
String nomTabla = JOptionPane.showInputDialog(null, "?Nombre de la tabla a cargar?", "provin"); |
154 |
VectorialDatabaseDriver driver = new MySQLdriver();
|
|
154 |
VectorialDatabaseDriver driver = new MySQLDriver();
|
|
155 | 155 |
String dburl = "jdbc:mysql://localhost/test"; |
156 | 156 |
String dbuser = "root"; |
157 | 157 |
String dbpass = "aquilina"; |
... | ... | |
182 | 182 |
|
183 | 183 |
protected void addLayerGT2_PostGIS() |
184 | 184 |
{ |
185 |
String nomTabla = JOptionPane.showInputDialog(null, "?Nombre de la tabla a cargar?", "provin"); |
|
185 |
/* String nomTabla = JOptionPane.showInputDialog(null, "?Nombre de la tabla a cargar?", "provin");
|
|
186 | 186 |
|
187 | 187 |
remote = new HashMap(); |
188 | 188 |
remote.put("dbtype","postgis"); |
... | ... | |
202 | 202 |
} catch (IOException e) { |
203 | 203 |
// TODO Auto-generated catch block |
204 | 204 |
e.printStackTrace(); |
205 |
} |
|
205 |
} */
|
|
206 | 206 |
} |
207 | 207 |
|
208 | 208 |
|
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/jdbc/mysql/MySQLdriver.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 04-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.jdbc.mysql; |
|
45 |
|
|
46 |
import java.awt.geom.Rectangle2D; |
|
47 |
import java.sql.Connection; |
|
48 |
import java.sql.ResultSet; |
|
49 |
import java.sql.SQLException; |
|
50 |
import java.sql.Statement; |
|
51 |
|
|
52 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
53 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
54 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
|
55 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
|
56 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
|
57 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser; |
|
58 |
import com.vividsolutions.jts.io.ParseException; |
|
59 |
|
|
60 |
/** |
|
61 |
* @author FJP |
|
62 |
* |
|
63 |
* TODO To change the template for this generated type comment go to |
|
64 |
* Window - Preferences - Java - Code Generation - Code and Comments |
|
65 |
*/ |
|
66 |
public class MySQLdriver extends DefaultDBDriver { |
|
67 |
private WKBParser parser = new WKBParser(); |
|
68 |
/* private int fetch_min=-1; |
|
69 |
private int fetch_max=-1; */ |
|
70 |
private Statement st; |
|
71 |
private Rectangle2D fullExtent = null; |
|
72 |
private String strAux; |
|
73 |
|
|
74 |
|
|
75 |
/** |
|
76 |
* |
|
77 |
*/ |
|
78 |
public MySQLdriver() { |
|
79 |
} |
|
80 |
/* (non-Javadoc) |
|
81 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes() |
|
82 |
*/ |
|
83 |
public DriverAttributes getDriverAttributes() { |
|
84 |
return null; |
|
85 |
} |
|
86 |
|
|
87 |
/* (non-Javadoc) |
|
88 |
* @see com.hardcode.driverManager.Driver#getName() |
|
89 |
*/ |
|
90 |
public String getName() { |
|
91 |
return "mySQL JDBC Driver"; |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int) |
|
96 |
*/ |
|
97 |
public IGeometry getShape(int index) { |
|
98 |
IGeometry geom = null; |
|
99 |
boolean resul; |
|
100 |
try { |
|
101 |
// EL ABSOLUTE NO HACE QUE SE VUELVAN A LEER LAS |
|
102 |
// FILAS, ASI QUE MONTAMOS ESTA HISTORIA PARA QUE |
|
103 |
// LO HAGA |
|
104 |
// System.out.println("getShape " + index); |
|
105 |
/* if (index < fetch_min) |
|
106 |
{ |
|
107 |
rs.close(); |
|
108 |
|
|
109 |
rs = st.executeQuery(sqlOrig); |
|
110 |
fetch_min = 0; |
|
111 |
fetch_max = rs.getFetchSize(); |
|
112 |
} |
|
113 |
while (index >= fetch_max) |
|
114 |
{ |
|
115 |
rs.last(); |
|
116 |
// forzamos una carga |
|
117 |
rs.next(); |
|
118 |
fetch_min = fetch_max; |
|
119 |
fetch_max = fetch_max + rs.getFetchSize(); |
|
120 |
// System.out.println("fetchSize = " + rs.getFetchSize() + " " + fetch_min + "-" + fetch_max); |
|
121 |
} |
|
122 |
rs.absolute(index+1 - fetch_min); */ |
|
123 |
rs.absolute(index+1); |
|
124 |
// strAux = rs.getString(1); |
|
125 |
// geom = parser.read(strAux); |
|
126 |
byte[] data = rs.getBytes(1); |
|
127 |
geom = parser.parse(data); |
|
128 |
|
|
129 |
|
|
130 |
} catch (SQLException e) { |
|
131 |
e.printStackTrace(); |
|
132 |
} |
|
133 |
|
|
134 |
return geom; |
|
135 |
} |
|
136 |
/** |
|
137 |
* @param conn |
|
138 |
* @param tableName |
|
139 |
* @param fields OJO: EL PRIMER CAMPO HA DE SER EL DE GEOMETRIA |
|
140 |
* @param whereClause |
|
141 |
*/ |
|
142 |
public void setData(Connection conn, String tableName, String fields, String whereClause, int id_FID_field) |
|
143 |
{ |
|
144 |
this.conn = conn; |
|
145 |
this.tableName = tableName; |
|
146 |
this.fields = fields; |
|
147 |
this.whereClause = whereClause; |
|
148 |
this.sqlOrig = "SELECT " + fields + " FROM " + tableName + " " + whereClause; |
|
149 |
this.idFID_FieldName = id_FID_field; |
|
150 |
try { |
|
151 |
st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
|
152 |
rs = st.executeQuery(sqlOrig); |
|
153 |
metaData = rs.getMetaData(); |
|
154 |
// Le pegamos un primera pasada para poder relacionar |
|
155 |
// un campo de identificador ?nico (parecido al OID en |
|
156 |
// postgresql) con el ?ndice dentro del recordset. |
|
157 |
// Esto cuando haya ediciones, no es v?lido, y hay |
|
158 |
// que refrescarlo. |
|
159 |
doRelateID_FID(); |
|
160 |
|
|
161 |
} catch (SQLException e) { |
|
162 |
// TODO Auto-generated catch block |
|
163 |
e.printStackTrace(); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent() |
|
169 |
*/ |
|
170 |
public Rectangle2D getFullExtent(){ |
|
171 |
if (fullExtent == null) |
|
172 |
{ |
|
173 |
try |
|
174 |
{ |
|
175 |
IFeatureIterator itGeom = getFeatureIterator("SELECT ASBINARY(ogc_geom) AS the_geom FROM " + tableName); |
|
176 |
IGeometry geom; |
|
177 |
int cont = 0; |
|
178 |
while (itGeom.hasNext()) |
|
179 |
{ |
|
180 |
geom = itGeom.next().getGeometry(); |
|
181 |
if (cont==0) |
|
182 |
fullExtent = geom.getBounds2D(); |
|
183 |
else |
|
184 |
fullExtent.add(geom.getBounds2D()); |
|
185 |
cont++; |
|
186 |
} |
|
187 |
} |
|
188 |
catch (SQLException e) |
|
189 |
{ |
|
190 |
System.err.println(e.getMessage()); |
|
191 |
} catch (DriverException e) { |
|
192 |
// TODO Auto-generated catch block |
|
193 |
e.printStackTrace(); |
|
194 |
} |
|
195 |
|
|
196 |
} |
|
197 |
return fullExtent; |
|
198 |
} |
|
199 |
/* (non-Javadoc) |
|
200 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getGeometryIterator(java.lang.String) |
|
201 |
*/ |
|
202 |
public IFeatureIterator getFeatureIterator(String sql) throws com.iver.cit.gvsig.fmap.DriverException { |
|
203 |
Statement st; |
|
204 |
MySqlFeatureIterator geomIterator = null; |
|
205 |
try { |
|
206 |
st = conn.createStatement(); |
|
207 |
// st.setFetchSize(2000); |
|
208 |
ResultSet rs = st.executeQuery(sql); |
|
209 |
geomIterator = new MySqlFeatureIterator(rs); |
|
210 |
} catch (SQLException e) { |
|
211 |
e.printStackTrace(); |
|
212 |
throw new com.iver.cit.gvsig.fmap.DriverException(e); |
|
213 |
} |
|
214 |
|
|
215 |
return geomIterator; |
|
216 |
} |
|
217 |
/* (non-Javadoc) |
|
218 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getGeometryIterator(java.awt.geom.Rectangle2D) |
|
219 |
*/ |
|
220 |
public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException { |
|
221 |
double xMin = r.getMinX(); |
|
222 |
double yMin = r.getMinY(); |
|
223 |
double xMax = r.getMaxX(); |
|
224 |
double yMax = r.getMaxY(); |
|
225 |
|
|
226 |
String wktBox = "GeomFromText('LINESTRING(" + xMin + " " + yMin + ", " |
|
227 |
+ xMax + " " + yMin + ", " |
|
228 |
+ xMax + " " + yMax + ", " |
|
229 |
+ xMin + " " + yMax + ")', " |
|
230 |
+ strEPSG + ")"; |
|
231 |
String sqlAux; |
|
232 |
if (getWhereClause().startsWith("WHERE")) |
|
233 |
sqlAux = sqlOrig + " MBRIntersects(" + wktBox + ",ogc_geom);" ; |
|
234 |
else |
|
235 |
sqlAux = sqlOrig + "WHERE MBRIntersects(" + wktBox + ",ogc_geom);" ; |
|
236 |
|
|
237 |
|
|
238 |
return getFeatureIterator(sqlAux); |
|
239 |
} |
|
240 |
public void open() { |
|
241 |
// TODO Auto-generated method stub |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
} |
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/jdbc/mysql/MySQLDriver.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 04-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.jdbc.mysql; |
|
45 |
|
|
46 |
import java.awt.geom.Rectangle2D; |
|
47 |
import java.sql.Connection; |
|
48 |
import java.sql.ResultSet; |
|
49 |
import java.sql.SQLException; |
|
50 |
import java.sql.Statement; |
|
51 |
|
|
52 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
53 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
54 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
|
55 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
|
56 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
|
57 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser; |
|
58 |
import com.vividsolutions.jts.io.ParseException; |
|
59 |
|
|
60 |
/** |
|
61 |
* @author FJP |
|
62 |
* |
|
63 |
* TODO To change the template for this generated type comment go to |
|
64 |
* Window - Preferences - Java - Code Generation - Code and Comments |
|
65 |
*/ |
|
66 |
public class MySQLDriver extends DefaultDBDriver { |
|
67 |
private WKBParser parser = new WKBParser(); |
|
68 |
/* private int fetch_min=-1; |
|
69 |
private int fetch_max=-1; */ |
|
70 |
private Statement st; |
|
71 |
private Rectangle2D fullExtent = null; |
|
72 |
private String strAux; |
|
73 |
|
|
74 |
|
|
75 |
/** |
|
76 |
* |
|
77 |
*/ |
|
78 |
public MySQLDriver() { |
|
79 |
} |
|
80 |
/* (non-Javadoc) |
|
81 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes() |
|
82 |
*/ |
|
83 |
public DriverAttributes getDriverAttributes() { |
|
84 |
return null; |
|
85 |
} |
|
86 |
|
|
87 |
/* (non-Javadoc) |
|
88 |
* @see com.hardcode.driverManager.Driver#getName() |
|
89 |
*/ |
|
90 |
public String getName() { |
|
91 |
return "mySQL JDBC Driver"; |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int) |
|
96 |
*/ |
|
97 |
public IGeometry getShape(int index) { |
|
98 |
IGeometry geom = null; |
|
99 |
boolean resul; |
|
100 |
try { |
|
101 |
// EL ABSOLUTE NO HACE QUE SE VUELVAN A LEER LAS |
|
102 |
// FILAS, ASI QUE MONTAMOS ESTA HISTORIA PARA QUE |
|
103 |
// LO HAGA |
|
104 |
// System.out.println("getShape " + index); |
|
105 |
/* if (index < fetch_min) |
|
106 |
{ |
|
107 |
rs.close(); |
|
108 |
|
|
109 |
rs = st.executeQuery(sqlOrig); |
|
110 |
fetch_min = 0; |
|
111 |
fetch_max = rs.getFetchSize(); |
|
112 |
} |
|
113 |
while (index >= fetch_max) |
|
114 |
{ |
|
115 |
rs.last(); |
|
116 |
// forzamos una carga |
|
117 |
rs.next(); |
|
118 |
fetch_min = fetch_max; |
|
119 |
fetch_max = fetch_max + rs.getFetchSize(); |
|
120 |
// System.out.println("fetchSize = " + rs.getFetchSize() + " " + fetch_min + "-" + fetch_max); |
|
121 |
} |
|
122 |
rs.absolute(index+1 - fetch_min); */ |
|
123 |
rs.absolute(index+1); |
|
124 |
// strAux = rs.getString(1); |
|
125 |
// geom = parser.read(strAux); |
|
126 |
byte[] data = rs.getBytes(1); |
|
127 |
geom = parser.parse(data); |
|
128 |
|
|
129 |
|
|
130 |
} catch (SQLException e) { |
|
131 |
e.printStackTrace(); |
|
132 |
} |
|
133 |
|
|
134 |
return geom; |
|
135 |
} |
|
136 |
/** |
|
137 |
* @param conn |
|
138 |
* @param tableName |
|
139 |
* @param fields OJO: EL PRIMER CAMPO HA DE SER EL DE GEOMETRIA |
|
140 |
* @param whereClause |
|
141 |
*/ |
|
142 |
public void setData(Connection conn, String tableName, String fields, String whereClause, int id_FID_field) |
|
143 |
{ |
|
144 |
this.conn = conn; |
|
145 |
this.tableName = tableName; |
|
146 |
this.fields = fields; |
|
147 |
this.whereClause = whereClause; |
|
148 |
this.sqlOrig = "SELECT " + fields + " FROM " + tableName + " " + whereClause; |
|
149 |
this.idFID_FieldName = id_FID_field; |
|
150 |
try { |
|
151 |
st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
|
152 |
rs = st.executeQuery(sqlOrig); |
|
153 |
metaData = rs.getMetaData(); |
|
154 |
// Le pegamos un primera pasada para poder relacionar |
|
155 |
// un campo de identificador ?nico (parecido al OID en |
|
156 |
// postgresql) con el ?ndice dentro del recordset. |
|
157 |
// Esto cuando haya ediciones, no es v?lido, y hay |
|
158 |
// que refrescarlo. |
|
159 |
doRelateID_FID(); |
|
160 |
|
|
161 |
} catch (SQLException e) { |
|
162 |
// TODO Auto-generated catch block |
|
163 |
e.printStackTrace(); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent() |
|
169 |
*/ |
|
170 |
public Rectangle2D getFullExtent(){ |
|
171 |
if (fullExtent == null) |
|
172 |
{ |
|
173 |
try |
|
174 |
{ |
|
175 |
IFeatureIterator itGeom = getFeatureIterator("SELECT ASBINARY(ogc_geom) AS the_geom FROM " + tableName); |
|
176 |
IGeometry geom; |
|
177 |
int cont = 0; |
|
178 |
while (itGeom.hasNext()) |
|
179 |
{ |
|
180 |
geom = itGeom.next().getGeometry(); |
|
181 |
if (cont==0) |
|
182 |
fullExtent = geom.getBounds2D(); |
|
183 |
else |
|
184 |
fullExtent.add(geom.getBounds2D()); |
|
185 |
cont++; |
|
186 |
} |
|
187 |
} |
|
188 |
catch (SQLException e) |
|
189 |
{ |
|
190 |
System.err.println(e.getMessage()); |
|
191 |
} catch (DriverException e) { |
|
192 |
// TODO Auto-generated catch block |
|
193 |
e.printStackTrace(); |
|
194 |
} |
|
195 |
|
|
196 |
} |
|
197 |
return fullExtent; |
|
198 |
} |
|
199 |
/* (non-Javadoc) |
|
200 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getGeometryIterator(java.lang.String) |
|
201 |
*/ |
|
202 |
public IFeatureIterator getFeatureIterator(String sql) throws com.iver.cit.gvsig.fmap.DriverException { |
|
203 |
Statement st; |
|
204 |
MySqlFeatureIterator geomIterator = null; |
|
205 |
try { |
|
206 |
st = conn.createStatement(); |
|
207 |
// st.setFetchSize(2000); |
|
208 |
ResultSet rs = st.executeQuery(sql); |
|
209 |
geomIterator = new MySqlFeatureIterator(rs); |
|
210 |
} catch (SQLException e) { |
|
211 |
e.printStackTrace(); |
|
212 |
throw new com.iver.cit.gvsig.fmap.DriverException(e); |
|
213 |
} |
|
214 |
|
|
215 |
return geomIterator; |
|
216 |
} |
|
217 |
/* (non-Javadoc) |
|
218 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getGeometryIterator(java.awt.geom.Rectangle2D) |
|
219 |
*/ |
|
220 |
public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException { |
|
221 |
double xMin = r.getMinX(); |
|
222 |
double yMin = r.getMinY(); |
|
223 |
double xMax = r.getMaxX(); |
|
224 |
double yMax = r.getMaxY(); |
|
225 |
|
|
226 |
String wktBox = "GeomFromText('LINESTRING(" + xMin + " " + yMin + ", " |
|
227 |
+ xMax + " " + yMin + ", " |
|
228 |
+ xMax + " " + yMax + ", " |
|
229 |
+ xMin + " " + yMax + ")', " |
|
230 |
+ strEPSG + ")"; |
|
231 |
String sqlAux; |
|
232 |
if (getWhereClause().startsWith("WHERE")) |
|
233 |
sqlAux = sqlOrig + " MBRIntersects(" + wktBox + ",ogc_geom);" ; |
|
234 |
else |
|
235 |
sqlAux = sqlOrig + "WHERE MBRIntersects(" + wktBox + ",ogc_geom);" ; |
|
236 |
|
|
237 |
|
|
238 |
return getFeatureIterator(sqlAux); |
|
239 |
} |
|
240 |
public void open() { |
|
241 |
// TODO Auto-generated method stub |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
} |
|
0 | 248 |
Also available in: Unified diff