root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / ShpStrategy.java @ 2976
History | View | Annotate | Download (8.32 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 java.awt.Graphics2D; |
44 |
import java.awt.geom.Point2D; |
45 |
import java.awt.geom.Rectangle2D; |
46 |
import java.awt.image.BufferedImage; |
47 |
import java.io.IOException; |
48 |
import java.util.BitSet; |
49 |
|
50 |
import org.apache.log4j.Logger; |
51 |
import org.cresques.cts.ICoordTrans; |
52 |
import org.geotools.resources.geometry.XRectangle2D; |
53 |
|
54 |
import com.iver.cit.gvsig.fmap.DriverException; |
55 |
import com.iver.cit.gvsig.fmap.ViewPort; |
56 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
57 |
import com.iver.cit.gvsig.fmap.core.FShape; |
58 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
59 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
60 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
61 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
62 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
63 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
64 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
65 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
66 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
67 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
68 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
69 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
70 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
71 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
72 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
73 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
74 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo; |
75 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
76 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
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 |
if (adapter.getShapeCount() <= 0) |
104 |
{ |
105 |
logger.debug("Layer:" + getCapa().getName() + " sin registros"); |
106 |
return;
|
107 |
} |
108 |
Selectable selection = (Selectable) getCapa(); |
109 |
ICoordTrans ct = getCapa().getCoordTrans(); |
110 |
BitSet bitSet = selection.getSelection();
|
111 |
BoundedShapes shapeBounds = (BoundedShapes) adapter.getDriver(); |
112 |
VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver(); |
113 |
logger.debug("adapter.start() -> Layer:" + getCapa().getName());
|
114 |
adapter.start(); |
115 |
IGeometry geom; |
116 |
if (adapter.getShapeCount()>0){ |
117 |
geom = adapter.getShape(0);
|
118 |
} |
119 |
VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) getCapa()).getLegend(); |
120 |
|
121 |
if (l instanceof ClassifiedLegendInfo) { |
122 |
ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) l; |
123 |
FSymbol[] symbs = clsfLegend.getSymbols();
|
124 |
//double rSym = 0;
|
125 |
//double maxRSym = -1;
|
126 |
|
127 |
for (int i = 0; i < symbs.length; i++) { |
128 |
// TODO: REVISAR LOS SIMBOLOS Y SUS TAMA?OS
|
129 |
|
130 |
/* Style2D pointSymbol = symbs[i].getPointStyle2D();
|
131 |
if (pointSymbol instanceof MarkStyle2D)
|
132 |
{
|
133 |
MarkStyle2D mrk2D = (MarkStyle2D) pointSymbol;
|
134 |
rSym = viewPort.toMapDistance(mrk2D.getSize());
|
135 |
if (maxRSym < rSym)
|
136 |
maxRSym = rSym;
|
137 |
}*/
|
138 |
} |
139 |
} |
140 |
|
141 |
Rectangle2D extent = viewPort.getAdjustedExtent();
|
142 |
//AffineTransform at = viewPort.getAffineTransform();
|
143 |
|
144 |
int sc;
|
145 |
|
146 |
Rectangle2D bounds;
|
147 |
|
148 |
sc = adapter.getShapeCount(); |
149 |
|
150 |
long t1 = System.currentTimeMillis(); |
151 |
logger.debug("getCapa().getRecordset().start()");
|
152 |
((AlphanumericData) getCapa()).getRecordset().start(); |
153 |
|
154 |
// TODO: A revisar si es o no conveniente este sistema
|
155 |
// de comunicaci?n con los drivers.
|
156 |
DriverAttributes attr = adapter.getDriverAttributes(); |
157 |
boolean bMustClone = false; |
158 |
if (attr != null) |
159 |
{ |
160 |
if (attr.isLoadedInMemory())
|
161 |
{ |
162 |
bMustClone = attr.isLoadedInMemory(); |
163 |
} |
164 |
} |
165 |
|
166 |
|
167 |
for (int i = 0; i < sc; i++) { |
168 |
// Salimos si alguien cancela
|
169 |
if (cancel.isCanceled()) {
|
170 |
break;
|
171 |
} |
172 |
|
173 |
bounds = shapeBounds.getShapeBounds(i); |
174 |
|
175 |
if (ct != null) { |
176 |
bounds = ct.convert(bounds); |
177 |
} |
178 |
|
179 |
if (XRectangle2D.intersectInclusive(extent, bounds)) {
|
180 |
FSymbol symbol = l.getSymbol(i); |
181 |
|
182 |
if (bitSet.get(i)) {
|
183 |
symbol = FSymbol.getSymbolForSelection(symbol); |
184 |
} |
185 |
|
186 |
boolean bPoint = (shapeBounds.getShapeType(i) == FShape.POINT);
|
187 |
|
188 |
if (bPoint ||
|
189 |
((bounds.getHeight() > viewPort.getDist1pixel()) || |
190 |
(bounds.getWidth() > viewPort.getDist1pixel()))) { |
191 |
geom = driver.getShape(i); |
192 |
|
193 |
// PRUEBA DE VELOCIDAD
|
194 |
// geom = ShapeFactory.createPolygon2D(new GeneralPathX(bounds));
|
195 |
|
196 |
if (ct != null) { |
197 |
if (bMustClone)
|
198 |
geom = geom.cloneGeometry(); |
199 |
geom.reProject(ct); |
200 |
} |
201 |
// FJP: CAMBIO: Sabemos que vamos a dibujar sobre una
|
202 |
// imagen, con coordenadas enteras, as?
|
203 |
// que lo tenemos en cuenta.
|
204 |
// ANTES: geom.draw(g, viewPort, symbol);
|
205 |
// AHORA:
|
206 |
// geom.drawInts(g, viewPort, symbol);
|
207 |
geom.draw(g, viewPort, symbol); |
208 |
|
209 |
|
210 |
} else {
|
211 |
Point2D.Double pOrig = new Point2D.Double(bounds.getMinX(), |
212 |
bounds.getMinY()); |
213 |
Point2D pDest, pDest2;
|
214 |
|
215 |
pDest = viewPort.getAffineTransform().transform(pOrig, null);
|
216 |
pDest2 = g.getTransform().transform(pDest, null);
|
217 |
|
218 |
int pixX = (int) pDest2.getX(); |
219 |
int pixY = (int) pDest2.getY(); |
220 |
if (symbol ==null) |
221 |
continue;
|
222 |
if ((pixX > 0) && (pixX < image.getWidth())) { |
223 |
if ((pixY > 0) && (pixY < image.getHeight())) { |
224 |
image.setRGB(pixX, pixY, symbol.getRgb()); |
225 |
} |
226 |
} |
227 |
} |
228 |
} |
229 |
} |
230 |
|
231 |
logger.debug("getCapa().getRecordset().stop()");
|
232 |
((AlphanumericData) getCapa()).getRecordset().stop(); |
233 |
|
234 |
long t2 = System.currentTimeMillis(); |
235 |
logger.debug("adapter.stop()");
|
236 |
adapter.stop(); |
237 |
|
238 |
System.out.println(t2 - t1);
|
239 |
} catch (DriverIOException e) {
|
240 |
throw new DriverException(e); |
241 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
242 |
throw new DriverException(e); |
243 |
} catch (DriverException e) {
|
244 |
throw new DriverException(e); |
245 |
} catch (IOException e) { |
246 |
throw new DriverException(e); |
247 |
} |
248 |
} |
249 |
|
250 |
/**
|
251 |
* M?todo utilizado para dibujar sobre el graphics que se pasa como
|
252 |
* par?metro, pensado para utilizarse para imprimir.
|
253 |
*
|
254 |
* @param g Graphics2D
|
255 |
* @param viewPort ViewPort.
|
256 |
* @param cancel
|
257 |
*
|
258 |
* @throws DriverException
|
259 |
*/
|
260 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) |
261 |
throws DriverException {
|
262 |
super.draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!! |
263 |
} |
264 |
} |