root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 5390
History | View | Annotate | Download (31.2 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.layers; |
42 | |||
43 | 1828 | fernando | import java.awt.Graphics2D; |
44 | 5048 | ldiaz | import java.awt.Point; |
45 | 1828 | fernando | import java.awt.geom.Point2D; |
46 | import java.awt.geom.Rectangle2D; |
||
47 | import java.awt.image.BufferedImage; |
||
48 | 4977 | azabala | import java.io.File; |
49 | 2978 | fjp | import java.io.IOException; |
50 | 1828 | fernando | |
51 | import org.apache.log4j.Logger; |
||
52 | import org.cresques.cts.ICoordTrans; |
||
53 | |||
54 | 408 | fernando | import com.hardcode.driverManager.DriverLoadException; |
55 | 2694 | fjp | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
56 | 1828 | fernando | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
57 | 470 | fjp | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
58 | 652 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
59 | 214 | fernando | import com.iver.cit.gvsig.fmap.ViewPort; |
60 | 757 | fjp | import com.iver.cit.gvsig.fmap.core.IGeometry; |
61 | 5152 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
62 | 2978 | fjp | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
63 | 214 | fernando | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
64 | 2778 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
65 | 3301 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
66 | 5390 | caballero | import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
67 | 4256 | caballero | import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter; |
68 | 5184 | caballero | import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
69 | 4147 | fjp | import com.iver.cit.gvsig.fmap.edition.EditionException; |
70 | 3981 | caballero | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
71 | 4159 | fjp | import com.iver.cit.gvsig.fmap.edition.VectorialEditableDBAdapter; |
72 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
73 | import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
||
74 | 5048 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
75 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable; |
76 | import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
||
77 | import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
||
78 | import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
||
79 | 5057 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialXMLItem; |
80 | 5201 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
81 | 214 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
82 | 231 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
83 | import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
||
84 | 926 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
85 | 461 | fernando | import com.iver.cit.gvsig.fmap.rendering.Legend; |
86 | import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
||
87 | 214 | fernando | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
88 | 3035 | fjp | import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
89 | 321 | fernando | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
90 | 4977 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.IPersistentSpatialIndex; |
91 | import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex; |
||
92 | import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts; |
||
93 | import com.iver.cit.gvsig.fmap.spatialindex.RTreeSptLib; |
||
94 | import com.iver.cit.gvsig.fmap.spatialindex.SpatialIndexException; |
||
95 | import com.iver.utiles.FileUtils; |
||
96 | 3301 | fjp | import com.iver.utiles.IPersistance; |
97 | 2672 | fjp | import com.iver.utiles.PostProcessSupport; |
98 | 415 | fernando | import com.iver.utiles.XMLEntity; |
99 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
100 | import com.iver.utiles.swing.threads.CancellableMonitorable; |
||
101 | 214 | fernando | |
102 | 562 | fernando | /**
|
103 | 1034 | vcaballero | * Capa b?sica Vectorial.
|
104 | 5184 | caballero | *
|
105 | 562 | fernando | * @author Fernando Gonz?lez Cort?s
|
106 | */
|
||
107 | 885 | fjp | |
108 | 5152 | fjp | // TODO Cuando no sea para pruebas debe no ser public
|
109 | public class FLyrVect extends FLyrDefault implements Labelable, |
||
110 | ClassifiableVectorial, SingleLayer, VectorialData, RandomVectorialData, |
||
111 | AlphanumericData, InfoByPoint { |
||
112 | 526 | vcaballero | private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
113 | 562 | fernando | |
114 | 526 | vcaballero | /** Leyenda de la capa vectorial */
|
115 | 562 | fernando | private VectorialLegend legend;
|
116 | 5152 | fjp | |
117 | 562 | fernando | private int typeShape = -1; |
118 | 3963 | caballero | |
119 | 562 | fernando | private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
120 | 5152 | fjp | |
121 | 3940 | caballero | private ReadableVectorial source;
|
122 | 5152 | fjp | |
123 | 4455 | fjp | private SelectableDataSource sds;
|
124 | 5152 | fjp | |
125 | 4455 | fjp | private SelectionSupport selectionSupport = new SelectionSupport(); |
126 | 5390 | caballero | |
127 | 5223 | fjp | private SpatialCache spatialCache = null; |
128 | private boolean spatialCacheEnabled = true; |
||
129 | 3940 | caballero | |
130 | 5152 | fjp | // protected SpatialIndex spatialIndex = null;
|
131 | 4977 | azabala | /**
|
132 | * An implementation of gvSIG spatial index
|
||
133 | */
|
||
134 | 5152 | fjp | protected ISpatialIndex spatialIndex = null; |
135 | 5115 | caballero | |
136 | 5152 | fjp | private boolean bHasJoin = false; |
137 | 461 | fernando | |
138 | 562 | fernando | /**
|
139 | 1034 | vcaballero | * A?ade un SelectionListener a la lista de listeners.
|
140 | 5184 | caballero | *
|
141 | 5152 | fjp | * @param listener
|
142 | * SelectionListener.
|
||
143 | 562 | fernando | */
|
144 | 5152 | fjp | /*
|
145 | * public void addSelectionListener(SelectionListener listener) { try {
|
||
146 | * getRecordset().addSelectionListener(listener); } catch (DriverException
|
||
147 | * e) { // TODO Auto-generated catch block e.printStackTrace(); } }
|
||
148 | */
|
||
149 | 562 | fernando | /**
|
150 | 1034 | vcaballero | * Borra un selectionListener de la lista de listeners.
|
151 | 5184 | caballero | *
|
152 | 5152 | fjp | * @param listener
|
153 | * SelectionListener
|
||
154 | 562 | fernando | */
|
155 | 5152 | fjp | /*
|
156 | * public void removeSelectionListener(SelectionListener listener) { try {
|
||
157 | * getRecordset().removeSelectionListener(listener); } catch
|
||
158 | * (DriverException e) { // TODO Auto-generated catch block
|
||
159 | * e.printStackTrace(); } }
|
||
160 | */
|
||
161 | 562 | fernando | /**
|
162 | * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
||
163 | * una gran cantidad de eventos. Con el fin de no propagar todos estos
|
||
164 | * eventos, se realiza la propagaci?n de manera manual al final de la
|
||
165 | * "r?faga" de eventos
|
||
166 | */
|
||
167 | 5152 | fjp | /*
|
168 | * public void fireSelectionEvents() { try {
|
||
169 | * getRecordset().fireSelectionEvents(); } catch (DriverException e) { //
|
||
170 | * TODO Auto-generated catch block e.printStackTrace(); } }
|
||
171 | */
|
||
172 | 562 | fernando | /**
|
173 | 1034 | vcaballero | * Devuelve el VectorialAdapater de la capa.
|
174 | 5184 | caballero | *
|
175 | 1034 | vcaballero | * @return VectorialAdapter.
|
176 | 562 | fernando | */
|
177 | 3940 | caballero | public ReadableVectorial getSource() {
|
178 | 562 | fernando | return source;
|
179 | } |
||
180 | 5115 | caballero | |
181 | 4977 | azabala | /**
|
182 | 5152 | fjp | * If we use a persistent spatial index associated with this layer, and the
|
183 | * index is not intrisic to the layer (for example spatial databases) this
|
||
184 | * method looks for existent spatial index, and loads it.
|
||
185 | 5184 | caballero | *
|
186 | 4977 | azabala | */
|
187 | 5152 | fjp | private void loadSpatialIndex() { |
188 | 4977 | azabala | ReadableVectorial source = getSource(); |
189 | 5152 | fjp | if (!(source instanceof VectorialFileAdapter)) { |
190 | // we are not interested in db adapters
|
||
191 | 4977 | azabala | return;
|
192 | } |
||
193 | VectorialDriver driver = source.getDriver(); |
||
194 | 5152 | fjp | if (!(driver instanceof BoundedShapes)) { |
195 | // we dont spatially index layers that are not bounded
|
||
196 | 4977 | azabala | return;
|
197 | } |
||
198 | 5152 | fjp | File file = ((VectorialFileAdapter) source).getFile();
|
199 | String fileName = FileUtils.getFileWithoutExtension(file);
|
||
200 | File sptFile = new File(fileName + ".dat"); |
||
201 | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
||
202 | // before to exit, look for it in temp path
|
||
203 | 5115 | caballero | |
204 | 4977 | azabala | String tempPath = System.getProperty("java.io.tmpdir"); |
205 | fileName = tempPath + File.separator + sptFile.getName();
|
||
206 | sptFile = new File(fileName); |
||
207 | 5152 | fjp | // it doesnt exists, must to create
|
208 | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
||
209 | 4977 | azabala | return;
|
210 | 5152 | fjp | }// if
|
211 | }// if
|
||
212 | 4977 | azabala | try {
|
213 | 5152 | fjp | spatialIndex = new RTreeSptLib(false, FileUtils |
214 | .getFileWithoutExtension(sptFile)); |
||
215 | 4977 | azabala | } catch (SpatialIndexException e) {
|
216 | spatialIndex = null;
|
||
217 | e.printStackTrace(); |
||
218 | return;
|
||
219 | } |
||
220 | } |
||
221 | 5115 | caballero | |
222 | 4977 | azabala | /**
|
223 | * Checks if it has associated an external spatial index
|
||
224 | 5184 | caballero | *
|
225 | 4977 | azabala | * @return
|
226 | */
|
||
227 | 5152 | fjp | public boolean isExternallySpatiallyIndexed() { |
228 | 4977 | azabala | ReadableVectorial source = getSource(); |
229 | 5152 | fjp | if (!(source instanceof VectorialFileAdapter)) { |
230 | // we are not interested in db adapters
|
||
231 | 4977 | azabala | return false; |
232 | } |
||
233 | 5152 | fjp | File file = ((VectorialFileAdapter) source).getFile();
|
234 | String fileName = FileUtils.getFileWithoutExtension(file);
|
||
235 | File sptFile = new File(fileName + ".dat"); |
||
236 | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
||
237 | // before to exit, look for it in temp path
|
||
238 | // it doesnt exists, must to create
|
||
239 | 4977 | azabala | String tempPath = System.getProperty("java.io.tmpdir"); |
240 | fileName = tempPath + File.separator + sptFile.getName();
|
||
241 | sptFile = new File(fileName); |
||
242 | 5152 | fjp | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
243 | 4977 | azabala | return false; |
244 | 5152 | fjp | }// if
|
245 | }// if
|
||
246 | 4977 | azabala | return true; |
247 | } |
||
248 | 472 | fernando | |
249 | 562 | fernando | /**
|
250 | 1034 | vcaballero | * Inserta el VectorialAdapter a la capa.
|
251 | 5184 | caballero | *
|
252 | 5152 | fjp | * @param va
|
253 | * VectorialAdapter.
|
||
254 | 562 | fernando | */
|
255 | 3940 | caballero | public void setSource(ReadableVectorial rv) { |
256 | source = rv; |
||
257 | 5152 | fjp | // azabala: we check if this layer could have a file spatial index
|
258 | // , if it has, and load it if it exists
|
||
259 | 4977 | azabala | loadSpatialIndex(); |
260 | 562 | fernando | } |
261 | 214 | fernando | |
262 | /**
|
||
263 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
264 | 214 | fernando | */
|
265 | 652 | fernando | public Rectangle2D getFullExtent() throws DriverException { |
266 | 885 | fjp | try {
|
267 | 652 | fernando | Rectangle2D rAux;
|
268 | logger.debug("source.start()");
|
||
269 | source.start(); |
||
270 | rAux = source.getFullExtent(); |
||
271 | logger.debug("source.stop()");
|
||
272 | source.stop(); |
||
273 | 885 | fjp | |
274 | // Si existe reproyecci?n, reproyectar el extent
|
||
275 | ICoordTrans ct = getCoordTrans(); |
||
276 | |||
277 | if (ct != null) { |
||
278 | Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
||
279 | Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
||
280 | pt1 = ct.convert(pt1, null);
|
||
281 | pt2 = ct.convert(pt2, null);
|
||
282 | rAux = new Rectangle2D.Double(); |
||
283 | rAux.setFrameFromDiagonal(pt1, pt2); |
||
284 | } |
||
285 | |||
286 | 652 | fernando | return rAux;
|
287 | 885 | fjp | } catch (DriverIOException e) {
|
288 | 652 | fernando | throw new DriverException(e); |
289 | } |
||
290 | 214 | fernando | } |
291 | |||
292 | /**
|
||
293 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
294 | 5152 | fjp | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
295 | 214 | fernando | */
|
296 | 562 | fernando | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
297 | 5152 | fjp | Cancellable cancel, double scale) throws DriverException { |
298 | 3940 | caballero | |
299 | 5152 | fjp | if (isWithinScale(scale)) {
|
300 | // Las que solo tienen etiquetado sin pintar el shape,
|
||
301 | // no pasamos por ellas
|
||
302 | boolean bDrawShapes = true; |
||
303 | if (legend instanceof SingleSymbolLegend) { |
||
304 | if (legend.getDefaultSymbol().isShapeVisible() == false) |
||
305 | bDrawShapes = false;
|
||
306 | } |
||
307 | if (bDrawShapes) {
|
||
308 | Strategy strategy = StrategyManager.getStrategy(this);
|
||
309 | try {
|
||
310 | strategy.draw(image, g, viewPort, cancel); |
||
311 | } catch (DriverException e) {
|
||
312 | 3462 | caballero | this.setVisible(false); |
313 | this.setActive(false); |
||
314 | throw e;
|
||
315 | } |
||
316 | 5152 | fjp | } |
317 | if (getVirtualLayers() != null) { |
||
318 | getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
||
319 | } |
||
320 | 3940 | caballero | |
321 | 5152 | fjp | if (getLayerText() != null) { |
322 | getLayerText().draw(image, g, viewPort, cancel, scale); |
||
323 | } |
||
324 | 885 | fjp | } |
325 | 214 | fernando | } |
326 | |||
327 | /**
|
||
328 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
329 | 5152 | fjp | * com.iver.cit.gvsig.fmap.ViewPort,
|
330 | 5317 | fjp | * com.iver.utiles.swing.threads.Cancellable)
|
331 | 562 | fernando | */
|
332 | 5152 | fjp | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
333 | double scale) throws DriverException { |
||
334 | if (isVisible() && isWithinScale(scale)) {
|
||
335 | Strategy strategy = StrategyManager.getStrategy(this);
|
||
336 | 650 | vcaballero | |
337 | 5152 | fjp | strategy.print(g, viewPort, cancel); |
338 | 757 | fjp | |
339 | 5152 | fjp | if (getLayerText() != null) { |
340 | getLayerText().draw(null, g, viewPort, cancel, scale);
|
||
341 | } |
||
342 | 885 | fjp | } |
343 | 562 | fernando | } |
344 | |||
345 | /**
|
||
346 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
347 | 214 | fernando | */
|
348 | 2629 | fjp | // public FLayer createLabelLayer(int fieldId) {
|
349 | 5152 | fjp | public FLayer createLabelLayer(SelectableDataSource ds) {
|
350 | 3247 | fjp | FLyrText layerText = null;
|
351 | 5152 | fjp | try {
|
352 | layerText = new FLyrText();
|
||
353 | 763 | fjp | layerText.setLegend((VectorialLegend) getLegend()); |
354 | 5152 | fjp | layerText.createLabels(this);
|
355 | 763 | fjp | } catch (FieldNotFoundException e1) {
|
356 | // TODO Auto-generated catch block
|
||
357 | e1.printStackTrace(); |
||
358 | } catch (DriverException e1) {
|
||
359 | // TODO Auto-generated catch block
|
||
360 | e1.printStackTrace(); |
||
361 | 5152 | fjp | } |
362 | 885 | fjp | |
363 | 757 | fjp | setLayerText(layerText); |
364 | 3438 | caballero | layerText.setCoordTrans(getCoordTrans()); |
365 | 757 | fjp | return layerText;
|
366 | 214 | fernando | } |
367 | |||
368 | /**
|
||
369 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
370 | 214 | fernando | */
|
371 | 228 | fernando | public void removeLabels() { |
372 | 757 | fjp | setLayerText(null);
|
373 | 214 | fernando | } |
374 | |||
375 | 5152 | fjp | /*
|
376 | * (non-Javadoc)
|
||
377 | 5184 | caballero | *
|
378 | 5152 | fjp | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#deleteSpatialIndex()
|
379 | */
|
||
380 | public void deleteSpatialIndex() { |
||
381 | spatialIndex = null;
|
||
382 | } |
||
383 | 5115 | caballero | |
384 | 5152 | fjp | /**
|
385 | * Creates an spatial index associated to this layers.
|
||
386 | 5184 | caballero | *
|
387 | 5152 | fjp | * @param cancelMonitor
|
388 | * instance of CancellableMonitorable that allows to monitor
|
||
389 | * progress of spatial index creation, and cancel the process
|
||
390 | */
|
||
391 | public void createSpatialIndex(CancellableMonitorable cancelMonitor) { |
||
392 | // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
||
393 | // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
||
394 | // para que acepten recorrer sin geometria, solo con rectangulos.
|
||
395 | 5115 | caballero | |
396 | 5152 | fjp | // //If this vectorial layer is based in a spatial database, the spatial
|
397 | // index is already implicit. We only will index file drivers
|
||
398 | ReadableVectorial va = getSource(); |
||
399 | if (!(va instanceof VectorialFileAdapter)) { |
||
400 | 4977 | azabala | return;
|
401 | } |
||
402 | 5152 | fjp | if (!(va.getDriver() instanceof BoundedShapes)) { |
403 | 4977 | azabala | return;
|
404 | } |
||
405 | 5152 | fjp | File file = ((VectorialFileAdapter) va).getFile();
|
406 | String fileName = FileUtils.getFileWithoutExtension(file);
|
||
407 | try {
|
||
408 | 4977 | azabala | spatialIndex = new RTreeSptLib(true, fileName); |
409 | } catch (SpatialIndexException e1) {
|
||
410 | 5152 | fjp | // Probably we dont have writing permissions
|
411 | 4977 | azabala | String directoryName = System.getProperty("java.io.tmpdir"); |
412 | File newFile = new File(file.getName()); |
||
413 | String newFileName = newFile.getName();
|
||
414 | try {
|
||
415 | 5152 | fjp | spatialIndex = new RTreeSptLib(true, directoryName |
416 | + File.pathSeparator + newFileName);
|
||
417 | 4977 | azabala | } catch (SpatialIndexException e) {
|
418 | 5152 | fjp | // si no lo podemos crear en fichero, lo creamos en memoria
|
419 | 4977 | azabala | spatialIndex = new QuadtreeJts();
|
420 | } |
||
421 | 5152 | fjp | }// try
|
422 | 5115 | caballero | |
423 | 5152 | fjp | ICoordTrans ct = getCoordTrans(); |
424 | BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
||
425 | try {
|
||
426 | va.start(); |
||
427 | 2978 | fjp | |
428 | 5152 | fjp | for (int i = 0; i < va.getShapeCount(); i++) { |
429 | if (cancelMonitor != null) { |
||
430 | if (cancelMonitor.isCanceled())
|
||
431 | return;
|
||
432 | cancelMonitor.reportStep(); |
||
433 | } |
||
434 | Rectangle2D r = shapeBounds.getShapeBounds(i);
|
||
435 | if (ct != null) { |
||
436 | r = ct.convert(r); |
||
437 | } |
||
438 | spatialIndex.insert(r, i); |
||
439 | if (spatialIndex instanceof IPersistentSpatialIndex) { |
||
440 | if ((i % 50) == 0) {// flush spatial index in buckets of 50 |
||
441 | ((IPersistentSpatialIndex) spatialIndex).flush(); |
||
442 | } |
||
443 | } |
||
444 | } // for
|
||
445 | va.stop(); |
||
446 | if (spatialIndex instanceof IPersistentSpatialIndex) |
||
447 | ((IPersistentSpatialIndex) spatialIndex).flush(); |
||
448 | } catch (DriverIOException e) {
|
||
449 | // TODO Auto-generated catch block
|
||
450 | e.printStackTrace(); |
||
451 | } catch (IOException e) { |
||
452 | // TODO Auto-generated catch block
|
||
453 | e.printStackTrace(); |
||
454 | } |
||
455 | } |
||
456 | 5115 | caballero | |
457 | 5152 | fjp | /*
|
458 | * (non-Javadoc)
|
||
459 | 5184 | caballero | *
|
460 | 4977 | azabala | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
|
461 | */
|
||
462 | public void createSpatialIndex() { |
||
463 | createSpatialIndex(null);
|
||
464 | 214 | fernando | } |
465 | |||
466 | /**
|
||
467 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
468 | 5152 | fjp | * FBitSet)
|
469 | 214 | fernando | */
|
470 | 2969 | fjp | public void process(FeatureVisitor visitor, FBitSet subset) |
471 | 5152 | fjp | throws DriverException, VisitException {
|
472 | 562 | fernando | Strategy s = StrategyManager.getStrategy(this);
|
473 | s.process(visitor, subset); |
||
474 | 228 | fernando | } |
475 | |||
476 | /**
|
||
477 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
478 | */
|
||
479 | 5152 | fjp | public void process(FeatureVisitor visitor) throws DriverException, |
480 | VisitException { |
||
481 | 562 | fernando | Strategy s = StrategyManager.getStrategy(this);
|
482 | s.process(visitor); |
||
483 | } |
||
484 | 4223 | caballero | |
485 | 4200 | azabala | /**
|
486 | 5152 | fjp | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
487 | * Rectangle2D)
|
||
488 | 4200 | azabala | */
|
489 | public void process(FeatureVisitor visitor, Rectangle2D rect) |
||
490 | 5152 | fjp | throws DriverException, VisitException {
|
491 | 4200 | azabala | Strategy s = StrategyManager.getStrategy(this);
|
492 | s.process(visitor, rect); |
||
493 | } |
||
494 | 562 | fernando | |
495 | /**
|
||
496 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
497 | */
|
||
498 | 5152 | fjp | /*
|
499 | * public void setSelection(FBitSet selection) { try {
|
||
500 | * getRecordset().setSelection(selection); } catch (DriverException e) { //
|
||
501 | * TODO Auto-generated catch block e.printStackTrace(); }
|
||
502 | * fireSelectionEvents(); }
|
||
503 | */
|
||
504 | 228 | fernando | /**
|
505 | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
||
506 | */
|
||
507 | 5152 | fjp | /*
|
508 | * public boolean isSelected(int index) { try { return
|
||
509 | * getRecordset().isSelected(index); } catch (DriverException e) { // TODO
|
||
510 | * Auto-generated catch block e.printStackTrace(); } return false; }
|
||
511 | */
|
||
512 | 228 | fernando | /**
|
513 | 456 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
514 | */
|
||
515 | 5152 | fjp | /*
|
516 | * public FBitSet getSelection() { try { return
|
||
517 | * getRecordset().getSelection(); } catch (DriverException e) { // TODO
|
||
518 | * Auto-generated catch block e.printStackTrace(); } return new FBitSet(); }
|
||
519 | */
|
||
520 | 456 | fernando | /**
|
521 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
522 | */
|
||
523 | 5152 | fjp | /*
|
524 | * public void clearSelection() { try { getRecordset().clearSelection(); }
|
||
525 | * catch (DriverException e) { // TODO Auto-generated catch block
|
||
526 | * e.printStackTrace(); } }
|
||
527 | */
|
||
528 | 228 | fernando | |
529 | 5152 | fjp | /*
|
530 | * (non-Javadoc)
|
||
531 | 5184 | caballero | *
|
532 | 2978 | fjp | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
|
533 | 214 | fernando | */
|
534 | 2978 | fjp | public FBitSet queryByRect(Rectangle2D rect) throws DriverException { |
535 | 488 | vcaballero | Strategy s = StrategyManager.getStrategy(this);
|
536 | 562 | fernando | |
537 | 488 | vcaballero | return s.queryByRect(rect);
|
538 | 214 | fernando | } |
539 | |||
540 | 5152 | fjp | public FBitSet queryByPoint(Point2D p, double tolerance) |
541 | throws DriverException {
|
||
542 | Strategy s = StrategyManager.getStrategy(this);
|
||
543 | return s.queryByPoint(p, tolerance);
|
||
544 | } |
||
545 | 3940 | caballero | |
546 | 5152 | fjp | public FBitSet queryByShape(IGeometry g, int relationship) |
547 | throws DriverException, VisitException {
|
||
548 | Strategy s = StrategyManager.getStrategy(this);
|
||
549 | return s.queryByShape(g, relationship);
|
||
550 | } |
||
551 | 5048 | ldiaz | |
552 | 5152 | fjp | public XMLItem[] getInfo(Point p, double tolerance) throws DriverException { |
553 | 5057 | ldiaz | Point2D pReal = this.getFMap().getViewPort().toMapPoint(p); |
554 | 5152 | fjp | FBitSet bs = queryByPoint(pReal, tolerance); |
555 | VectorialXMLItem[] item = new VectorialXMLItem[1]; |
||
556 | item[0] = new VectorialXMLItem(bs, this); |
||
557 | 5115 | caballero | |
558 | 5152 | fjp | return item;
|
559 | } |
||
560 | |||
561 | 214 | fernando | /**
|
562 | 1828 | fernando | * @throws DriverException
|
563 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
564 | */
|
||
565 | 5152 | fjp | /*
|
566 | * public SelectableDataSource getRecordset() throws DriverException { if
|
||
567 | * (sds == null){ try { DataSource ds = getSource().getRecordset();
|
||
568 | 5184 | caballero | *
|
569 | 5152 | fjp | * if (ds == null) { return null; }
|
570 | 5184 | caballero | *
|
571 | 5152 | fjp | * sds = new SelectableDataSource(ds);
|
572 | * //sds.setSelectionSupport(selectionSupport);
|
||
573 | 5184 | caballero | *
|
574 | 5152 | fjp | * return sds; } catch (DriverLoadException e) { throw new
|
575 | * DriverException(e); } catch
|
||
576 | * (com.hardcode.gdbms.engine.data.driver.DriverException e) { throw new
|
||
577 | * DriverException(e); } } return sds; }
|
||
578 | */
|
||
579 | 214 | fernando | /**
|
580 | 5152 | fjp | * Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
581 | * forma, podr?s poner leyendas basadas en el nuevo recordset
|
||
582 | 5184 | caballero | *
|
583 | 5152 | fjp | * @param newSds
|
584 | * @throws DriverException
|
||
585 | * @throws FieldNotFoundException
|
||
586 | * @throws FieldNotFoundException
|
||
587 | */
|
||
588 | /*
|
||
589 | * public void setRecordset(SelectableDataSource newSds) throws
|
||
590 | * DriverException, FieldNotFoundException { sds = newSds;
|
||
591 | * //sds.setSelectionSupport(selectionSupport); legend.setDataSource(sds);
|
||
592 | * logger.debug("Recordset cambiado a " + sds.getName()); }
|
||
593 | */
|
||
594 | /**
|
||
595 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
|
596 | 5152 | fjp | * com.iver.cit.gvsig.fmap.rendering.Legend)
|
597 | 214 | fernando | */
|
598 | 5152 | fjp | public void setLegend(VectorialLegend r) throws DriverException, |
599 | FieldNotFoundException { |
||
600 | 486 | fjp | VectorialLegend oldLegend = legend; |
601 | 264 | fernando | legend = r; |
602 | 885 | fjp | |
603 | try {
|
||
604 | 652 | fernando | legend.setDataSource(getRecordset()); |
605 | 885 | fjp | |
606 | if (legend.getLabelField() != null) { |
||
607 | 5152 | fjp | // sds.start();
|
608 | // int idLabelField =
|
||
609 | // getRecordset().getFieldIndexByName(legend.getLabelField());
|
||
610 | 3963 | caballero | createLabelLayer(getSource().getRecordset()); |
611 | 2629 | fjp | // sds.stop();
|
612 | 5152 | fjp | } else
|
613 | removeLabels(); |
||
614 | 885 | fjp | } catch (DriverException e) {
|
615 | 652 | fernando | throw new DriverException(e); |
616 | 757 | fjp | } catch (FieldNotFoundException e) {
|
617 | // TODO Auto-generated catch block
|
||
618 | e.printStackTrace(); |
||
619 | 5152 | fjp | } catch (DriverLoadException e) {
|
620 | 3963 | caballero | // TODO Auto-generated catch block
|
621 | e.printStackTrace(); |
||
622 | } |
||
623 | 562 | fernando | |
624 | 5152 | fjp | LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent( |
625 | oldLegend, legend); |
||
626 | 486 | fjp | callLegendChanged(e); |
627 | 214 | fernando | } |
628 | 303 | fernando | |
629 | 321 | fernando | /**
|
630 | 1034 | vcaballero | * Devuelve la Leyenda de la capa.
|
631 | 5184 | caballero | *
|
632 | 1034 | vcaballero | * @return Leyenda.
|
633 | 321 | fernando | */
|
634 | 562 | fernando | public Legend getLegend() {
|
635 | return legend;
|
||
636 | 321 | fernando | } |
637 | 373 | fernando | |
638 | /**
|
||
639 | 1034 | vcaballero | * Devuelve el tipo de shape que contiene la capa.
|
640 | 5184 | caballero | *
|
641 | 1034 | vcaballero | * @return tipo de shape.
|
642 | 5184 | caballero | *
|
643 | 1034 | vcaballero | * @throws DriverException
|
644 | 373 | fernando | */
|
645 | 652 | fernando | public int getShapeType() throws DriverException { |
646 | 562 | fernando | if (typeShape == -1) { |
647 | 885 | fjp | try {
|
648 | 652 | fernando | logger.debug("source.start()");
|
649 | 4213 | caballero | getSource().start(); |
650 | typeShape = getSource().getShapeType(); |
||
651 | 652 | fernando | logger.debug("source.stop()");
|
652 | 4213 | caballero | getSource().stop(); |
653 | 885 | fjp | } catch (DriverIOException e) {
|
654 | 652 | fernando | throw new DriverException(e); |
655 | } |
||
656 | 526 | vcaballero | } |
657 | 562 | fernando | |
658 | 526 | vcaballero | return typeShape;
|
659 | 373 | fernando | } |
660 | 435 | vcaballero | |
661 | /**
|
||
662 | 1828 | fernando | * @throws XMLException
|
663 | 435 | vcaballero | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
664 | */
|
||
665 | 1828 | fernando | public XMLEntity getXMLEntity() throws XMLException { |
666 | 562 | fernando | XMLEntity xml = super.getXMLEntity();
|
667 | 5152 | fjp | xml.addChild(getLegend().getXMLEntity()); |
668 | try {
|
||
669 | 3963 | caballero | xml.addChild(getRecordset().getSelectionSupport().getXMLEntity()); |
670 | 562 | fernando | |
671 | 4455 | fjp | } catch (DriverException e1) {
|
672 | e1.printStackTrace(); |
||
673 | throw new XMLException(e1); |
||
674 | } |
||
675 | 5152 | fjp | if (getSource() instanceof VectorialEditableAdapter) { |
676 | setSource(((VectorialEditableAdapter) source).getOriginalAdapter()); |
||
677 | 3981 | caballero | } |
678 | 4213 | caballero | if (getSource() instanceof VectorialFileAdapter) { |
679 | 1828 | fernando | xml.putProperty("type", "vectorial"); |
680 | 5152 | fjp | xml.putProperty("file", ((VectorialFileAdapter) getSource())
|
681 | .getFile()); |
||
682 | // try {
|
||
683 | try {
|
||
684 | xml.putProperty("recordset-name", getSource().getRecordset()
|
||
685 | .getName()); |
||
686 | } catch (DriverLoadException e) {
|
||
687 | // TODO Auto-generated catch block
|
||
688 | e.printStackTrace(); |
||
689 | } |
||
690 | // } catch (DriverException e) {
|
||
691 | // throw new XMLException(e);
|
||
692 | // }
|
||
693 | 562 | fernando | } else if (source instanceof VectorialDBAdapter) { |
694 | 5152 | fjp | xml.putProperty("type", "vectorial"); |
695 | 3940 | caballero | |
696 | 5152 | fjp | VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) getSource() |
697 | .getDriver(); |
||
698 | 3940 | caballero | |
699 | 5152 | fjp | // Guardamos el nombre del driver para poder recuperarlo
|
700 | // con el DriverManager de Fernando.
|
||
701 | xml.putProperty("db", dbDriver.getName());
|
||
702 | // try {
|
||
703 | try {
|
||
704 | xml.putProperty("recordset-name", getSource().getRecordset()
|
||
705 | .getName()); |
||
706 | } catch (DriverLoadException e) {
|
||
707 | // TODO Auto-generated catch block
|
||
708 | e.printStackTrace(); |
||
709 | } |
||
710 | // } catch (DriverException e) {
|
||
711 | // throw new XMLException(e);
|
||
712 | // }
|
||
713 | xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos
|
||
714 | // metido la leyenda y el
|
||
715 | // selection support
|
||
716 | } else if (source instanceof VectorialAdapter) { |
||
717 | // Se supone que hemos hecho algo gen?rico.
|
||
718 | xml.putProperty("type", "vectorial"); |
||
719 | 3940 | caballero | |
720 | 5152 | fjp | VectorialDriver driver = (VectorialDriver) getSource().getDriver(); |
721 | 3940 | caballero | |
722 | 5152 | fjp | // Guardamos el nombre del driver para poder recuperarlo
|
723 | // con el DriverManager de Fernando.
|
||
724 | xml.putProperty("other", driver.getName());
|
||
725 | // try {
|
||
726 | try {
|
||
727 | xml.putProperty("recordset-name", getSource().getRecordset()
|
||
728 | .getName()); |
||
729 | } catch (DriverLoadException e) {
|
||
730 | // TODO Auto-generated catch block
|
||
731 | e.printStackTrace(); |
||
732 | } |
||
733 | // } catch (DriverException e) {
|
||
734 | // throw new XMLException(e);
|
||
735 | // }
|
||
736 | if (driver instanceof IPersistance) { |
||
737 | // xml.putProperty("className", driver.getClass().getName());
|
||
738 | IPersistance persist = (IPersistance) driver; |
||
739 | xml.addChild(persist.getXMLEntity()); // Tercer child. Antes
|
||
740 | // hemos metido la
|
||
741 | // leyenda y el
|
||
742 | // selection support
|
||
743 | } |
||
744 | 3940 | caballero | } |
745 | 562 | fernando | xml.putProperty("driverName", getSource().getDriver().getName());
|
746 | 5152 | fjp | if (bHasJoin)
|
747 | xml.putProperty("hasJoin", "true"); |
||
748 | 3940 | caballero | |
749 | 435 | vcaballero | return xml;
|
750 | } |
||
751 | |||
752 | /**
|
||
753 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
754 | */
|
||
755 | 5152 | fjp | public void setXMLEntity03(XMLEntity xml) throws XMLException { |
756 | 3940 | caballero | |
757 | 2183 | fernando | super.setXMLEntity(xml);
|
758 | legend = LegendFactory.createFromXML03(xml.getChild(0));
|
||
759 | |||
760 | try {
|
||
761 | // legend.setDataSource(getRecordset());
|
||
762 | setLegend(legend); |
||
763 | } catch (FieldNotFoundException e) {
|
||
764 | throw new XMLException(e); |
||
765 | } catch (DriverException e) {
|
||
766 | throw new XMLException(e); |
||
767 | 3940 | caballero | } |
768 | 2183 | fernando | |
769 | 4455 | fjp | try {
|
770 | 5152 | fjp | getRecordset().getSelectionSupport() |
771 | .setXMLEntity03(xml.getChild(1));
|
||
772 | 4455 | fjp | } catch (DriverException e) {
|
773 | e.printStackTrace(); |
||
774 | } |
||
775 | 2183 | fernando | } |
776 | |||
777 | /**
|
||
778 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
779 | */
|
||
780 | 5152 | fjp | public void setXMLEntity(XMLEntity xml) throws XMLException { |
781 | super.setXMLEntity(xml);
|
||
782 | 3940 | caballero | |
783 | 4213 | caballero | VectorialLegend leg = LegendFactory.createFromXML(xml.getChild(0));
|
784 | 4455 | fjp | try {
|
785 | getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
||
786 | String recordsetName = xml.getStringProperty("recordset-name"); |
||
787 | 885 | fjp | |
788 | 1828 | fernando | LayerFactory.getDataSourceFactory().changeDataSourceName( |
789 | 5152 | fjp | getSource().getRecordset().getName(), recordsetName); |
790 | // Hacemos que el recordset que hemos creado antes (los
|
||
791 | // recordset se crean antes que todo) sea el recordset
|
||
792 | // de esta capa. Y del que se crea automaticamente
|
||
793 | // en el setLegend del createLayer, nos olvidamos
|
||
794 | SelectableDataSource sds = new SelectableDataSource(LayerFactory
|
||
795 | .getDataSourceFactory().createRandomDataSource( |
||
796 | recordsetName, DataSourceFactory.AUTOMATIC_OPENING)); |
||
797 | // sds.setSelectionSupport(selectionSupport);
|
||
798 | // ((EditableAdapter)getSource()).setRecordSet(sds);
|
||
799 | 1828 | fernando | } catch (NoSuchTableException e1) {
|
800 | throw new XMLException(e1); |
||
801 | 5152 | fjp | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
802 | throw new XMLException(e1); |
||
803 | } catch (DriverLoadException e1) {
|
||
804 | throw new XMLException(e1); |
||
805 | } catch (DriverException e1) {
|
||
806 | throw new XMLException(e1); |
||
807 | 4455 | fjp | } |
808 | 5152 | fjp | // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
809 | // el final
|
||
810 | // de la lectura del proyecto
|
||
811 | if (xml.contains("hasJoin")) { |
||
812 | setIsJoined(true);
|
||
813 | PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
||
814 | } else {
|
||
815 | try {
|
||
816 | // legend.setDataSource(getRecordset());
|
||
817 | setLegend(leg); |
||
818 | } catch (FieldNotFoundException e) {
|
||
819 | throw new XMLException(e); |
||
820 | } catch (DriverException e) {
|
||
821 | throw new XMLException(e); |
||
822 | } |
||
823 | } |
||
824 | 3940 | caballero | |
825 | 435 | vcaballero | } |
826 | 562 | fernando | |
827 | /**
|
||
828 | 1034 | vcaballero | * A?ade un LegendListener a la lista de Listeners.
|
829 | 5184 | caballero | *
|
830 | 5152 | fjp | * @param listener
|
831 | * LegendListener.
|
||
832 | 562 | fernando | */
|
833 | public void addLegendListener(LegendListener listener) { |
||
834 | 472 | fernando | layerChangeSupport.addLayerListener(listener); |
835 | } |
||
836 | 562 | fernando | |
837 | /**
|
||
838 | 1034 | vcaballero | * Llamada al m?todo callLegendChanged de los listener.
|
839 | 5184 | caballero | *
|
840 | 5152 | fjp | * @param e
|
841 | * Evento.
|
||
842 | 562 | fernando | */
|
843 | 486 | fjp | private void callLegendChanged(LegendChangedEvent e) { |
844 | 472 | fernando | layerChangeSupport.callLegendChanged(e); |
845 | } |
||
846 | 562 | fernando | |
847 | /**
|
||
848 | 1034 | vcaballero | * Borra un LegendListener de la lista de Listeners
|
849 | 5184 | caballero | *
|
850 | 5152 | fjp | * @param listener
|
851 | * LegendListener.
|
||
852 | 562 | fernando | */
|
853 | public void removeLegendListener(LegendListener listener) { |
||
854 | 472 | fernando | layerChangeSupport.removeLayerListener(listener); |
855 | } |
||
856 | 544 | fernando | |
857 | /**
|
||
858 | 1034 | vcaballero | * Sobreimplementaci?n del m?todo toString para que las bases de datos
|
859 | * identifiquen la capa.
|
||
860 | 5184 | caballero | *
|
861 | 911 | fernando | * @return DOCUMENT ME!
|
862 | */
|
||
863 | public String toString() { |
||
864 | /*
|
||
865 | 5152 | fjp | * Se usa internamente para que la parte de datos identifique de forma
|
866 | * un?voca las tablas
|
||
867 | 911 | fernando | */
|
868 | String ret = super.toString(); |
||
869 | |||
870 | return "layer" + ret.substring(ret.indexOf('@') + 1); |
||
871 | } |
||
872 | 2672 | fjp | |
873 | 5152 | fjp | public boolean isJoined() { |
874 | return bHasJoin;
|
||
875 | } |
||
876 | 5115 | caballero | |
877 | 5152 | fjp | /**
|
878 | 4977 | azabala | * Returns if a layer is spatially indexed
|
879 | 5184 | caballero | *
|
880 | 5152 | fjp | * @return if this layer has the ability to proces spatial queries without
|
881 | * secuential scans.
|
||
882 | 4977 | azabala | */
|
883 | 5152 | fjp | public boolean isSpatiallyIndexed() { |
884 | 4977 | azabala | ReadableVectorial source = getSource(); |
885 | 5152 | fjp | if (source instanceof ISpatialDB) |
886 | 4977 | azabala | return true; |
887 | 5152 | fjp | if (getISpatialIndex() != null) |
888 | 4977 | azabala | return true; |
889 | return false; |
||
890 | } |
||
891 | 2672 | fjp | |
892 | 5152 | fjp | public void setIsJoined(boolean hasJoin) { |
893 | bHasJoin = hasJoin; |
||
894 | } |
||
895 | 2978 | fjp | |
896 | 5152 | fjp | /**
|
897 | * @return Returns the spatialIndex.
|
||
898 | */
|
||
899 | public ISpatialIndex getISpatialIndex() {
|
||
900 | return spatialIndex;
|
||
901 | } |
||
902 | 3366 | caballero | |
903 | 5152 | fjp | /*
|
904 | * public SelectableDataSource getRecordset() { try { return
|
||
905 | * getSource().getRecordset(); } catch (DriverLoadException e) { // TODO
|
||
906 | * Auto-generated catch block e.printStackTrace(); } return null; }
|
||
907 | */
|
||
908 | 4977 | azabala | |
909 | 4455 | fjp | /**
|
910 | * @throws DriverException
|
||
911 | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
||
912 | */
|
||
913 | public SelectableDataSource getRecordset() throws DriverException { |
||
914 | 5152 | fjp | if (sds == null) { |
915 | 4455 | fjp | try {
|
916 | SelectableDataSource ds = source.getRecordset(); |
||
917 | |||
918 | if (ds == null) { |
||
919 | return null; |
||
920 | } |
||
921 | |||
922 | sds = ds; |
||
923 | sds.setSelectionSupport(selectionSupport); |
||
924 | 4523 | caballero | |
925 | 4455 | fjp | } catch (DriverLoadException e) {
|
926 | throw new DriverException(e); |
||
927 | 5152 | fjp | } |
928 | 4455 | fjp | } |
929 | return sds;
|
||
930 | 4523 | caballero | } |
931 | |||
932 | 5152 | fjp | /*
|
933 | * (non-Javadoc)
|
||
934 | 5184 | caballero | *
|
935 | 4147 | fjp | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setEditing(boolean)
|
936 | */
|
||
937 | 5152 | fjp | public void setEditing(boolean b) throws EditionException { |
938 | 4147 | fjp | super.setEditing(b);
|
939 | 5152 | fjp | try {
|
940 | if (b) {
|
||
941 | VectorialEditableAdapter vea = null;
|
||
942 | // TODO: Qu? pasa si hay m?s tipos de adapters?
|
||
943 | // FJP: Se podr?a pasar como argumento el
|
||
944 | // VectorialEditableAdapter
|
||
945 | // que se quiera usar para evitar meter c?digo aqu? de este
|
||
946 | // estilo.
|
||
947 | if (getSource() instanceof VectorialDBAdapter) { |
||
948 | vea = new VectorialEditableDBAdapter();
|
||
949 | } else if (this instanceof FLyrAnnotation) { |
||
950 | 5390 | caballero | vea = new AnnotationEditableAdapter(
|
951 | (FLyrAnnotation) this);
|
||
952 | } else {
|
||
953 | 5152 | fjp | vea = new VectorialEditableAdapter();
|
954 | 5115 | caballero | } |
955 | 5152 | fjp | vea.setOriginalVectorialAdapter(getSource()); |
956 | 5115 | caballero | |
957 | 5152 | fjp | // /vea.setSpatialIndex(getSpatialIndex());
|
958 | // /vea.setFullExtent(getFullExtent());
|
||
959 | 5184 | caballero | vea.startEdition(EditionEvent.GRAPHIC); |
960 | 5152 | fjp | setSource(vea); |
961 | getRecordset().setSelectionSupport( |
||
962 | vea.getOriginalAdapter().getRecordset() |
||
963 | .getSelectionSupport()); |
||
964 | |||
965 | } else {
|
||
966 | VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource(); |
||
967 | setSource(vea.getOriginalAdapter()); |
||
968 | 4159 | fjp | } |
969 | 5152 | fjp | // Si tenemos una leyenda, hay que pegarle el cambiazo a su
|
970 | // recordset
|
||
971 | setRecordset(getSource().getRecordset()); |
||
972 | if (getLegend() instanceof VectorialLegend) { |
||
973 | VectorialLegend ley = (VectorialLegend) getLegend(); |
||
974 | ley.setDataSource(getSource().getRecordset()); |
||
975 | 5184 | caballero | // Esto lo pongo para evitar que al dibujar sobre un
|
976 | 5152 | fjp | // dxf, dwg, o dgn no veamos nada. Es debido al checkbox
|
977 | // de la leyenda de textos "dibujar solo textos".
|
||
978 | 5390 | caballero | if (!(getSource().getDriver() instanceof IndexedShpDriver)){ |
979 | 5152 | fjp | ley.setDefaultSymbol(new FSymbol(getShapeType()));
|
980 | } |
||
981 | 5390 | caballero | ley.useDefaultSymbol(true);
|
982 | 4147 | fjp | } |
983 | 5152 | fjp | } catch (DriverLoadException e) {
|
984 | e.printStackTrace(); |
||
985 | throw new EditionException(e); |
||
986 | } catch (DriverException e) {
|
||
987 | e.printStackTrace(); |
||
988 | throw new EditionException(e); |
||
989 | } catch (FieldNotFoundException e) {
|
||
990 | e.printStackTrace(); |
||
991 | throw new EditionException(e); |
||
992 | 4147 | fjp | } |
993 | 4223 | caballero | |
994 | 5152 | fjp | callEditionChanged(LayerEvent |
995 | .createEditionChangedEvent(this, "edition")); |
||
996 | |||
997 | 4147 | fjp | } |
998 | |||
999 | 5152 | fjp | /**
|
1000 | * Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
||
1001 | * forma, podr?s poner leyendas basadas en el nuevo recordset
|
||
1002 | 5184 | caballero | *
|
1003 | 5152 | fjp | * @param newSds
|
1004 | */
|
||
1005 | public void setRecordset(SelectableDataSource newSds) { |
||
1006 | sds = newSds; |
||
1007 | sds.setSelectionSupport(selectionSupport); |
||
1008 | 3366 | caballero | } |
1009 | 5152 | fjp | /*
|
1010 | * public SelectionSupport getSelectionSupport() { return selectionSupport; }
|
||
1011 | 5184 | caballero | *
|
1012 | 5152 | fjp | * public void setSelectionSupport(SelectionSupport selectionSupport) {
|
1013 | * this.selectionSupport = selectionSupport; }
|
||
1014 | */
|
||
1015 | 3366 | caballero | |
1016 | 5226 | fjp | public SpatialCache createSpatialCache() {
|
1017 | spatialCache = new SpatialCache();
|
||
1018 | 5223 | fjp | return spatialCache;
|
1019 | } |
||
1020 | |||
1021 | 5226 | fjp | // public void setSpatialCache(SpatialCache spatialCache) {
|
1022 | // this.spatialCache = spatialCache;
|
||
1023 | // }
|
||
1024 | 5223 | fjp | |
1025 | public boolean isSpatialCacheEnabled() { |
||
1026 | return spatialCacheEnabled;
|
||
1027 | } |
||
1028 | |||
1029 | public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
||
1030 | this.spatialCacheEnabled = spatialCacheEnabled;
|
||
1031 | } |
||
1032 | |||
1033 | 5226 | fjp | public SpatialCache getSpatialCache() {
|
1034 | return spatialCache;
|
||
1035 | } |
||
1036 | |||
1037 | 214 | fernando | } |