47 |
47 |
import java.awt.geom.Point2D;
|
48 |
48 |
import java.awt.geom.Rectangle2D;
|
49 |
49 |
import java.awt.image.BufferedImage;
|
|
50 |
import java.sql.SQLException;
|
50 |
51 |
import java.util.BitSet;
|
51 |
52 |
|
52 |
53 |
import org.cresques.cts.ICoordTrans;
|
... | ... | |
55 |
56 |
import com.iver.cit.gvsig.fmap.ViewPort;
|
56 |
57 |
import com.iver.cit.gvsig.fmap.core.IGeometry;
|
57 |
58 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
|
|
59 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator;
|
58 |
60 |
import com.iver.cit.gvsig.fmap.layers.FLayer;
|
59 |
61 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
|
60 |
62 |
import com.iver.cit.gvsig.fmap.layers.VectorialDBAdapter;
|
|
63 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
|
61 |
64 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
|
62 |
65 |
import com.iver.cit.gvsig.fmap.operations.Cancellable;
|
|
66 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
|
63 |
67 |
|
64 |
68 |
/**
|
65 |
69 |
* @author FJP
|
... | ... | |
78 |
82 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable)
|
79 |
83 |
*/
|
80 |
84 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException {
|
81 |
|
// TODO Auto-generated method stub
|
|
85 |
// Nos aprovechamos del SQL para lanzar la consulta
|
|
86 |
// teniendo en cuenta el boundingbox que toca.
|
|
87 |
FLayer capa = getCapa();
|
|
88 |
VectorialDBAdapter dbAdapter = (VectorialDBAdapter) ((SingleLayer) capa).getSource();
|
82 |
89 |
|
|
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 |
String strEPSG = viewPort.getProjection().getAbrev().substring(5);
|
|
99 |
System.out.println(strEPSG);
|
|
100 |
|
|
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);
|
|
114 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend();
|
|
115 |
try {
|
|
116 |
while (geomIt.hasNext())
|
|
117 |
{
|
|
118 |
if (cancel.isCanceled()) {
|
|
119 |
// TODO: Deber?amos cerrar el resulset que va dentro del iterator
|
|
120 |
break;
|
|
121 |
}
|
|
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());
|
|
131 |
}
|
|
132 |
} catch (SQLException e) {
|
|
133 |
e.printStackTrace();
|
|
134 |
throw new DriverException(e);
|
|
135 |
}
|
|
136 |
|
|
137 |
|
83 |
138 |
}
|
84 |
139 |
|
85 |
|
/**
|
86 |
|
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
87 |
|
* java.util.BitSet)
|
88 |
|
*/
|
89 |
|
public void process(FeatureVisitor visitor, BitSet subset)
|
90 |
|
throws DriverException, VisitException {
|
91 |
|
try {
|
92 |
|
FLayer capa = getCapa();
|
93 |
|
if (visitor.start(capa)) {
|
94 |
|
VectorialAdapter va = ((SingleLayer) capa).getSource();
|
95 |
140 |
|
96 |
|
va.start();
|
97 |
|
for (int i = 0; i < va.getShapeCount(); i++) {
|
98 |
|
if (subset.get(i)) {
|
99 |
|
visitor.visit(va.getShape(i), i);
|
100 |
|
}
|
101 |
|
}
|
102 |
|
va.stop();
|
103 |
|
|
104 |
|
visitor.stop(capa);
|
105 |
|
}
|
106 |
|
} catch (DriverIOException e) {
|
107 |
|
throw new DriverException(e);
|
108 |
|
}
|
109 |
|
}
|
110 |
|
|
111 |
|
/**
|
112 |
|
* DOCUMENT ME!
|
113 |
|
*
|
114 |
|
* @param visitor DOCUMENT ME!
|
115 |
|
*
|
116 |
|
* @throws DriverException DOCUMENT ME!
|
117 |
|
* @throws VisitException
|
118 |
|
*
|
119 |
|
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
120 |
|
*/
|
121 |
|
public void process(FeatureVisitor visitor)
|
122 |
|
throws DriverException, VisitException {
|
123 |
|
try {
|
124 |
|
FLayer capa = getCapa();
|
125 |
|
if (visitor.start(capa)) {
|
126 |
|
VectorialDBAdapter va = (VectorialDBAdapter) ((SingleLayer) capa).getSource();
|
127 |
|
ICoordTrans ct = getCapa().getCoordTrans();
|
128 |
|
// GeometryIterator geomIt = va.getGeometryIterator();
|
129 |
|
va.start();
|
130 |
|
for (int i = 0; i < va.getShapeCount(); i++) {
|
131 |
|
IGeometry geom = va.getShape(i);
|
132 |
|
if (ct != null) {
|
133 |
|
geom.reProject(ct);
|
134 |
|
}
|
135 |
|
|
136 |
|
visitor.visit(geom, i);
|
137 |
|
}
|
138 |
|
va.stop();
|
139 |
|
visitor.stop(capa);
|
140 |
|
}
|
141 |
|
} catch (DriverIOException e) {
|
142 |
|
throw new DriverException(e);
|
143 |
|
}
|
144 |
|
}
|
145 |
|
|
146 |
|
|
147 |
141 |
}
|