Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / WFSStrategy.java @ 2183

History | View | Annotate | Download (4.9 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package com.iver.cit.gvsig.fmap.operations.strategies;
42

    
43
import java.awt.Graphics2D;
44
import java.awt.image.BufferedImage;
45
import java.sql.SQLException;
46

    
47
import org.cresques.cts.ICoordTrans;
48

    
49
import com.iver.cit.gvsig.fmap.DriverException;
50
import com.iver.cit.gvsig.fmap.ViewPort;
51
import com.iver.cit.gvsig.fmap.core.IFeature;
52
import com.iver.cit.gvsig.fmap.core.IGeometry;
53
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
54
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
55
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
56
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
57
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSDriver;
58
import com.iver.cit.gvsig.fmap.layers.FBitSet;
59
import com.iver.cit.gvsig.fmap.layers.FLayer;
60
import com.iver.cit.gvsig.fmap.layers.VectorialDBAdapter;
61
import com.iver.cit.gvsig.fmap.layers.WFSAdapter;
62
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
63
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
64
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
65
import com.iver.cit.gvsig.fmap.operations.Cancellable;
66
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
67
/**
68
 * Estrategia para WFS.
69
 *
70
 * @author Vicente Caballero Navarro
71
 */
72
public class WFSStrategy extends DefaultStrategy {
73

    
74
        public WFSStrategy(FLayer capa) {
75
                super(capa);
76
        }
77

    
78

    
79
    /* (non-Javadoc)
80
     * @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)
81
     */
82
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException {
83
        // Nos aprovechamos del SQL para lanzar la consulta
84
        // teniendo en cuenta el boundingbox que toca.
85
        FLayer capa = getCapa();
86
        WFSAdapter wfsAdapter = (WFSAdapter) ((SingleLayer) capa).getSource();
87
        WFSDriver wfsDriver = (WFSDriver) wfsAdapter.getDriver();
88
        wfsAdapter.start();
89
                Selectable selection = (Selectable) getCapa();
90
                ICoordTrans ct = getCapa().getCoordTrans();
91
                FBitSet bitSet = selection.getSelection();
92
        
93
        String strEPSG = viewPort.getProjection().getAbrev().substring(5);
94
        IFeatureIterator geomIt = wfsAdapter.getFeatureIterator(viewPort.getAdjustedExtent(), strEPSG);
95
        VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend();
96
        int i;
97
        FSymbol symbol;
98
        try {
99
            while (geomIt.hasNext())
100
            {
101
                    if (cancel.isCanceled()) {
102
                        wfsAdapter.stop();
103
                            break;
104
                    }
105
                    IFeature feat = geomIt.next();
106
                IGeometry geom = feat.getGeometry();
107
                // TODO: CORREGIR LO DE LOS SIMBOLOS
108
                // Es probable que necesitemos generar un Feature
109
                // (Geometr?a + Atributos) para que opere con esa feature
110
                // el gestor de leyendas. A la leyenda le pasar?amos un
111
                // feature, y nos devolver? la colecci?n de s?mbolos a 
112
                // aplicar. Similar a lo de "processStylers" de GT2
113
                                // if (viewPort.getAdjustedExtent().intersects(geom.getBounds2D())){
114
                                i = wfsDriver.getRowIndexByFID(feat);
115
                symbol = l.getSymbolByFeature(feat);                
116
                if (symbol == null) continue;
117
               if (bitSet.get(i)) {
118
                    symbol = FSymbol.getSymbolForSelection(symbol);
119
                }
120
                
121
                //FSymbol symbol = l.getDefaultSymbol();
122
                geom.draw(g,viewPort, symbol);
123
            }
124
            //}
125
        } catch (SQLException e) {
126
            e.printStackTrace();
127
            throw new DriverException(e);
128
        }
129
        wfsAdapter.stop();
130
        
131
    }
132
    
133

    
134
}