root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / DBStrategy.java @ 2183
History | View | Annotate | Download (5.05 KB)
1 |
/*
|
---|---|
2 |
* Created on 08-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.operations.strategies; |
45 |
|
46 |
import java.awt.Graphics2D; |
47 |
import java.awt.image.BufferedImage; |
48 |
import java.sql.SQLException; |
49 |
import java.util.BitSet; |
50 |
|
51 |
import org.cresques.cts.ICoordTrans; |
52 |
|
53 |
import com.iver.cit.gvsig.fmap.DriverException; |
54 |
import com.iver.cit.gvsig.fmap.ViewPort; |
55 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
56 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
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; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
62 |
import com.iver.cit.gvsig.fmap.layers.VectorialDBAdapter; |
63 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
64 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
65 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
66 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
67 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
68 |
|
69 |
/**
|
70 |
* @author FJP
|
71 |
*
|
72 |
* TODO To change the template for this generated type comment go to
|
73 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
74 |
*/
|
75 |
public class DBStrategy extends DefaultStrategy { |
76 |
|
77 |
public DBStrategy(FLayer capa) {
|
78 |
super(capa);
|
79 |
} |
80 |
|
81 |
|
82 |
/* (non-Javadoc)
|
83 |
* @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)
|
84 |
*/
|
85 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException { |
86 |
// Nos aprovechamos del SQL para lanzar la consulta
|
87 |
// teniendo en cuenta el boundingbox que toca.
|
88 |
FLayer capa = getCapa(); |
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(); |
95 |
|
96 |
String strEPSG = viewPort.getProjection().getAbrev().substring(5); |
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.
|
106 |
|
107 |
IFeatureIterator geomIt = dbAdapter.getFeatureIterator(viewPort.getAdjustedExtent(), strEPSG); |
108 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend(); |
109 |
int i;
|
110 |
FSymbol symbol; |
111 |
try {
|
112 |
while (geomIt.hasNext())
|
113 |
{ |
114 |
if (cancel.isCanceled()) {
|
115 |
dbAdapter.stop(); |
116 |
break;
|
117 |
} |
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); |
130 |
} |
131 |
} catch (SQLException e) { |
132 |
e.printStackTrace(); |
133 |
throw new DriverException(e); |
134 |
} |
135 |
dbAdapter.stop(); |
136 |
|
137 |
} |
138 |
|
139 |
|
140 |
} |