Statistics
| Revision:

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

History | View | Annotate | Download (5.11 KB)

1
/* Generated by Together */
2

    
3
package com.iver.cit.gvsig.fmap.operations.strategies;
4

    
5
import java.awt.Graphics2D;
6
import java.awt.geom.AffineTransform;
7
import java.awt.geom.Rectangle2D;
8
import java.awt.image.BufferedImage;
9
import java.io.IOException;
10

    
11
import org.geotools.renderer.style.MarkStyle2D;
12
import org.geotools.renderer.style.Style2D;
13

    
14
import com.hardcode.driverManager.DriverLoadException;
15
import com.hardcode.gdbms.engine.data.DriverException;
16
import com.iver.cit.gvsig.fmap.ViewPort;
17
import com.iver.cit.gvsig.fmap.core.IGeometry;
18
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
19
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
20
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
21
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
22
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
23
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
24
import com.iver.cit.gvsig.fmap.operations.Cancellable;
25
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo;
26
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
27
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
28

    
29

    
30
/**
31
 * Esta clase definir? las operaciones de la interfaz FLyrVect de la manera m?s ?ptima para los ficheros shp. 
32
 */
33
public class ShpStrategy extends DefaultStrategy {
34

    
35
        /**
36
         * @param capa
37
         */
38
        public ShpStrategy(FLyrVect capa) {
39
                super(capa);
40
        }
41
        /**
42
         * @throws DriverLoadException
43
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, FStyle2D)
44
         */
45
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel)
46
                        throws DriverIOException, DriverLoadException {
47
                VectorialAdapter adapter = getCapa().getSource();
48
                BoundedShapes shapeBounds = (BoundedShapes) adapter.getDriver();
49
                VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver();
50
                
51
                adapter.start();
52
                
53
                IGeometry geom = adapter.getShape(0);
54
                VectorialLegend l = getCapa().getLegend();
55
                if (l instanceof ClassifiedLegendInfo)
56
                {
57
                        ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) l;
58
                        FSymbol[] symbs = clsfLegend.getSymbols();
59
                        double rSym=0, maxRSym = -1;
60
                        for (int i=0; i < symbs.length; i++)
61
                        {
62
                                // TODO: REVISAR LOS SIMBOLOS Y SUS TAMA?OS
63
                                /* Style2D pointSymbol = symbs[i].getPointStyle2D(); 
64
                                if (pointSymbol instanceof MarkStyle2D)
65
                                {
66
                                        MarkStyle2D mrk2D = (MarkStyle2D) pointSymbol;
67
                                        rSym = viewPort.toMapDistance(mrk2D.getSize());
68
                                        if (maxRSym < rSym)
69
                                                maxRSym = rSym;
70
                                }*/
71
                                
72
                        }
73
                }
74
                Rectangle2D extent = viewPort.getAdjustedExtent();
75
                AffineTransform at = viewPort.getAffineTransform();
76
                
77
                int sc;
78
                
79
                Rectangle2D bounds;
80

    
81
                sc = adapter.getShapeCount();
82
                long t1 = System.currentTimeMillis();
83
                //Prueba query
84
                ///BitSet bitset=this.queryByPoint((QueriedPoint)new QueriedPoint(904561,4712059),200000);
85
                ///BitSet bitset=this.queryByRect(new Rectangle2D.Double(304561,3712059,500000,500000));
86
                // BitSet bitset=this.queryByShape((IGeometry)new com.iver.cit.gvsig.fmap.core.Point2D(642561,4397059),1);
87
                try {
88
                        // g.setTransform(viewPort.getAffineTransform());
89
                        getCapa().getRecordset().start();
90
                        for (int i = 0; i < sc; i++){
91
                                // Salimos si alguien cancela
92
                                if (cancel.isCanceled()) break;
93
                                
94
                                bounds = shapeBounds.getShapeBounds(i);
95
                                if (extent.intersects(bounds))
96
                                {
97
//                                        Prueba query
98
                                        /* if (bitset.get(i)){
99
                                                g.setPaint(Color.yellow);
100
                                        }else{
101
                                                g.setPaint(Color.black);
102
                                        } */
103
                                        
104
                                        FSymbol symbol = l.getSymbol(i); // Cambiar esto
105
                                        
106
                            // if ((bounds.getHeight() > viewPort.getDist1pixel()) ||
107
                            //          (bounds.getWidth() > viewPort.getDist1pixel()))
108
                            {        
109
                                    geom = driver.getShape(i);
110
                                    if (getCapa().isSelected(i)){
111
                                            
112
                                    }else{
113
                                            geom.draw(g, viewPort, symbol);
114
                                    }
115
                            }
116
                        /* else
117
                        {
118
                            Point2D.Double pOrig = new Point2D.Double(bounds.getMinX(),
119
                                            bounds.getMinY());
120
                            Point2D pDest;
121

122
                            pDest = viewPort.getAffineTransform().transform(pOrig, null);
123

124
                            int pixX = (int) pDest.getX();
125
                            int pixY = (int) pDest.getY();
126

127
                            if ((pixX > 0) && (pixX < image.getWidth())) {
128
                                if ((pixY > 0) && (pixY < image.getHeight())) {
129
                                    // theSymbol = getAssociatedSymbol(numReg);
130
                                    image.setRGB(pixX, pixY,
131
                                        symbol.getRgb());
132
                                }
133
                            }
134
                        } */         
135
                                        
136
                                        
137
                                        
138
                                        
139
                                }
140
                        }
141
                } catch(IOException e) {
142
                        throw new DriverIOException(e);
143
                } catch (DriverException e) {
144
                        throw new DriverIOException(e);
145
                }
146

    
147
                
148
                long t2 = System.currentTimeMillis();
149
                adapter.stop();
150
                
151
                System.out.println(t2 - t1);
152
        }
153
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverIOException, DriverLoadException, DriverException {
154
                super.draw(null, g, viewPort, cancel);  // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!!
155
                
156
        }
157
        
158
}