Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / operations / strategies / WFSStrategy.java @ 5312

History | View | Annotate | Download (4.4 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.io.IOException;
46

    
47
import org.cresques.cts.ICoordTrans;
48

    
49
import com.iver.andami.PluginServices;
50
import com.iver.cit.gvsig.fmap.DriverException;
51
import com.iver.cit.gvsig.fmap.ViewPort;
52
import com.iver.cit.gvsig.fmap.core.IFeature;
53
import com.iver.cit.gvsig.fmap.core.IGeometry;
54
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
55
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
56
import com.iver.cit.gvsig.fmap.drivers.WFSDriver;
57
import com.iver.cit.gvsig.fmap.layers.FBitSet;
58
import com.iver.cit.gvsig.fmap.layers.FLayer;
59
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
60
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
61
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
62
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
63
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
64
import com.iver.cit.gvsig.fmap.operations.Cancellable;
65
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
66
/**
67
 * Estrategia para WFS.
68
 *
69
 * @author Vicente Caballero Navarro
70
 */
71
public class WFSStrategy extends DefaultStrategy {
72
        
73
        public WFSStrategy(FLayer capa) {
74
                super(capa);
75
        }
76
        
77
        
78
        /* (non-Javadoc)
79
         * @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)
80
         */
81
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException {
82
//                // Nos aprovechamos del SQL para lanzar la consulta
83
//                // teniendo en cuenta el boundingbox que toca.
84
//                com.iver.cit.gvsig.gui.View activeView = 
85
//                        (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
86
                
87
                FLayer capa = getCapa();
88
                ICoordTrans ct = getCapa().getCoordTrans();
89
                VectorialAdapter wfsAdapter =  (VectorialAdapter) ((SingleLayer) capa).getSource();
90
                if (wfsAdapter==null){
91
                        capa.setActive(false);
92
                        capa.setVisible(false);
93
                        throw new DriverException("Error en la conexi?n");
94
                }
95
                WFSDriver wfsDriver = (WFSDriver) wfsAdapter.getDriver();
96
                
97
                
98
                wfsDriver.open();
99
                
100
                FLyrVect flryVect = (FLyrVect)getCapa();
101
                Selectable selectable = flryVect.getRecordset();
102
                FBitSet bitSet = selectable.getSelection();
103
                        
104
                String strEPSG = viewPort.getProjection().getAbrev().substring(5);
105
                IFeatureIterator geomIt=null;
106
                try{
107
                        geomIt = wfsDriver.getFeatureIterator(viewPort.getAdjustedExtent(), strEPSG);
108
                }catch (IOException e) {
109
                        throw new DriverException(e);
110
                }
111
                VectorialLegend vectorialLegend = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend();
112
                int rowIndex;
113
                FSymbol symbol;
114
                while (geomIt.hasNext()){
115
                        if (cancel.isCanceled()){
116
                                wfsDriver.close();
117
                                break;
118
                        }
119
                        IFeature feat = geomIt.next();
120
                        IGeometry geom = feat.getGeometry();
121
                        if (ct != null) {
122
                                geom.reProject(ct);
123
                        }
124
                        rowIndex = wfsDriver.getRowIndexByFID(feat);
125
                        symbol = vectorialLegend.getSymbolByFeature(feat);                
126
                        if (symbol == null){
127
                                continue;
128
                        }
129
                        if (bitSet.get(rowIndex)) {
130
                                symbol = FSymbol.getSymbolForSelection(symbol);
131
                        }
132
                        geom.drawInts(g,viewPort, symbol);
133
                }                        
134
        }
135
        
136
        
137
}