Statistics
| Revision:

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

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

    
53
import org.cresques.cts.ICoordTrans;
54

    
55
import com.iver.cit.gvsig.fmap.DriverException;
56
import com.iver.cit.gvsig.fmap.ViewPort;
57
import com.iver.cit.gvsig.fmap.core.IGeometry;
58
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
59
import com.iver.cit.gvsig.fmap.drivers.jdbc.GeometryIterator;
60
import com.iver.cit.gvsig.fmap.layers.FLayer;
61
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
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.SingleLayer;
65
import com.iver.cit.gvsig.fmap.operations.Cancellable;
66
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
67

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

    
76
        public DBStrategy(FLayer capa) {
77
                super(capa);
78
        }
79

    
80

    
81
    /* (non-Javadoc)
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)
83
     */
84
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException {
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();
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
        
138
    }
139
    
140

    
141
}