root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / ShpStrategy.java @ 1100
History | View | Annotate | Download (7.08 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.operations.strategies; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.DriverException; |
44 |
import com.iver.cit.gvsig.fmap.ViewPort; |
45 |
import com.iver.cit.gvsig.fmap.core.FShape; |
46 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
47 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
48 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
49 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
50 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
51 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
52 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
53 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
54 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
55 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
56 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
57 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
58 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo; |
59 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
60 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
61 |
|
62 |
import org.apache.log4j.Logger; |
63 |
|
64 |
import org.cresques.cts.ICoordTrans; |
65 |
|
66 |
import org.geotools.resources.geometry.XRectangle2D; |
67 |
|
68 |
import java.awt.Graphics2D; |
69 |
import java.awt.geom.AffineTransform; |
70 |
import java.awt.geom.Point2D; |
71 |
import java.awt.geom.Rectangle2D; |
72 |
import java.awt.image.BufferedImage; |
73 |
|
74 |
import java.io.IOException; |
75 |
|
76 |
import java.util.BitSet; |
77 |
|
78 |
|
79 |
/**
|
80 |
* Esta clase definir? las operaciones de la interfaz FLyrVect de la manera m?s
|
81 |
* ?ptima para los ficheros shp.
|
82 |
*/
|
83 |
public class ShpStrategy extends DefaultStrategy { |
84 |
private static Logger logger = Logger.getLogger(ShpStrategy.class.getName()); |
85 |
|
86 |
/**
|
87 |
* Crea una ShpStrategy.
|
88 |
*
|
89 |
* @param capa
|
90 |
*/
|
91 |
public ShpStrategy(FLayer capa) {
|
92 |
super(capa);
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
97 |
* java.awt.Graphics2D, FStyle2D)
|
98 |
*/
|
99 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
100 |
Cancellable cancel) throws DriverException {
|
101 |
try {
|
102 |
VectorialAdapter adapter = ((SingleLayer) getCapa()).getSource(); |
103 |
Selectable selection = (Selectable) getCapa(); |
104 |
ICoordTrans ct = getCapa().getCoordTrans(); |
105 |
BitSet bitSet = selection.getSelection();
|
106 |
BoundedShapes shapeBounds = (BoundedShapes) adapter.getDriver(); |
107 |
VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver(); |
108 |
logger.debug("adapter.start()");
|
109 |
adapter.start(); |
110 |
|
111 |
IGeometry geom = adapter.getShape(0);
|
112 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) getCapa()).getLegend(); |
113 |
|
114 |
if (l instanceof ClassifiedLegendInfo) { |
115 |
ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) l; |
116 |
FSymbol[] symbs = clsfLegend.getSymbols();
|
117 |
double rSym = 0; |
118 |
double maxRSym = -1; |
119 |
|
120 |
for (int i = 0; i < symbs.length; i++) { |
121 |
// TODO: REVISAR LOS SIMBOLOS Y SUS TAMA?OS
|
122 |
|
123 |
/* Style2D pointSymbol = symbs[i].getPointStyle2D();
|
124 |
if (pointSymbol instanceof MarkStyle2D)
|
125 |
{
|
126 |
MarkStyle2D mrk2D = (MarkStyle2D) pointSymbol;
|
127 |
rSym = viewPort.toMapDistance(mrk2D.getSize());
|
128 |
if (maxRSym < rSym)
|
129 |
maxRSym = rSym;
|
130 |
}*/
|
131 |
} |
132 |
} |
133 |
|
134 |
Rectangle2D extent = viewPort.getAdjustedExtent();
|
135 |
AffineTransform at = viewPort.getAffineTransform();
|
136 |
|
137 |
int sc;
|
138 |
|
139 |
Rectangle2D bounds;
|
140 |
|
141 |
sc = adapter.getShapeCount(); |
142 |
|
143 |
long t1 = System.currentTimeMillis(); |
144 |
logger.debug("getCapa().getRecordset().start()");
|
145 |
((AlphanumericData) getCapa()).getRecordset().start(); |
146 |
|
147 |
for (int i = 0; i < sc; i++) { |
148 |
// Salimos si alguien cancela
|
149 |
if (cancel.isCanceled()) {
|
150 |
break;
|
151 |
} |
152 |
|
153 |
bounds = shapeBounds.getShapeBounds(i); |
154 |
|
155 |
if (ct != null) { |
156 |
Point2D pt1 = new Point2D.Double(bounds.getMinX(), |
157 |
bounds.getMinY()); |
158 |
Point2D pt2 = new Point2D.Double(bounds.getMaxX(), |
159 |
bounds.getMaxY()); |
160 |
pt1 = ct.convert(pt1, null);
|
161 |
pt2 = ct.convert(pt2, null);
|
162 |
bounds.setFrameFromDiagonal(pt1, pt2); |
163 |
} |
164 |
|
165 |
if (XRectangle2D.intersectInclusive(extent, bounds)) {
|
166 |
FSymbol symbol = l.getSymbol(i); |
167 |
|
168 |
if (bitSet.get(i)) {
|
169 |
symbol = FSymbol.getSymbolForSelection(symbol); |
170 |
} |
171 |
|
172 |
boolean bPoint = (shapeBounds.getShapeType(i) == FShape.POINT);
|
173 |
|
174 |
if (bPoint ||
|
175 |
((bounds.getHeight() > viewPort.getDist1pixel()) || |
176 |
(bounds.getWidth() > viewPort.getDist1pixel()))) { |
177 |
geom = driver.getShape(i); |
178 |
|
179 |
if (ct != null) { |
180 |
geom.reProject(ct); |
181 |
} |
182 |
|
183 |
geom.draw(g, viewPort, symbol); |
184 |
} else {
|
185 |
Point2D.Double pOrig = new Point2D.Double(bounds.getMinX(), |
186 |
bounds.getMinY()); |
187 |
Point2D pDest;
|
188 |
|
189 |
pDest = viewPort.getAffineTransform().transform(pOrig, |
190 |
null);
|
191 |
|
192 |
int pixX = (int) pDest.getX(); |
193 |
int pixY = (int) pDest.getY(); |
194 |
|
195 |
if ((pixX > 0) && (pixX < image.getWidth())) { |
196 |
if ((pixY > 0) && (pixY < image.getHeight())) { |
197 |
image.setRGB(pixX, pixY, symbol.getRgb()); |
198 |
} |
199 |
} |
200 |
} |
201 |
} |
202 |
} |
203 |
|
204 |
logger.debug("getCapa().getRecordset().stop()");
|
205 |
((AlphanumericData) getCapa()).getRecordset().stop(); |
206 |
|
207 |
long t2 = System.currentTimeMillis(); |
208 |
logger.debug("adapter.stop()");
|
209 |
adapter.stop(); |
210 |
|
211 |
System.out.println(t2 - t1);
|
212 |
} catch (DriverIOException e) {
|
213 |
throw new DriverException(e); |
214 |
} catch (com.hardcode.gdbms.engine.data.DriverException e) {
|
215 |
throw new DriverException(e); |
216 |
} catch (DriverException e) {
|
217 |
throw new DriverException(e); |
218 |
} catch (IOException e) { |
219 |
throw new DriverException(e); |
220 |
} |
221 |
} |
222 |
|
223 |
/**
|
224 |
* M?todo utilizado para dibujar sobre el graphics que se pasa como
|
225 |
* par?metro, pensado para utilizarse para imprimir.
|
226 |
*
|
227 |
* @param g Graphics2D
|
228 |
* @param viewPort ViewPort.
|
229 |
* @param cancel
|
230 |
*
|
231 |
* @throws DriverException
|
232 |
*/
|
233 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) |
234 |
throws DriverException {
|
235 |
super.draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!! |
236 |
} |
237 |
} |