Revision 2183 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/DBStrategy.java
DBStrategy.java | ||
---|---|---|
44 | 44 |
package com.iver.cit.gvsig.fmap.operations.strategies; |
45 | 45 |
|
46 | 46 |
import java.awt.Graphics2D; |
47 |
import java.awt.geom.Point2D; |
|
48 |
import java.awt.geom.Rectangle2D; |
|
49 | 47 |
import java.awt.image.BufferedImage; |
50 | 48 |
import java.sql.SQLException; |
51 | 49 |
import java.util.BitSet; |
... | ... | |
54 | 52 |
|
55 | 53 |
import com.iver.cit.gvsig.fmap.DriverException; |
56 | 54 |
import com.iver.cit.gvsig.fmap.ViewPort; |
55 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
57 | 56 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
58 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
59 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator; |
|
57 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
|
58 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
|
59 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
|
60 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
60 | 61 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
61 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
|
62 | 62 |
import com.iver.cit.gvsig.fmap.layers.VectorialDBAdapter; |
63 | 63 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
64 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
|
64 | 65 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
65 | 66 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
66 | 67 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
... | ... | |
86 | 87 |
// teniendo en cuenta el boundingbox que toca. |
87 | 88 |
FLayer capa = getCapa(); |
88 | 89 |
VectorialDBAdapter dbAdapter = (VectorialDBAdapter) ((SingleLayer) capa).getSource(); |
90 |
VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) dbAdapter.getDriver(); |
|
91 |
dbAdapter.start(); |
|
92 |
Selectable selection = (Selectable) getCapa(); |
|
93 |
ICoordTrans ct = getCapa().getCoordTrans(); |
|
94 |
FBitSet bitSet = selection.getSelection(); |
|
89 | 95 |
|
90 |
String sqlOrig = "SELECT " + dbAdapter.getFields() + " FROM " + |
|
91 |
dbAdapter.getTableName() + " " + dbAdapter.getWhereClause(); |
|
92 |
double xMin = viewPort.getAdjustedExtent().getMinX(); |
|
93 |
double yMin = viewPort.getAdjustedExtent().getMinY(); |
|
94 |
double xMax = viewPort.getAdjustedExtent().getMaxX(); |
|
95 |
double yMax = viewPort.getAdjustedExtent().getMaxY(); |
|
96 |
|
|
97 |
|
|
98 | 96 |
String strEPSG = viewPort.getProjection().getAbrev().substring(5); |
99 |
System.out.println(strEPSG); |
|
97 |
// TODO: EXPLORAR LAS LEYENDAS PARA SABER LOS CAMPOS QUE VAMOS |
|
98 |
// A NECESITAR RECUPERAR, PARA INCLUIR EN LA CONSULTA SOLO |
|
99 |
// AQUELLOS QUE VAMOS A NECESITAR. CON ESO GANAREMOS VELOCIDAD. |
|
100 |
// Ejemplo: |
|
101 |
// En ArcSDE: |
|
102 |
// con Vias cogiendo un campo solo: 5 segundos |
|
103 |
// con todos los campos de Vias: 11 segundos. |
|
104 |
// => MODIFICAR EL getFeatureIterator para que admita los nombres |
|
105 |
// de los campos adem?s del rect?ngulo que pides. |
|
100 | 106 |
|
101 |
String wktBox = "GeometryFromText('LINESTRING(" + xMin + " " + yMin + ", " |
|
102 |
+ xMax + " " + yMin + ", " |
|
103 |
+ xMax + " " + yMax + ", " |
|
104 |
+ xMin + " " + yMax + ")', " |
|
105 |
+ strEPSG + ");"; |
|
106 |
|
|
107 |
String sqlAux; |
|
108 |
if (dbAdapter.getWhereClause().startsWith("WHERE")) |
|
109 |
sqlAux = sqlOrig + " the_geom && " + wktBox; |
|
110 |
else |
|
111 |
sqlAux = sqlOrig + "WHERE the_geom && " + wktBox; |
|
112 |
|
|
113 |
GeometryIterator geomIt = dbAdapter.getGeometryIterator(sqlAux); |
|
107 |
IFeatureIterator geomIt = dbAdapter.getFeatureIterator(viewPort.getAdjustedExtent(), strEPSG); |
|
114 | 108 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend(); |
109 |
int i; |
|
110 |
FSymbol symbol; |
|
115 | 111 |
try { |
116 | 112 |
while (geomIt.hasNext()) |
117 | 113 |
{ |
118 | 114 |
if (cancel.isCanceled()) { |
119 |
// TODO: Deber?amos cerrar el resulset que va dentro del iterator
|
|
115 |
dbAdapter.stop();
|
|
120 | 116 |
break; |
121 | 117 |
} |
122 |
|
|
123 |
IGeometry geom = geomIt.next(); |
|
124 |
// TODO: CORREGIR LO DE LOS SIMBOLOS |
|
125 |
// Es probable que necesitemos generar un Feature |
|
126 |
// (Geometr?a + Atributos) para que opere con esa feature |
|
127 |
// el gestor de leyendas. A la leyenda le pasar?amos un |
|
128 |
// feature, y nos devolver? la colecci?n de s?mbolos a |
|
129 |
// aplicar. Similar a lo de "processStylers" de GT2 |
|
130 |
geom.draw(g,viewPort,l.getDefaultSymbol()); |
|
118 |
IFeature feat = geomIt.next(); |
|
119 |
IGeometry geom = feat.getGeometry(); |
|
120 |
i = dbDriver.getRowIndexByFID(feat); |
|
121 |
// System.out.println("Antes de pintar " + i); |
|
122 |
symbol = l.getSymbolByFeature(feat); |
|
123 |
if (symbol == null) continue; |
|
124 |
if (bitSet.get(i)) { |
|
125 |
symbol = FSymbol.getSymbolForSelection(symbol); |
|
126 |
} |
|
127 |
|
|
128 |
// symbol = l.getDefaultSymbol(); |
|
129 |
geom.draw(g,viewPort, symbol); |
|
131 | 130 |
} |
132 | 131 |
} catch (SQLException e) { |
133 | 132 |
e.printStackTrace(); |
134 | 133 |
throw new DriverException(e); |
135 | 134 |
} |
135 |
dbAdapter.stop(); |
|
136 | 136 |
|
137 |
|
|
138 | 137 |
} |
139 | 138 |
|
140 | 139 |
|
Also available in: Unified diff