Statistics
| Revision:

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

History | View | Annotate | Download (4.63 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.iver.cit.gvsig.fmap.ViewPort;
15
import com.iver.cit.gvsig.fmap.core.IGeometry;
16
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
17
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
18
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
19
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
20
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
21
import com.iver.cit.gvsig.fmap.operations.Cancellable;
22
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo;
23
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
24
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
25

    
26

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

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

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

112
                            pDest = viewPort.getAffineTransform().transform(pOrig, null);
113

114
                            int pixX = (int) pDest.getX();
115
                            int pixY = (int) pDest.getY();
116

117
                            if ((pixX > 0) && (pixX < image.getWidth())) {
118
                                if ((pixY > 0) && (pixY < image.getHeight())) {
119
                                    // theSymbol = getAssociatedSymbol(numReg);
120
                                    image.setRGB(pixX, pixY,
121
                                        symbol.getRgb());
122
                                }
123
                            }
124
                        } */         
125
                                        
126
                                        
127
                                        
128
                                        
129
                                }
130
                        }
131
                } catch(IOException e) {
132
                        throw new DriverIOException(e);
133
                }
134

    
135
                
136
                long t2 = System.currentTimeMillis();
137
                adapter.stop();
138
                
139
                System.out.println(t2 - t1);
140
        }
141
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverIOException {
142
                super.draw(null, g, viewPort, cancel);  // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!!
143
                
144
        }
145
        
146
}