svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / ShpStrategy.java @ 244
History | View | Annotate | Download (3.87 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 |
|
13 |
import org.geotools.renderer.style.Style2D; |
14 |
|
15 |
import com.iver.cit.gvsig.fmap.ViewPort; |
16 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
17 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
18 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
19 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
20 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
21 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
22 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
23 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
24 |
|
25 |
|
26 |
/**
|
27 |
* Esta clase definir? las operaciones de la interfaz FLyrVect de la manera m?s ?ptima para los ficheros shp.
|
28 |
*/
|
29 |
public class ShpStrategy extends DefaultStrategy { |
30 |
|
31 |
/**
|
32 |
* @param capa
|
33 |
*/
|
34 |
public ShpStrategy(FLyrVect capa) {
|
35 |
super(capa);
|
36 |
} |
37 |
/**
|
38 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
39 |
*/
|
40 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort) |
41 |
throws DriverIOException {
|
42 |
VectorialAdapter adapter = getCapa().getSource(); |
43 |
BoundedShapes shapeBounds = (BoundedShapes) adapter.getDriver(); |
44 |
VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver(); |
45 |
|
46 |
adapter.start(); |
47 |
|
48 |
FGeometry geom = adapter.getShape(0);
|
49 |
Legend l = getCapa().getLegend(geom.getType()); |
50 |
Rectangle2D extent = viewPort.getAdjustedExtent();
|
51 |
AffineTransform at = viewPort.getAffineTransform();
|
52 |
|
53 |
int sc;
|
54 |
|
55 |
Rectangle2D bounds;
|
56 |
|
57 |
sc = adapter.getShapeCount(); |
58 |
long t1 = System.currentTimeMillis(); |
59 |
//Prueba query
|
60 |
///BitSet bitset=this.queryByPoint((QueriedPoint)new QueriedPoint(904561,4712059),200000);
|
61 |
///BitSet bitset=this.queryByRect(new Rectangle2D.Double(304561,3712059,500000,500000));
|
62 |
// BitSet bitset=this.queryByShape((FGeometry)new com.iver.cit.gvsig.fmap.core.Point2D(642561,4397059),1);
|
63 |
for (int i = 0; i < sc; i++){ |
64 |
try {
|
65 |
bounds = shapeBounds.getShapeBounds(i); |
66 |
if (extent.intersects(bounds))
|
67 |
{ |
68 |
// Prueba query
|
69 |
/* if (bitset.get(i)){
|
70 |
g.setPaint(Color.yellow);
|
71 |
}else{
|
72 |
g.setPaint(Color.black);
|
73 |
} */
|
74 |
Style2D symbol = l.getSymbol(null); // Cambiar esto |
75 |
if ((bounds.getHeight() > viewPort.getDist1pixel()) ||
|
76 |
(bounds.getWidth() > viewPort.getDist1pixel())) |
77 |
{ |
78 |
geom = driver.getShape(i); |
79 |
geom.draw(g, viewPort, symbol); |
80 |
} |
81 |
else
|
82 |
{ |
83 |
Point2D.Double pOrig = new Point2D.Double(bounds.getMinX(), |
84 |
bounds.getMinY()); |
85 |
Point2D pDest;
|
86 |
|
87 |
pDest = viewPort.getAffineTransform().transform(pOrig, null);
|
88 |
|
89 |
int pixX = (int) pDest.getX(); |
90 |
int pixY = (int) pDest.getY(); |
91 |
|
92 |
if ((pixX > 0) && (pixX < image.getWidth())) { |
93 |
if ((pixY > 0) && (pixY < image.getHeight())) { |
94 |
// theSymbol = getAssociatedSymbol(numReg);
|
95 |
image.setRGB(pixX, pixY, |
96 |
Color.GRAY.getRGB());
|
97 |
} |
98 |
} |
99 |
} |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
} |
105 |
} catch(IOException e) { |
106 |
throw new DriverIOException(e); |
107 |
} |
108 |
} |
109 |
|
110 |
|
111 |
long t2 = System.currentTimeMillis(); |
112 |
adapter.stop(); |
113 |
|
114 |
System.out.println(t2 - t1);
|
115 |
} |
116 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverIOException { |
117 |
super.draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!! |
118 |
|
119 |
} |
120 |
|
121 |
} |