svn-gvsig-desktop / tags / v1_0_RELEASE / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / ShpStrategy.java @ 9167
History | View | Annotate | Download (20.8 KB)
1 | 1100 | fjp | /* 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 | 214 | fernando | package com.iver.cit.gvsig.fmap.operations.strategies; |
42 | |||
43 | 2412 | caballero | 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 | 2979 | fjp | import java.util.List; |
50 | 2412 | caballero | |
51 | 9013 | caballero | import javax.print.attribute.PrintRequestAttributeSet; |
52 | |||
53 | 2412 | caballero | import org.apache.log4j.Logger; |
54 | import org.cresques.cts.ICoordTrans; |
||
55 | import org.geotools.resources.geometry.XRectangle2D; |
||
56 | |||
57 | 3963 | caballero | import com.hardcode.driverManager.DriverLoadException; |
58 | 652 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
59 | 214 | fernando | import com.iver.cit.gvsig.fmap.ViewPort; |
60 | 597 | fjp | import com.iver.cit.gvsig.fmap.core.FShape; |
61 | 305 | fjp | import com.iver.cit.gvsig.fmap.core.IGeometry; |
62 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.core.ISymbol; |
63 | 214 | fernando | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
64 | 1233 | fjp | import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
65 | 214 | fernando | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
66 | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
||
67 | 2979 | fjp | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
68 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.FLayer; |
69 | 2979 | fjp | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
70 | 3940 | caballero | import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
71 | 5224 | fjp | import com.iver.cit.gvsig.fmap.layers.SpatialCache; |
72 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
73 | import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
||
74 | import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
||
75 | import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
||
76 | 322 | fernando | import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo; |
77 | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
||
78 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
79 | import com.iver.utiles.swing.threads.CancellableMonitorable; |
||
80 | 2979 | fjp | import com.vividsolutions.jts.geom.Geometry; |
81 | import com.vividsolutions.jts.geom.IntersectionMatrix; |
||
82 | 214 | fernando | |
83 | /**
|
||
84 | 1034 | vcaballero | * Esta clase definir? las operaciones de la interfaz FLyrVect de la manera m?s
|
85 | * ?ptima para los ficheros shp.
|
||
86 | 214 | fernando | */
|
87 | public class ShpStrategy extends DefaultStrategy { |
||
88 | 5813 | fjp | private static Logger logger = Logger |
89 | .getLogger(ShpStrategy.class.getName()); |
||
90 | 1034 | vcaballero | |
91 | 214 | fernando | /**
|
92 | 1034 | vcaballero | * Crea una ShpStrategy.
|
93 | 8765 | jjdelcerro | *
|
94 | 214 | fernando | * @param capa
|
95 | */
|
||
96 | 562 | fernando | public ShpStrategy(FLayer capa) {
|
97 | 214 | fernando | super(capa);
|
98 | } |
||
99 | 1034 | vcaballero | |
100 | 214 | fernando | /**
|
101 | 1034 | vcaballero | * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
102 | 8765 | jjdelcerro | * java.awt.Graphics2D, ISymbol)
|
103 | 214 | fernando | */
|
104 | 1034 | vcaballero | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
105 | 5813 | fjp | Cancellable cancel) throws DriverException {
|
106 | 1034 | vcaballero | try {
|
107 | 3940 | caballero | ReadableVectorial adapter = ((SingleLayer) getCapa()).getSource(); |
108 | 5813 | fjp | if (adapter.getShapeCount() <= 0) { |
109 | 8765 | jjdelcerro | // logger.info("Layer:" + getCapa().getName() + " sin registros");
|
110 | 5813 | fjp | return;
|
111 | 1122 | fjp | } |
112 | 5490 | caballero | |
113 | 5813 | fjp | // Selectable selection = (Selectable) getCapa();
|
114 | FLyrVect lyr = (FLyrVect) getCapa(); |
||
115 | Selectable selectable = lyr.getRecordset(); |
||
116 | ICoordTrans ct = getCapa().getCoordTrans(); |
||
117 | 3998 | fjp | FBitSet bitSet = selectable.getSelection(); |
118 | 3980 | caballero | BoundedShapes shapeBounds; |
119 | if (adapter instanceof BoundedShapes) |
||
120 | 5813 | fjp | shapeBounds = (BoundedShapes) adapter; |
121 | 3980 | caballero | else
|
122 | shapeBounds = (BoundedShapes) adapter.getDriver(); |
||
123 | 5813 | fjp | // VectorialFileDriver driver = (VectorialFileDriver)
|
124 | // adapter.getDriver();
|
||
125 | 3025 | fjp | // logger.debug("adapter.start() -> Layer:" + getCapa().getName());
|
126 | 1034 | vcaballero | adapter.start(); |
127 | 1128 | vcaballero | IGeometry geom; |
128 | 8765 | jjdelcerro | // if (adapter.getShapeCount() > 0) {
|
129 | // geom = adapter.getShape(0);
|
||
130 | // }
|
||
131 | 5813 | fjp | VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) getCapa()) |
132 | .getLegend(); |
||
133 | 1034 | vcaballero | |
134 | if (l instanceof ClassifiedLegendInfo) { |
||
135 | ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) l; |
||
136 | 8765 | jjdelcerro | ISymbol[] symbs = clsfLegend.getSymbols();
|
137 | 5813 | fjp | // double rSym = 0;
|
138 | // double maxRSym = -1;
|
||
139 | 1034 | vcaballero | |
140 | for (int i = 0; i < symbs.length; i++) { |
||
141 | // TODO: REVISAR LOS SIMBOLOS Y SUS TAMA?OS
|
||
142 | |||
143 | 5813 | fjp | /*
|
144 | * Style2D pointSymbol = symbs[i].getPointStyle2D(); if
|
||
145 | * (pointSymbol instanceof MarkStyle2D) { MarkStyle2D mrk2D =
|
||
146 | * (MarkStyle2D) pointSymbol; rSym =
|
||
147 | * viewPort.toMapDistance(mrk2D.getSize()); if (maxRSym <
|
||
148 | * rSym) maxRSym = rSym; }
|
||
149 | */
|
||
150 | 1034 | vcaballero | } |
151 | 281 | fjp | } |
152 | 214 | fernando | |
153 | 1034 | vcaballero | Rectangle2D extent = viewPort.getAdjustedExtent();
|
154 | 5813 | fjp | // AffineTransform at = viewPort.getAffineTransform();
|
155 | 1034 | vcaballero | |
156 | int sc;
|
||
157 | |||
158 | Rectangle2D bounds;
|
||
159 | |||
160 | long t1 = System.currentTimeMillis(); |
||
161 | 3025 | fjp | // logger.debug("getCapa().getRecordset().start()");
|
162 | 3963 | caballero | ((FLyrVect) getCapa()).getRecordset().start(); |
163 | 3940 | caballero | |
164 | 1233 | fjp | // TODO: A revisar si es o no conveniente este sistema
|
165 | // de comunicaci?n con los drivers.
|
||
166 | DriverAttributes attr = adapter.getDriverAttributes(); |
||
167 | boolean bMustClone = false; |
||
168 | 5813 | fjp | if (attr != null) { |
169 | if (attr.isLoadedInMemory()) {
|
||
170 | bMustClone = attr.isLoadedInMemory(); |
||
171 | } |
||
172 | 1233 | fjp | } |
173 | 3940 | caballero | |
174 | 5813 | fjp | List lstIndexes = null; |
175 | 3940 | caballero | |
176 | 5813 | fjp | // If area of needed extent is less than fullExtent / 4,
|
177 | // it will be worthy to use SpatialIndex.
|
||
178 | // Otherwhise, we will not use it.
|
||
179 | 3601 | fjp | boolean bUseSpatialIndex = false; |
180 | 5813 | fjp | sc = adapter.getShapeCount(); |
181 | // if (lyr.getSpatialIndex() != null) AZABALA
|
||
182 | // long t11 = System.currentTimeMillis();
|
||
183 | if (lyr.getISpatialIndex() != null) { |
||
184 | if (isSpatialIndexNecessary(extent)) {
|
||
185 | lstIndexes = lyr.getISpatialIndex().query(extent); |
||
186 | // If the layer is reprojected, spatial index was created
|
||
187 | // in its own projection, so we must to apply an inverse
|
||
188 | // transform
|
||
189 | if (ct != null) { |
||
190 | Rectangle2D newExtent = ct.getInverted()
|
||
191 | .convert(extent); |
||
192 | // Rectangle2D newExtent = ct.convert(extent);
|
||
193 | // lstIndexes = lyr.getISpatialIndex().query(extent);
|
||
194 | lstIndexes = lyr.getISpatialIndex().query(newExtent); |
||
195 | } else {
|
||
196 | lstIndexes = lyr.getISpatialIndex().query(extent); |
||
197 | } |
||
198 | sc = lstIndexes.size(); |
||
199 | bUseSpatialIndex = true;
|
||
200 | }// if
|
||
201 | }// if
|
||
202 | /*
|
||
203 | * long t12 = System.currentTimeMillis(); System.out.println("Tiempo
|
||
204 | * en mirar el ?ndice espacial y recuperar los ?ndices:" +
|
||
205 | * (t12-t11)); System.out.println("Numero de ?ndices:" + sc);
|
||
206 | */
|
||
207 | 5490 | caballero | |
208 | 5813 | fjp | // SpatialCache cache = lyr.createSpatialCache();
|
209 | lyr.getSpatialCache().clearAll(); |
||
210 | SpatialCache cache = lyr.getSpatialCache(); |
||
211 | int i;
|
||
212 | 8765 | jjdelcerro | |
213 | //En OS X con renderer Quartz (JRE<6), mezclar setRGB con dibujado geometrico en mismo BufferedImage
|
||
214 | //provoca ralentizaci?n brutal. Lo evitamos separando los setRGB en otro BufferedImage y juntandolos luego.
|
||
215 | 7502 | mija | boolean MAC_OS_X = System.getProperty("os.name").toLowerCase().startsWith("mac os x"); |
216 | 8765 | jjdelcerro | BufferedImage auxBI = null; |
217 | 7502 | mija | if (MAC_OS_X) {
|
218 | auxBI = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); |
||
219 | 8765 | jjdelcerro | } |
220 | 7502 | mija | |
221 | 8765 | jjdelcerro | |
222 | 3560 | fjp | for (int aux = 0; aux < sc; aux++) { |
223 | 305 | fjp | // Salimos si alguien cancela
|
224 | 5813 | fjp | if (cancel != null) { |
225 | // azabala (por si acaso, al arreglar bug de process)
|
||
226 | 4895 | azabala | if (cancel.isCanceled()) {
|
227 | break;
|
||
228 | } |
||
229 | 1034 | vcaballero | } |
230 | 5813 | fjp | if (bUseSpatialIndex) {
|
231 | Integer idRec = (Integer) lstIndexes.get(aux); |
||
232 | i = idRec.intValue(); |
||
233 | } else {
|
||
234 | i = aux; |
||
235 | } |
||
236 | 214 | fernando | bounds = shapeBounds.getShapeBounds(i); |
237 | 1034 | vcaballero | if (ct != null) { |
238 | 1233 | fjp | bounds = ct.convert(bounds); |
239 | 1034 | vcaballero | } |
240 | if (XRectangle2D.intersectInclusive(extent, bounds)) {
|
||
241 | 8765 | jjdelcerro | ISymbol symbol = l.getSymbol(i); |
242 | 1034 | vcaballero | |
243 | if (bitSet.get(i)) {
|
||
244 | 8765 | jjdelcerro | symbol = symbol.getSymbolForSelection(); |
245 | 3940 | caballero | } |
246 | 1034 | vcaballero | |
247 | 8765 | jjdelcerro | if (symbol == null) |
248 | continue;
|
||
249 | |||
250 | 597 | fjp | boolean bPoint = (shapeBounds.getShapeType(i) == FShape.POINT);
|
251 | 239 | fjp | |
252 | 5813 | fjp | if (bPoint
|
253 | || ((bounds.getHeight() > viewPort.getDist1pixel()) || (bounds |
||
254 | 8765 | jjdelcerro | .getWidth() > viewPort.getDist1pixel()))) { |
255 | 3601 | fjp | geom = adapter.getShape(i); |
256 | 3940 | caballero | |
257 | 5813 | fjp | // PRUEBA DE VELOCIDAD
|
258 | // geom = ShapeFactory.createPolygon2D(new
|
||
259 | // GeneralPathX(bounds));
|
||
260 | 239 | fjp | |
261 | 1034 | vcaballero | if (ct != null) { |
262 | 5813 | fjp | if (bMustClone)
|
263 | geom = geom.cloneGeometry(); |
||
264 | 1034 | vcaballero | geom.reProject(ct); |
265 | } |
||
266 | 5813 | fjp | if (lyr.isSpatialCacheEnabled()) {
|
267 | if (cache.getMaxFeatures() >= cache.size()) {
|
||
268 | // Ya reproyectado todo
|
||
269 | cache.insert(bounds, geom); |
||
270 | 5224 | fjp | } |
271 | } |
||
272 | 5490 | caballero | |
273 | 5813 | fjp | // FJP: CAMBIO: Sabemos que vamos a dibujar sobre una
|
274 | // imagen, con coordenadas enteras, as?
|
||
275 | // que lo tenemos en cuenta.
|
||
276 | 2859 | fjp | // ANTES: geom.draw(g, viewPort, symbol);
|
277 | 5813 | fjp | // AHORA:
|
278 | geom.drawInts(g, viewPort, symbol); |
||
279 | // geom.draw(g, viewPort, symbol);
|
||
280 | /*
|
||
281 | * if (lyr.isEditing()) { if (bitSet.get(i)) { Handler[]
|
||
282 | * handlers = geom.getHandlers(IGeometry.SELECTHANDLER);
|
||
283 | * FGraphicUtilities.DrawHandlers(g,
|
||
284 | * viewPort.getAffineTransform(), handlers); } }
|
||
285 | */
|
||
286 | 239 | fjp | |
287 | 1034 | vcaballero | } else {
|
288 | 5813 | fjp | Point2D.Double pOrig = new Point2D.Double(bounds |
289 | .getMinX(), bounds.getMinY()); |
||
290 | 2469 | fjp | Point2D pDest, pDest2;
|
291 | 1034 | vcaballero | |
292 | 5813 | fjp | pDest = viewPort.getAffineTransform().transform(pOrig, |
293 | null);
|
||
294 | pDest2 = g.getTransform().transform(pDest, null);
|
||
295 | 1034 | vcaballero | |
296 | 2469 | fjp | int pixX = (int) pDest2.getX(); |
297 | int pixY = (int) pDest2.getY(); |
||
298 | 5813 | fjp | if (symbol == null) |
299 | 2412 | caballero | continue;
|
300 | 1034 | vcaballero | if ((pixX > 0) && (pixX < image.getWidth())) { |
301 | if ((pixY > 0) && (pixY < image.getHeight())) { |
||
302 | 7502 | mija | if (MAC_OS_X) {
|
303 | 8765 | jjdelcerro | auxBI.setRGB(pixX, pixY, symbol.getOnePointRgb()); |
304 | 7502 | mija | } else {
|
305 | 8765 | jjdelcerro | image.setRGB(pixX, pixY, symbol.getOnePointRgb()); |
306 | 7502 | mija | } |
307 | 1034 | vcaballero | } |
308 | } |
||
309 | } |
||
310 | 214 | fernando | } |
311 | } |
||
312 | 8765 | jjdelcerro | |
313 | 7502 | mija | if (MAC_OS_X) {
|
314 | g.drawImage(auxBI,0,0,null); |
||
315 | 8765 | jjdelcerro | } |
316 | 1034 | vcaballero | |
317 | 3025 | fjp | // logger.debug("getCapa().getRecordset().stop()");
|
318 | 3963 | caballero | ((FLyrVect) getCapa()).getSource().getRecordset().stop(); |
319 | 214 | fernando | |
320 | 1034 | vcaballero | long t2 = System.currentTimeMillis(); |
321 | 3025 | fjp | // logger.debug("adapter.stop()");
|
322 | 1034 | vcaballero | adapter.stop(); |
323 | |||
324 | 3025 | fjp | // System.out.println(t2 - t1);
|
325 | 1034 | vcaballero | } catch (DriverIOException e) {
|
326 | throw new DriverException(e); |
||
327 | 1828 | fernando | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
328 | 1034 | vcaballero | throw new DriverException(e); |
329 | } catch (DriverException e) {
|
||
330 | throw new DriverException(e); |
||
331 | } catch (IOException e) { |
||
332 | throw new DriverException(e); |
||
333 | 3963 | caballero | } catch (DriverLoadException e) {
|
334 | // TODO Auto-generated catch block
|
||
335 | e.printStackTrace(); |
||
336 | 1034 | vcaballero | } |
337 | 214 | fernando | } |
338 | 1034 | vcaballero | |
339 | /**
|
||
340 | * M?todo utilizado para dibujar sobre el graphics que se pasa como
|
||
341 | * par?metro, pensado para utilizarse para imprimir.
|
||
342 | 8765 | jjdelcerro | *
|
343 | 5813 | fjp | * @param g
|
344 | * Graphics2D
|
||
345 | * @param viewPort
|
||
346 | * ViewPort.
|
||
347 | 1034 | vcaballero | * @param cancel
|
348 | 8765 | jjdelcerro | *
|
349 | 1034 | vcaballero | * @throws DriverException
|
350 | */
|
||
351 | 9013 | caballero | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, PrintRequestAttributeSet printProperties) |
352 | 5813 | fjp | throws DriverException {
|
353 | // super.draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del
|
||
354 | // padre, que es el que va sin acelaraci?n!!
|
||
355 | try {
|
||
356 | ReadableVectorial adapter = ((SingleLayer) getCapa()).getSource(); |
||
357 | if (adapter.getShapeCount() <= 0) { |
||
358 | 8765 | jjdelcerro | // logger.info("Layer:" + getCapa().getName() + " sin registros");
|
359 | 5813 | fjp | return;
|
360 | } |
||
361 | FLyrVect lyr = (FLyrVect) getCapa(); |
||
362 | 9066 | caballero | lyr.beforePrinting(printProperties); |
363 | |||
364 | 5813 | fjp | Selectable selectable = lyr.getRecordset(); |
365 | ICoordTrans ct = getCapa().getCoordTrans(); |
||
366 | BitSet bitSet = selectable.getSelection();
|
||
367 | BoundedShapes shapeBounds = (BoundedShapes) adapter.getDriver(); |
||
368 | VectorialFileDriver driver = (VectorialFileDriver) adapter |
||
369 | .getDriver(); |
||
370 | // logger.debug("adapter.start() -> Layer:" + getCapa().getName());
|
||
371 | adapter.start(); |
||
372 | IGeometry geom; |
||
373 | if (adapter.getShapeCount() > 0) { |
||
374 | geom = adapter.getShape(0);
|
||
375 | } |
||
376 | VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) getCapa()) |
||
377 | .getLegend(); |
||
378 | 3277 | fjp | |
379 | 5813 | fjp | Rectangle2D extent = viewPort.getAdjustedExtent();
|
380 | // AffineTransform at = viewPort.getAffineTransform();
|
||
381 | 3277 | fjp | |
382 | 5813 | fjp | int sc;
|
383 | 3277 | fjp | |
384 | 5813 | fjp | Rectangle2D bounds;
|
385 | 3277 | fjp | |
386 | 5813 | fjp | sc = adapter.getShapeCount(); |
387 | 3277 | fjp | |
388 | 5813 | fjp | long t1 = System.currentTimeMillis(); |
389 | // logger.debug("getCapa().getRecordset().start()");
|
||
390 | ((AlphanumericData) getCapa()).getRecordset().start(); |
||
391 | 3940 | caballero | |
392 | 5813 | fjp | // TODO: A revisar si es o no conveniente este sistema
|
393 | // de comunicaci?n con los drivers.
|
||
394 | DriverAttributes attr = adapter.getDriverAttributes(); |
||
395 | boolean bMustClone = false; |
||
396 | if (attr != null) { |
||
397 | if (attr.isLoadedInMemory()) {
|
||
398 | bMustClone = attr.isLoadedInMemory(); |
||
399 | } |
||
400 | } |
||
401 | 3277 | fjp | |
402 | 5813 | fjp | for (int i = 0; i < sc; i++) { |
403 | bounds = shapeBounds.getShapeBounds(i); |
||
404 | 3940 | caballero | |
405 | 5813 | fjp | if (ct != null) { |
406 | bounds = ct.convert(bounds); |
||
407 | } |
||
408 | 3277 | fjp | |
409 | 5813 | fjp | if (XRectangle2D.intersectInclusive(extent, bounds)) {
|
410 | 8765 | jjdelcerro | ISymbol symbol = l.getSymbol(i); |
411 | 9092 | caballero | if (symbol == null) |
412 | continue;
|
||
413 | 5813 | fjp | if (bitSet.get(i)) {
|
414 | 8765 | jjdelcerro | symbol = symbol.getSymbolForSelection(); |
415 | 5813 | fjp | } |
416 | 3277 | fjp | |
417 | 5813 | fjp | boolean bPoint = (shapeBounds.getShapeType(i) == FShape.POINT);
|
418 | 3277 | fjp | |
419 | 5813 | fjp | geom = driver.getShape(i); |
420 | 3277 | fjp | |
421 | 5813 | fjp | // PRUEBA DE VELOCIDAD
|
422 | // geom = ShapeFactory.createPolygon2D(new
|
||
423 | // GeneralPathX(bounds));
|
||
424 | 3940 | caballero | |
425 | 5813 | fjp | if (ct != null) { |
426 | if (bMustClone)
|
||
427 | geom = geom.cloneGeometry(); |
||
428 | geom.reProject(ct); |
||
429 | } |
||
430 | 9013 | caballero | |
431 | 5813 | fjp | geom.draw(g, viewPort, symbol); |
432 | 9092 | caballero | |
433 | 5813 | fjp | } |
434 | } |
||
435 | 3277 | fjp | |
436 | 5813 | fjp | // logger.debug("getCapa().getRecordset().stop()");
|
437 | ((AlphanumericData) getCapa()).getRecordset().stop(); |
||
438 | 3277 | fjp | |
439 | 5813 | fjp | long t2 = System.currentTimeMillis(); |
440 | // logger.debug("adapter.stop()");
|
||
441 | adapter.stop(); |
||
442 | 9066 | caballero | lyr.afterPrinting(); |
443 | 5813 | fjp | // System.out.println(t2 - t1);
|
444 | } catch (DriverIOException e) {
|
||
445 | throw new DriverException(e); |
||
446 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
447 | throw new DriverException(e); |
||
448 | } catch (DriverException e) {
|
||
449 | throw new DriverException(e); |
||
450 | } catch (IOException e) { |
||
451 | throw new DriverException(e); |
||
452 | } |
||
453 | 3277 | fjp | |
454 | 9066 | caballero | |
455 | 652 | fernando | } |
456 | 5490 | caballero | |
457 | 5813 | fjp | public FBitSet queryByShape(IGeometry g, int relationship) |
458 | throws DriverException, VisitException {
|
||
459 | 4419 | azabala | return queryByShape(g, relationship, null); |
460 | } |
||
461 | 3940 | caballero | |
462 | 5813 | fjp | /*
|
463 | * (non-Javadoc)
|
||
464 | 8765 | jjdelcerro | *
|
465 | 5813 | fjp | * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.core.IGeometry,
|
466 | * int)
|
||
467 | */
|
||
468 | public FBitSet queryByShape(IGeometry g, int relationship, |
||
469 | CancellableMonitorable cancel) throws DriverException,
|
||
470 | VisitException { |
||
471 | // Si hay un ?ndice espacial, lo usamos para hacer el query.
|
||
472 | FLyrVect lyr = (FLyrVect) capa; |
||
473 | // if (lyr.getSpatialIndex() == null) AZABALA
|
||
474 | if (lyr.getISpatialIndex() == null) |
||
475 | return super.queryByShape(g, relationship, null); |
||
476 | 3940 | caballero | |
477 | 5813 | fjp | long t1 = System.currentTimeMillis(); |
478 | ReadableVectorial va = lyr.getSource(); |
||
479 | ICoordTrans ct = lyr.getCoordTrans(); |
||
480 | Rectangle2D bounds = g.getBounds2D();
|
||
481 | List lstRecs = lyr.getISpatialIndex().query(bounds);
|
||
482 | Integer idRec;
|
||
483 | FBitSet bitset = new FBitSet();
|
||
484 | Geometry jtsShape = g.toJTSGeometry(); |
||
485 | IntersectionMatrix m; |
||
486 | int index;
|
||
487 | try {
|
||
488 | va.start(); |
||
489 | 2979 | fjp | |
490 | 5813 | fjp | for (int i = 0; i < lstRecs.size(); i++) { |
491 | if (cancel != null) { |
||
492 | cancel.reportStep(); |
||
493 | if (cancel.isCanceled()) {
|
||
494 | break;
|
||
495 | } |
||
496 | } |
||
497 | idRec = (Integer) lstRecs.get(i);
|
||
498 | index = idRec.intValue(); |
||
499 | IGeometry geom = va.getShape(index); |
||
500 | 5917 | azabala | if(geom == null) |
501 | continue;
|
||
502 | 5813 | fjp | if (ct != null) { |
503 | geom.reProject(ct); |
||
504 | } |
||
505 | Geometry jtsGeom = geom.toJTSGeometry(); |
||
506 | switch (relationship) {
|
||
507 | case CONTAINS:
|
||
508 | m = jtsShape.relate(jtsGeom); |
||
509 | if (m.isContains()) {
|
||
510 | bitset.set(index, true);
|
||
511 | } |
||
512 | break;
|
||
513 | 2979 | fjp | |
514 | 5813 | fjp | case CROSSES:
|
515 | m = jtsShape.relate(jtsGeom); |
||
516 | if (m.isCrosses(jtsGeom.getDimension(), jtsShape
|
||
517 | .getDimension())) { |
||
518 | bitset.set(index, true);
|
||
519 | } |
||
520 | break;
|
||
521 | 2979 | fjp | |
522 | 5813 | fjp | case DISJOINT:
|
523 | // TODO: CREO QUE EL DISJOINT NO SE PUEDE METER AQUI
|
||
524 | m = jtsShape.relate(jtsGeom); |
||
525 | if (m.isDisjoint()) {
|
||
526 | bitset.set(index, true);
|
||
527 | } |
||
528 | break;
|
||
529 | 2979 | fjp | |
530 | 5813 | fjp | case EQUALS:
|
531 | m = jtsShape.relate(jtsGeom); |
||
532 | if (m.isEquals(jtsGeom.getDimension(), jtsShape
|
||
533 | .getDimension())) { |
||
534 | bitset.set(index, true);
|
||
535 | } |
||
536 | break;
|
||
537 | 2979 | fjp | |
538 | 5813 | fjp | case INTERSECTS:
|
539 | m = jtsShape.relate(jtsGeom); |
||
540 | if (m.isIntersects()) {
|
||
541 | bitset.set(index, true);
|
||
542 | } |
||
543 | break;
|
||
544 | 2979 | fjp | |
545 | 5813 | fjp | case OVERLAPS:
|
546 | m = jtsShape.relate(jtsGeom); |
||
547 | if (m.isOverlaps(jtsGeom.getDimension(), jtsShape
|
||
548 | .getDimension())) { |
||
549 | bitset.set(index, true);
|
||
550 | } |
||
551 | 2979 | fjp | |
552 | 5813 | fjp | break;
|
553 | 2979 | fjp | |
554 | 5813 | fjp | case TOUCHES:
|
555 | m = jtsShape.relate(jtsGeom); |
||
556 | if (m.isTouches(jtsGeom.getDimension(), jtsShape
|
||
557 | .getDimension())) { |
||
558 | bitset.set(index, true);
|
||
559 | } |
||
560 | 2979 | fjp | |
561 | 5813 | fjp | break;
|
562 | 2979 | fjp | |
563 | 5813 | fjp | case WITHIN:
|
564 | m = jtsShape.relate(jtsGeom); |
||
565 | if (m.isWithin()) {
|
||
566 | bitset.set(index, true);
|
||
567 | } |
||
568 | 2979 | fjp | |
569 | 5813 | fjp | break;
|
570 | } |
||
571 | } |
||
572 | va.stop(); |
||
573 | } catch (DriverIOException e) {
|
||
574 | // TODO Auto-generated catch block
|
||
575 | e.printStackTrace(); |
||
576 | } |
||
577 | long t2 = System.currentTimeMillis(); |
||
578 | 8765 | jjdelcerro | // logger.info("queryByShape optimizado sobre la capa " + lyr.getName()
|
579 | // + ". " + (t2 - t1) + " mseg.");
|
||
580 | 5813 | fjp | return bitset;
|
581 | } |
||
582 | 2979 | fjp | |
583 | 5813 | fjp | public FBitSet queryByRect(Rectangle2D rect, CancellableMonitorable cancel) |
584 | throws DriverException {
|
||
585 | // Si hay un ?ndice espacial, lo usamos para hacer el query.
|
||
586 | FLyrVect lyr = (FLyrVect) capa; |
||
587 | if (lyr.getISpatialIndex() == null) |
||
588 | return super.queryByRect(rect, cancel); |
||
589 | 2979 | fjp | |
590 | 5813 | fjp | ReadableVectorial va = lyr.getSource(); |
591 | ICoordTrans ct = lyr.getCoordTrans(); |
||
592 | Rectangle2D bounds = rect;
|
||
593 | List lstRecs = lyr.getISpatialIndex().query(bounds);
|
||
594 | Integer idRec;
|
||
595 | FBitSet bitset = new FBitSet();
|
||
596 | int index;
|
||
597 | try {
|
||
598 | va.start(); |
||
599 | DriverAttributes attr = va.getDriverAttributes(); |
||
600 | boolean bMustClone = false; |
||
601 | if (attr != null) { |
||
602 | if (attr.isLoadedInMemory()) {
|
||
603 | bMustClone = attr.isLoadedInMemory(); |
||
604 | } |
||
605 | } |
||
606 | 2979 | fjp | |
607 | 5813 | fjp | for (int i = 0; i < lstRecs.size(); i++) { |
608 | if (cancel != null) { |
||
609 | cancel.reportStep(); |
||
610 | if (cancel.isCanceled()) {
|
||
611 | va.stop(); |
||
612 | return bitset;
|
||
613 | } |
||
614 | } |
||
615 | idRec = (Integer) lstRecs.get(i);
|
||
616 | index = idRec.intValue(); |
||
617 | IGeometry geom = va.getShape(index); |
||
618 | 5917 | azabala | if(geom == null)//azabala |
619 | continue;
|
||
620 | 5813 | fjp | if (ct != null) { |
621 | if (bMustClone)
|
||
622 | geom = geom.cloneGeometry(); |
||
623 | geom.reProject(ct); |
||
624 | } |
||
625 | if (geom.intersects(rect))
|
||
626 | bitset.set(index, true);
|
||
627 | } |
||
628 | va.stop(); |
||
629 | } catch (DriverIOException e) {
|
||
630 | // TODO Auto-generated catch block
|
||
631 | e.printStackTrace(); |
||
632 | } |
||
633 | return bitset;
|
||
634 | 3940 | caballero | |
635 | 5813 | fjp | } |
636 | 5490 | caballero | |
637 | 5813 | fjp | public void process(FeatureVisitor visitor, Rectangle2D rectangle) |
638 | throws DriverException, VisitException {
|
||
639 | process(visitor, rectangle, null);
|
||
640 | } |
||
641 | 5490 | caballero | |
642 | 5813 | fjp | /**
|
643 | * Processes (by calling visitor.process() method) only those features of
|
||
644 | * the vectorial layer associated which intersects given rectangle2d.
|
||
645 | 8765 | jjdelcerro | *
|
646 | 5813 | fjp | */
|
647 | 5490 | caballero | |
648 | 5813 | fjp | public void process(FeatureVisitor visitor, Rectangle2D rectangle, |
649 | CancellableMonitorable cancel) throws DriverException,
|
||
650 | VisitException { |
||
651 | if (visitor.start(capa)) {
|
||
652 | FLyrVect lyr = (FLyrVect) capa; |
||
653 | // if we dont have spatial index or...
|
||
654 | if (lyr.getISpatialIndex() == null) { |
||
655 | super.process(visitor, rectangle, cancel);
|
||
656 | return;
|
||
657 | } |
||
658 | // if spatial index is not worthy
|
||
659 | if (!isSpatialIndexNecessary(rectangle)) {
|
||
660 | super.process(visitor, rectangle, cancel);
|
||
661 | return;
|
||
662 | } |
||
663 | |||
664 | ReadableVectorial va = lyr.getSource(); |
||
665 | ICoordTrans ct = lyr.getCoordTrans(); |
||
666 | Rectangle2D bounds = rectangle;
|
||
667 | List lstRecs = lyr.getISpatialIndex().query(bounds);
|
||
668 | 5703 | azabala | Integer idRec;
|
669 | 5813 | fjp | int index;
|
670 | try {
|
||
671 | va.start(); |
||
672 | DriverAttributes attr = va.getDriverAttributes(); |
||
673 | boolean bMustClone = false; |
||
674 | if (attr != null) { |
||
675 | if (attr.isLoadedInMemory()) {
|
||
676 | bMustClone = attr.isLoadedInMemory(); |
||
677 | } |
||
678 | } |
||
679 | |||
680 | for (int i = 0; i < lstRecs.size(); i++) { |
||
681 | if (cancel != null) { |
||
682 | cancel.reportStep(); |
||
683 | } |
||
684 | if (verifyCancelation(cancel, va, visitor))
|
||
685 | return;
|
||
686 | idRec = (Integer) lstRecs.get(i);
|
||
687 | index = idRec.intValue(); |
||
688 | IGeometry geom = va.getShape(index); |
||
689 | 5917 | azabala | if(geom == null)//azabala |
690 | continue;
|
||
691 | 5813 | fjp | if (ct != null) { |
692 | if (bMustClone)
|
||
693 | geom = geom.cloneGeometry(); |
||
694 | geom.reProject(ct); |
||
695 | } |
||
696 | if (geom.intersects(rectangle))
|
||
697 | visitor.visit(geom, index); |
||
698 | }// for
|
||
699 | va.stop(); |
||
700 | } catch (DriverIOException e) {
|
||
701 | // TODO Auto-generated catch block
|
||
702 | e.printStackTrace(); |
||
703 | } |
||
704 | }// if visitor.start
|
||
705 | 4200 | azabala | } |
706 | |||
707 | 5813 | fjp | /*
|
708 | * (non-Javadoc)
|
||
709 | 8765 | jjdelcerro | *
|
710 | 5813 | fjp | * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(java.awt.geom.Point2D,
|
711 | * double)
|
||
712 | */
|
||
713 | public FBitSet queryByPoint(Point2D p, double tolerance, |
||
714 | CancellableMonitorable cancel) throws DriverException {
|
||
715 | // TODO: OJO!!!!. Est? implementado como un rectangulo.
|
||
716 | // Lo correcto deber?a ser calculando las distancias reales
|
||
717 | // es decir, con un c?rculo.
|
||
718 | Rectangle2D recPoint = new Rectangle2D.Double(p.getX() |
||
719 | - (tolerance / 2), p.getY() - (tolerance / 2), tolerance, |
||
720 | tolerance); |
||
721 | return queryByRect(recPoint, cancel);
|
||
722 | } |
||
723 | 214 | fernando | } |