svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / ShpStrategy.java @ 885
History | View | Annotate | Download (6.02 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.Point2D; |
8 |
import java.awt.geom.Rectangle2D; |
9 |
import java.awt.image.BufferedImage; |
10 |
import java.io.IOException; |
11 |
import java.util.BitSet; |
12 |
|
13 |
import org.apache.log4j.Logger; |
14 |
import org.cresques.cts.ICoordTrans; |
15 |
import org.geotools.resources.geometry.XRectangle2D; |
16 |
|
17 |
import com.hardcode.driverManager.DriverLoadException; |
18 |
import com.iver.cit.gvsig.fmap.DriverException; |
19 |
import com.iver.cit.gvsig.fmap.ViewPort; |
20 |
import com.iver.cit.gvsig.fmap.core.FShape; |
21 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
22 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
23 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
24 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
25 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
26 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
27 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
28 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
29 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
30 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
31 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
32 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
33 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo; |
34 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
35 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
36 |
|
37 |
|
38 |
/**
|
39 |
* Esta clase definir? las operaciones de la interfaz FLyrVect de la manera m?s ?ptima para los ficheros shp.
|
40 |
*/
|
41 |
public class ShpStrategy extends DefaultStrategy { |
42 |
private static Logger logger = Logger.getLogger(ShpStrategy.class.getName()); |
43 |
/**
|
44 |
* @param capa
|
45 |
*/
|
46 |
public ShpStrategy(FLayer capa) {
|
47 |
super(capa);
|
48 |
} |
49 |
/**
|
50 |
* @throws DriverLoadException
|
51 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, FStyle2D)
|
52 |
*/
|
53 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) |
54 |
throws DriverException {
|
55 |
try{
|
56 |
VectorialAdapter adapter = ((SingleLayer)getCapa()).getSource(); |
57 |
Selectable selection = (Selectable) getCapa(); |
58 |
ICoordTrans ct = getCapa().getCoordTrans(); |
59 |
BitSet bitSet = selection.getSelection();
|
60 |
BoundedShapes shapeBounds = (BoundedShapes) adapter.getDriver(); |
61 |
VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver(); |
62 |
logger.debug("adapter.start()");
|
63 |
adapter.start(); |
64 |
|
65 |
IGeometry geom = adapter.getShape(0);
|
66 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial)getCapa()).getLegend(); |
67 |
if (l instanceof ClassifiedLegendInfo) |
68 |
{ |
69 |
ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) l; |
70 |
FSymbol[] symbs = clsfLegend.getSymbols();
|
71 |
double rSym=0, maxRSym = -1; |
72 |
for (int i=0; i < symbs.length; i++) |
73 |
{ |
74 |
// TODO: REVISAR LOS SIMBOLOS Y SUS TAMA?OS
|
75 |
/* Style2D pointSymbol = symbs[i].getPointStyle2D();
|
76 |
if (pointSymbol instanceof MarkStyle2D)
|
77 |
{
|
78 |
MarkStyle2D mrk2D = (MarkStyle2D) pointSymbol;
|
79 |
rSym = viewPort.toMapDistance(mrk2D.getSize());
|
80 |
if (maxRSym < rSym)
|
81 |
maxRSym = rSym;
|
82 |
}*/
|
83 |
|
84 |
} |
85 |
} |
86 |
Rectangle2D extent = viewPort.getAdjustedExtent();
|
87 |
AffineTransform at = viewPort.getAffineTransform();
|
88 |
|
89 |
int sc;
|
90 |
|
91 |
Rectangle2D bounds;
|
92 |
|
93 |
sc = adapter.getShapeCount(); |
94 |
long t1 = System.currentTimeMillis(); |
95 |
logger.debug("getCapa().getRecordset().start()");
|
96 |
((AlphanumericData)getCapa()).getRecordset().start(); |
97 |
for (int i = 0; i < sc; i++){ |
98 |
// Salimos si alguien cancela
|
99 |
if (cancel.isCanceled()) break; |
100 |
|
101 |
bounds = shapeBounds.getShapeBounds(i); |
102 |
if (ct != null) |
103 |
{ |
104 |
Point2D pt1 = new Point2D.Double(bounds.getMinX(), bounds.getMinY()); |
105 |
Point2D pt2 = new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()); |
106 |
pt1 = ct.convert(pt1, null);
|
107 |
pt2 = ct.convert(pt2, null);
|
108 |
bounds.setFrameFromDiagonal(pt1, pt2); |
109 |
} |
110 |
if (XRectangle2D.intersectInclusive(extent, bounds))
|
111 |
{ |
112 |
FSymbol symbol = l.getSymbol(i); |
113 |
if (bitSet.get(i)){
|
114 |
symbol = FSymbol.getSymbolForSelection(symbol); |
115 |
} |
116 |
|
117 |
boolean bPoint = (shapeBounds.getShapeType(i) == FShape.POINT);
|
118 |
if (bPoint || ((bounds.getHeight() > viewPort.getDist1pixel()) ||
|
119 |
(bounds.getWidth() > viewPort.getDist1pixel()))) |
120 |
{ |
121 |
geom = driver.getShape(i); |
122 |
if (ct != null) |
123 |
{ |
124 |
geom.reProject(ct); |
125 |
} |
126 |
geom.draw(g, viewPort, symbol); |
127 |
} |
128 |
else
|
129 |
{ |
130 |
Point2D.Double pOrig = new Point2D.Double(bounds.getMinX(), |
131 |
bounds.getMinY()); |
132 |
Point2D pDest;
|
133 |
|
134 |
pDest = viewPort.getAffineTransform().transform(pOrig, null);
|
135 |
|
136 |
int pixX = (int) pDest.getX(); |
137 |
int pixY = (int) pDest.getY(); |
138 |
|
139 |
if ((pixX > 0) && (pixX < image.getWidth())) { |
140 |
if ((pixY > 0) && (pixY < image.getHeight())) { |
141 |
image.setRGB(pixX, pixY, |
142 |
symbol.getRgb()); |
143 |
} |
144 |
} |
145 |
} |
146 |
|
147 |
|
148 |
|
149 |
|
150 |
} |
151 |
} |
152 |
logger.debug("getCapa().getRecordset().stop()");
|
153 |
((AlphanumericData)getCapa()).getRecordset().stop(); |
154 |
|
155 |
|
156 |
long t2 = System.currentTimeMillis(); |
157 |
logger.debug("adapter.stop()");
|
158 |
adapter.stop(); |
159 |
|
160 |
System.out.println(t2 - t1);
|
161 |
}catch(DriverIOException e){
|
162 |
throw new DriverException(e); |
163 |
} catch (com.hardcode.gdbms.engine.data.DriverException e) {
|
164 |
throw new DriverException(e); |
165 |
} catch (DriverException e) {
|
166 |
throw new DriverException(e); |
167 |
} catch (IOException e) { |
168 |
throw new DriverException(e); |
169 |
} |
170 |
} |
171 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException { |
172 |
super.draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!! |
173 |
|
174 |
} |
175 |
|
176 |
} |