Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / DBStrategy.java @ 3236

History | View | Annotate | Download (6.16 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.geom.Rectangle2D;
48
import java.awt.image.BufferedImage;
49
import java.sql.SQLException;
50
import java.util.BitSet;
51

    
52
import org.cresques.cts.ICoordTrans;
53

    
54
import com.iver.cit.gvsig.fmap.DriverException;
55
import com.iver.cit.gvsig.fmap.ViewPort;
56
import com.iver.cit.gvsig.fmap.core.IFeature;
57
import com.iver.cit.gvsig.fmap.core.IGeometry;
58
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
59
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
60
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
61
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
62
import com.iver.cit.gvsig.fmap.layers.FBitSet;
63
import com.iver.cit.gvsig.fmap.layers.FLayer;
64
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
65
import com.iver.cit.gvsig.fmap.layers.VectorialDBAdapter;
66
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
67
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
68
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
69
import com.iver.cit.gvsig.fmap.operations.Cancellable;
70
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
71

    
72
/**
73
 * @author FJP
74
 *
75
 * TODO To change the template for this generated type comment go to
76
 * Window - Preferences - Java - Code Generation - Code and Comments
77
 */
78
public class DBStrategy extends DefaultStrategy {
79

    
80
        public DBStrategy(FLayer capa) {
81
                super(capa);
82
        }
83

    
84

    
85
    /* (non-Javadoc)
86
     * @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)
87
     */
88
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException {
89
        // Nos aprovechamos del SQL para lanzar la consulta
90
        // teniendo en cuenta el boundingbox que toca.
91
        FLyrVect lyr = (FLyrVect) getCapa();
92
        VectorialDBAdapter dbAdapter = (VectorialDBAdapter) ((SingleLayer) capa).getSource();
93
        VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) dbAdapter.getDriver();
94
        dbAdapter.start();
95
                Selectable selection = (Selectable) lyr;
96
                ICoordTrans ct = lyr.getCoordTrans();
97
                FBitSet bitSet = selection.getSelection();
98
        
99
        String strEPSG = viewPort.getProjection().getAbrev().substring(5);
100
        // TODO: EXPLORAR LAS LEYENDAS PARA SABER LOS CAMPOS QUE VAMOS
101
        // A NECESITAR RECUPERAR, PARA INCLUIR EN LA CONSULTA SOLO
102
        // AQUELLOS QUE VAMOS A NECESITAR. CON ESO GANAREMOS VELOCIDAD.
103
        // Ejemplo:
104
        // En ArcSDE:
105
        // con Vias cogiendo un campo solo: 5 segundos
106
        // con todos los campos de Vias: 11 segundos.
107
        // => MODIFICAR EL getFeatureIterator para que admita los nombres
108
        // de los campos adem?s del rect?ngulo que pides.
109
        String[] usedFields = null;
110
        if (lyr.getLegend() instanceof VectorialLegend)
111
        {
112
            VectorialLegend legend = (VectorialLegend) lyr.getLegend();
113
            // TODO: Meter en el interaz Legend un m?todo String[] getUsedFields()
114
        }
115
        
116
        Rectangle2D rectAux = viewPort.getAdjustedExtent();
117
        if (ct != null) {
118
            ICoordTrans invertedCT = ct.getInverted();
119
            rectAux = invertedCT.convert(rectAux);            
120
        }
121

    
122
        
123
        IFeatureIterator geomIt = dbAdapter.getFeatureIterator(rectAux, strEPSG);
124
        VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend();
125
        
126
        DriverAttributes attr = dbAdapter.getDriverAttributes();
127
        boolean bMustClone = false;
128
        if (attr != null)
129
        {
130
            if (attr.isLoadedInMemory())
131
            {
132
                bMustClone = attr.isLoadedInMemory();               
133
            }
134
        }
135

    
136
        
137
        int i;
138
        FSymbol symbol;
139
        try {
140
            while (geomIt.hasNext())
141
            {
142
                    if (cancel.isCanceled()) {
143
                        dbAdapter.stop();
144
                            break;
145
                    }
146
                    IFeature feat = geomIt.next();
147
                IGeometry geom = feat.getGeometry();
148
                
149
                if (ct != null) {
150
                    if (bMustClone)
151
                        geom = geom.cloneGeometry();
152
                    geom.reProject(ct);
153
                }
154

    
155
                i = dbDriver.getRowIndexByFID(feat);
156
                // System.out.println("Antes de pintar " + i);
157
                symbol = l.getSymbolByFeature(feat);
158
                // symbol = l.getSymbol(i);
159
                if (symbol == null) continue;
160
                if (bitSet.get(i)) {
161
                    symbol = FSymbol.getSymbolForSelection(symbol);
162
                } 
163
                
164
                // symbol = l.getDefaultSymbol();
165
                geom.draw(g,viewPort, symbol);
166
            }
167
        } catch (SQLException e) {
168
            e.printStackTrace();
169
            throw new DriverException(e);
170
        }
171
        dbAdapter.stop();
172
        
173
    }
174
    
175

    
176
}