Statistics
| Revision:

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

History | View | Annotate | Download (4 KB)

1
/* Generated by Together */
2

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

    
5
import java.awt.Color;
6
import java.awt.Graphics2D;
7
import java.awt.geom.AffineTransform;
8
import java.awt.geom.Point2D;
9
import java.awt.geom.Rectangle2D;
10
import java.awt.image.BufferedImage;
11
import java.io.IOException;
12
import java.util.BitSet;
13

    
14
import org.geotools.renderer.style.Style2D;
15

    
16
import com.iver.cit.gvsig.fmap.ViewPort;
17
import com.iver.cit.gvsig.fmap.core.FGeometry;
18
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
19
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
20
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
21
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
22
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
23
import com.iver.cit.gvsig.fmap.operations.Cancellable;
24
import com.iver.cit.gvsig.fmap.rendering.Legend;
25
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
26

    
27

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

    
33
        /**
34
         * @param capa
35
         */
36
        public ShpStrategy(FLyrVect capa) {
37
                super(capa);
38
        }
39
        /**
40
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
41
         */
42
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel)
43
                        throws DriverIOException {
44
                VectorialAdapter adapter = getCapa().getSource();
45
                BoundedShapes shapeBounds = (BoundedShapes) adapter.getDriver();
46
                VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver();
47
                
48
                adapter.start();
49
                
50
                FGeometry geom = adapter.getShape(0);
51
                Legend l = getCapa().getLegend();
52
                Rectangle2D extent = viewPort.getAdjustedExtent();
53
                AffineTransform at = viewPort.getAffineTransform();
54
                
55
                int sc;
56
                
57
                Rectangle2D bounds;
58

    
59
                sc = adapter.getShapeCount();
60
                long t1 = System.currentTimeMillis();
61
                //Prueba query
62
                ///BitSet bitset=this.queryByPoint((QueriedPoint)new QueriedPoint(904561,4712059),200000);
63
                ///BitSet bitset=this.queryByRect(new Rectangle2D.Double(304561,3712059,500000,500000));
64
                // BitSet bitset=this.queryByShape((FGeometry)new com.iver.cit.gvsig.fmap.core.Point2D(642561,4397059),1);
65
                try {
66
                        for (int i = 0; i < sc; i++){                                
67
                                bounds = shapeBounds.getShapeBounds(i);
68
                                if (extent.intersects(bounds))
69
                                {
70
//                                        Prueba query
71
                                        /* if (bitset.get(i)){
72
                                                g.setPaint(Color.yellow);
73
                                        }else{
74
                                                g.setPaint(Color.black);
75
                                        } */
76
                                        FStyle2D symbol = l.getSymbol(null); // Cambiar esto
77
                            if ((bounds.getHeight() > viewPort.getDist1pixel()) ||
78
                                     (bounds.getWidth() > viewPort.getDist1pixel()))
79
                            {        
80
                                    Style2D style2D = symbol.getStyle2D();
81
                                    geom = driver.getShape(i);
82
                                    geom.draw(g, viewPort, style2D);
83
                            }
84
                        else
85
                        {
86
                            Point2D.Double pOrig = new Point2D.Double(bounds.getMinX(),
87
                                            bounds.getMinY());
88
                            Point2D pDest;
89

    
90
                            pDest = viewPort.getAffineTransform().transform(pOrig, null);
91

    
92
                            int pixX = (int) pDest.getX();
93
                            int pixY = (int) pDest.getY();
94

    
95
                            if ((pixX > 0) && (pixX < image.getWidth())) {
96
                                if ((pixY > 0) && (pixY < image.getHeight())) {
97
                                    // theSymbol = getAssociatedSymbol(numReg);
98
                                    image.setRGB(pixX, pixY,
99
                                        symbol.getRgb());
100
                                }
101
                            }
102
                        }         
103
                                        
104
                                        
105
                                        
106
                                        
107
                                }
108
                        }
109
                } catch(IOException e) {
110
                        throw new DriverIOException(e);
111
                }
112

    
113
                
114
                long t2 = System.currentTimeMillis();
115
                adapter.stop();
116
                
117
                System.out.println(t2 - t1);
118
        }
119
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverIOException {
120
                super.draw(null, g, viewPort, cancel);  // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!!
121
                
122
        }
123
        
124
}